PVE UPS NUT配置 自动关机
此文适合ups带usb端口,若是不带,参考下方项目
https://github.com/Twtcer/ups-safe-shutdown 原理是ping路由器,若是停电无法ping通则关闭服务器
环境
- PVE7
- UPS为LADIS雷迪司H1000M后备带usb型号(大部分支持群晖nas的基本都可以使用)
原因&目标
原本厂家是由配套的程序,功能也比较多,能够配置提醒(短信,邮件)、配置关机,但是试用后发现是java开发,启动后内存占用比较高。
后面就找到了NUT,群晖里面的应该也是基于此工具。
一般有2种方式实现自动关机:
- PVE下安装黑群晖(dsm6版本),设置主机和开放从机,其他机器设置后可以联动信息关机。但是我黑群晖基本用centos8跑docker替代了大部分服务。所以就选择pve主机直接配置NUT
- PVE安装NUT,配置webUI。
配置过程
确定ups已经接入
lsusb
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 031: ID 0665:5161 Cypress Semiconductor USB to Serial
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 031: ID 0665:5161 Cypress Semiconductor USB to Serial
即UPS接入的信息
一般有USP字样,如果没有看后面的提示
安装NUT
apt update
apt install nut nut-client nut-server nut-cgi
查看ups连接信息
nut-scanner -U
SNMP library not found. SNMP search disabled.
Neon library not found. XML search disabled.
IPMI library not found. IPMI search disabled.
Scanning USB bus.
[nutdev1]
driver = "blazer_usb"
port = "auto"
vendorid = "0665"
productid = "5161"
product = "USB to Serial"
vendor = "INNO TECH"
bus = "001"
or
/bin/upsc nutdev1@localhost
Init SSL without certificate database
battery.charge: 100
battery.voltage: 13.50
battery.voltage.high: 13.00
battery.voltage.low: 10.40
battery.voltage.nominal: 12.0
device.type: ups
driver.name: blazer_usb
driver.parameter.bus: 001
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.product: USB to Serial
driver.parameter.productid: 5161
driver.parameter.synchronous: no
driver.parameter.vendor: INNO TECH
driver.parameter.vendorid: 0665
driver.version: 2.7.4
driver.version.internal: 0.12
input.current.nominal: 4.0
input.frequency: 50.0
input.frequency.nominal: 50
input.voltage: 222.3
input.voltage.fault: 222.3
input.voltage.nominal: 220
output.voltage: 222.3
ups.beeper.status: enabled
ups.delay.shutdown: 30
ups.delay.start: 180
ups.load: 0
ups.productid: 5161
ups.status: OL
ups.type: offline / line interactive
ups.vendorid: 0665
下面将开始配置
未说明的配置字段,请先#注释,后面需要再配置即可
1.UPS配置 vim /etc/nut/ups.conf
将上面获取到的配置信息拷贝到ups.conf
maxretry = 3
[nutdev1]
driver = "blazer_usb"
port = "auto"
vendorid = "0665"
productid = "5161"
product = "USB to Serial"
vendor = "INNO TECH"
bus = "001"
2.配置监视配置 vim /etc/nut/upsmon.conf
在配置文件最后面追加
RUN_AS_USER root
MONITOR nutdev1@localhost 1 monuser secret master
3.配置upsd vim /etc/nut/upsd.conf
修改服务监听端口,因为局域网多台设备都需要Server下发对应指令
#listen all interface
LISTEN 0.0.0.0 3493
4.配置nut vim /etc/nut/nut.conf
MODE=netserver
5.配置nut用户名,用于其他客户端连接 vim /etc/nut/upsd.users
[monuser]
password = secret
upsmon master
6.重启以上服务
service nut-server restart
service nut-client restart
systemctl restart nut-monitor
upsdrvctl stop
upsdrvctl start
or
service nut-server restart; \
service nut-client restart; \
systemctl restart nut-monitor; \
upsdrvctl stop; \
upsdrvctl start;
7.配置web界面 vim /etc/nut/hosts.conf
MONITOR nutdev1@localhost "LADS H1000M 1000VA 600W UPS"
启用cgi支持,重启服务及配置
a2enmod cgi
systemctl restart apache2
vim /etc/nut/upsset.conf
打开页面 http://ip/cgi-bin/nut/upsstats.cgi 查看
e.g. http://192.168.123.199/cgi-bin/nut/upsstats.cgi
至此,基本配置ok
8.配置关机脚本 vim /etc/nut/upssched.conf
CMDSCRIPT /etc/nut/upssched-cmd #编写此脚本设置
PIPEFN /etc/nut/upssched.pipe
LOCKFN /etc/nut/upssched.lock
AT ONBATT * START-TIMER power-off 60
AT ONLINE * CANCEL-TIMER power-off
AT ONLINE * EXECUTE power-on
/etc/nut/upssched-cmd
#!/bin/sh
case $1 in
onbatt)
logger -t upssched-cmd "UPS running on battery"
# do somethings ,e.g.send email \ wechat
;;
earlyshutdown)
logger -t upssched-cmd "UPS on battery too long, early shutdown"
/usr/sbin/upsmon -c fsd
;;
shutdowncritical)
logger -t upssched-cmd "UPS on battery critical, forced shutdown"
/usr/sbin/upsmon -c fsd
;;
upsgone)
logger -t upssched-cmd "UPS has been gone too long, can't reach"
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
参考
- Network UPS Tools (NUT)配置备忘 https://cku.nz/network-ups-tools-nut-server-configuration/
- 在Linux系统中使用NUT配置UPS https://www.wangchucheng.com/zh/posts/setting-up-ups-with-nut-on-linux/
- https://docs.technotim.live/posts/NUT-server-guide/
- https://blog.csdn.net/qq_37429313/article/details/113786525
- 官网语雀文档 https://www.yuque.com/ladis/gfg4p3/vdscue
- UPS官网站 http://www.ladis.com.cn/
如果,您认为阅读这篇博客让您有些收获,不妨点击一下下方【推荐】按钮。
如果,您希望获取更新的博客,不妨点击下方的的 【关注我】。
如果,博文能对您有所帮助,想给予我更多的鼓励,右方【打赏】随时为您开放(萌萌脸)
本文欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权
专注更高率,自律更自信