在现代的服务器和网络设备管理中,拥有一个电池备份解决方案是至关重要的。特别是在成本敏感的小型企业环境中,电池备份的目的通常不是全天候(或多小时)运行,而是20-30分钟——足以覆盖短暂的停电,并在更长时间的停电中通知并优雅地关闭设备。本文的目的是引导配置Proxmox主机服务器上的nut-server服务和Linux客户端上的nut-client服务,包括邮件通知和所有虚拟机的优雅服务器关闭。
最近,不得不更换一台老化的UPS,并基于成本、用户评价和技术能力选择了Tripp Lite SMART1500RM2U。将假设UPS单元通过USB连接到名为VMSERVER的Proxmox主机服务器。
在插入UPS之前,让开始一个持久的tail /var/log/messages,以确保UPS被操作系统识别。打开一个新的SSH会话到主机,将tail日志文件,观察USB条目。应该看到类似以下的输出:
root@vmserver [~]# tail -f /var/log/messages
Oct 26 09:32:03 vmserver kernel: [149701.226307]
usb 1-11: SerialNumber: 3122CVYSM88EC01815
Oct 26 09:32:03 vmserver kernel: [149701.275704]
hid-generic 0003:09AE:3015.270B: hiddev0,hidraw0: USB HID v1.10
Device [Tripp Lite TRIPP LITE SMART1500RM2U ] on usb-0000:00:14.0-11/input0
Oct 26 09:32:17 vmserver kernel: [149715.705236]
usb 1-11: USB disconnect, device number 36
Oct 26 09:32:18 vmserver kernel: [149716.051727]
usb 1-11: new low-speed USB device number 37 using xhci_hcd
Oct 26 09:32:18 vmserver kernel: [149716.209951]
usb 1-11: New USB device found, idVendor=09ae, idProduct=3015, bcdDevice= 2.0a
Oct 26 09:32:18 vmserver kernel: [149716.209960]
usb 1-11: New USB device strings: Mfr=2, Product=3, SerialNumber=4
Oct 26 09:32:18 vmserver kernel: [149716.209965]
usb 1-11: Product: TRIPP LITE SMART1500RM2U
Oct 26 09:32:18 vmserver kernel: [149716.209969]
usb 1-11: Manufacturer: Tripp Lite
Oct 26 09:32:18 vmserver kernel: [149716.209972]
usb 1-11: SerialNumber: 3122CVYSM88EC01815
Oct 26 09:32:18 vmserver kernel: [149716.259635]
hid-generic 0003:09AE:3015.270C: hiddev0,hidraw0: USB HID v1.10
Device [Tripp Lite TRIPP LITE SMART1500RM2U ] on usb-0000:00:14.0-11/input0
从上面的日志条目中,可以看到UPS已经被操作系统识别,现在可以安装和配置nut-server和nut-client。
使用apt-get安装nut、nut-client、nut-server、nut-cgi和lighttpd:
root@vmserver [~]# apt-get install nut nut-client nut-server nut-cgi lighttpd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libltdl7 libnutscan1 libupsclient4 libusb-0.1-4 lighttpd-mod-deflate
lighttpd-mod-openssl spawn-fcgi
Suggested packages:
rrdtool php-cgi php-fpm apache2-utils lighttpd-doc lighttpd-mod-authn-gssapi
lighttpd-mod-authn-pam lighttpd-mod-authn-sasl lighttpd-mod-geoip
lighttpd-mod-maxminddb lighttpd-mod-trigger-b4-dl lighttpd-mod-vhostdb-pgsql
lighttpd-mod-webdav lighttpd-modules-dbi lighttpd-modules-ldap
lighttpd-modules-lua lighttpd-modules-mysql nut-monitor nut-ipmi nut-snmp nut-xml
The following NEW packages will be installed:
libltdl7 libnutscan1 libupsclient4 libusb-0.1-4 lighttpd
lighttpd-mod-deflate lighttpd-mod-openssl nut nut-cgi nut-client
nut-server spawn-fcgi
0 upgraded, 12 newly installed, 0 to remove and 65 not upgraded.
Need to get 2,360 kB/2,786 kB of archives.
After this operation, 9,075 kB of additional disk space will be used.
Do you want to continue? [Y/n]
配置nut,如果不重启服务器,则需要重新启动udev:
systemctl restart udev
在lighttpd配置中加载CGI模块并重新启动lighttpd:
root@vmserver [/etc/nut]# lighttpd-enable-mod cgi
Enabling cgi: ok
Run "service lighttpd force-reload" to enable changes
root@vmserver [/etc/nut]# service lighttpd force-reload
通过在浏览器中访问http://<server name/IP>/cgi-bin/upsstats.cgi来检查UPS状态。应该看到一个类似于以下的页面:
现在nut服务器已经可以正常工作了,可以在Proxmox客户端系统上安装nut客户端。在Linux上,可以使用apt-get安装客户端:
root@linuxappserver [~]# apt-get install nut-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
bash-completion libupsclient4
Suggested packages:
nut-monitor
The following NEW packages will be installed:
bash-completion libupsclient4 nut-client
0 upgraded, 3 newly installed, 0 to remove and 28 not upgraded.
Need to get 673 kB of archives.
After this operation, 2,348 kB of additional disk space will be used.
Do you want to continue? [Y/n]
使用upsc命令检查nut服务器:
upsc tripplite@vmserver ups.status
应该得到类似于以下的输出:
root@linuxappserver [/var/log]# upsc tripplite@vmserver ups.status
Init SSL without certificate database
OL
修改nut配置文件:
nut.conf:
MODE=netclient
upsmon.conf:
RUN_AS_USER root
MONITOR tripplite@vmserver.wwf-mgt.com 1 admin secret slave
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h now"
NOTIFYCMD /usr/sbin/upssched
POLLFREQ 2
POLLFREQALERT 1
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYMSG ONLINE "UPS %s on line power"
NOTIFYMSG ONBATT "UPS %s on battery"
NOTIFYMSG LOWBATT "UPS %s battery is low"
NOTIFYMSG FSD "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK "Communications with UPS %s established"
NOTIFYMSG COMMBAD "Communications with UPS %s lost"
NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM "UPS %s is unavailable"
NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible"
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT SYSLOG+WALL
RBWARNTIME 43200
NOCOMMWARNTIME 600
FINALDELAY 5