先查看usb是否识别ups:
lsusb
Bus 001 Device 054: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
安装:
apt install nut-server nut-client
配置nut运行为服务器模式,可控制多台电脑。
/etc/nut/nut.conf
MODE=netserver
设置nut和ups连接方式,修改此配置后需重新启动upsdrvctl start生效。
/etc/nut/ups.conf
[myups]
driver = usbhid-ups
port = auto
desc = "APC UPS"
#忽略低电量和低运行时间,有的断电后会马上关机
ignorelb
#重写ups返回的低电量和低运行时间值,可用于控制停电时关机时间,满足一个关机,-1为禁用此项
override.battery.charge.low = 99
override.battery.runtime.low = -1
#可以都设置为-1禁用ups低电量自动关机,使用下面的脚本自定义关机
连接ups,nut-server启动时自动加载,usb拔出后需手工启动。
upsdrvctl start
设置nut server监听ip和端口:
/etc/nut/upsd.conf
LISTEN 0.0.0.0 3493
设置客户端连接验证密码:
/etc/nut/upsd.users
#管理员可set更改ups内变量参数,master可设置FSD关机标签,slave收到通知后关机
[admin]
password = 123456
actions = SET FSD
instcmds = ALL
upsmon master
[user1]
password = 123456
actions = FSD
#instcmds = ALL
upsmon master
#别的电脑连接使用此用户
[user2]
password = 123456
#actions = SET
#instcmds = ALL
upsmon slave
设置upsmon客户端连接nut server监控ups状态,当断电后执行关机等操作:
/etc/nut/upsmon.conf
MONITOR myups@localhost 1 user1 123456 master
upsmon默认监控断电且ups电量过低时执行关机,可自定义关机:
upsmon.conf
NOTIFYCMD /sbin/upssched
#当使用电池来电时syslog并执行上面的命令
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG ONLINE SYSLOG+EXEC
upssched自定义操作:
/etc/nut/upssched.conf
CMDSCRIPT /usr/local/bin/upssched
#此目录nut要可写
PIPEFN /run/nut/upssched.pipe
LOCKFN /run/nut/upssched.lock
#断电10秒后执行上面脚本并发送power-off参数
AT ONBATT * START-TIMER power-off 10
#来电后取消上面定时
AT ONLINE * CANCEL-TIMER power-off
关机脚本,要添加可执行权限:
/usr/local/bin/upssched
#! /bin/sh
case $1 in
power-off)
/sbin/upsmon -c fsd
;;
*)
logger -t upssched "Unrecognized command: $1"
;;
esac
启动并查看ups信息:
systemctl restart nut-server.service
systemctl restart nut-client.service
upsc myups
配置nut-cgi web管理界面:
apt install nut-cgi --no-install-recommends fcgiwrap nginx
nut-cgi连接nut-server配置:
/etc/nut/hosts.conf
MONITOR myups@localhost 1 user1 123456 master
nginx配置文件:
server {
listen 89;
charset utf-8;
location /{
alias /usr/share/nut/www/;
try_files $uri $uri/ /index.html;
}
location /cgi-bin/nut/ {
gzip off;
alias /usr/lib/cgi-bin/nut/;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/$fastcgi_script_name;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
access_log off;
}
nut web界面效果:
参考:
https://loganmarchione.com/2017/02/raspberry-pi-ups-monitor-with-nginx-web-monitoring/
https://srackham.wordpress.com/2013/02/27/configuring-nut-for-the-eaton-3s-ups-on-ubuntu-linux/
https://alainlam.cn/?p=56
https://untitled.pw/hardware-iot/2767.html
https://www.wangchucheng.com/zh/posts/setting-up-ups-with-nut-on-linux/
https://forums.contribs.org/index.php?topic=44443.0
请问下nginx配置好了,怎么和这个nut链接呢?最后可视化管理这块能给个详细一点的教程么?谢谢。
写的很详细了啊,/etc/nut/hosts.conf用以nut-cgi连接nut服务器参数,nginx配置文件连接nut-cgi,注意修改nginx内linsten port。
想请教一下,设置了的电脑自动关机之后,几秒后UPS怎么也跟着关机了,导致另外一台电脑没关机就断电了,有没有办法避免UPS关机
ups不知有没选项可设置此参数,不过你可以在另外一台电脑上安装nut客户端自动关机。
此文甚好甚强巨,依照此文在树莓派2 + Rasbian上部署成功
感谢博主美文共赏
override.battery.charge.low以及override.battery.runtime.low的作用是自动关闭UPS还是服务器呢。
关闭服务器
擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办法解决下
ups_status_set: seems that UPS [BK650M2-CH] is in OL+DISCHRG state now. Is it calibrating or do you perhaps want to set 'onlinedischarge' option? Some UPS models (e.g. CyberPower UT series) emit OL+DISCHRG when offline.