Network UPS Tools (NUT)配置备忘

Network UPS Tools (NUT)配置备忘
Photo by Josh Miller / Unsplash

此文主要场景为usb通讯的UPS,SNMP的太高端了暂未用到,我自己是用一台吃灰多年的树莓派来当UPS服务器;当然也可以用群晖、Unraid等应用,这里推荐群晖的UPS管理软件,其核心也是用的NUT并无区别,只是自己部署安装的支持WEB UI,看着装逼了很多。

硬件:

  • 树莓派3B+
  • 山特桌面式UPS
  • 雷迪司机架式UPS

准备工作: UPS通讯线插入树莓派,可支持多个UPS。

~#lsusb
Bus 001 Device 004: ID 0c45:7000 Microdia iPazzPort
Bus 001 Device 005: ID 0463:ffff MGE UPS Systems UPS
Bus 001 Device 006: ID 0665:5161 Cypress Semiconductor USB to Serial
Bus 001 Device 003: ID 0424:ec00 Microchip Technology, Inc. (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Microchip Technology, Inc. (formerly SMSC) SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

可查看是否被发现,一般都会比较顺利。

~#sudo apt update
~#sudo apt install nut nut-client nut-server nut-cgi

安装所需的应用

~#sudo 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"
[nutdev2]
	driver = "usbhid-ups"
	port = "auto"
	vendorid = "0463"
	productid = "FFFF"
	product = "SANTAK TG-BOX"
	serial = "Blank"
	vendor = "EATON"
	bus = "001"

查看nut获取到当前UPS的列表,并将内容直接复制到/etc/nut/ups.conf文件中,可对名称进行修改。

~#sudo nano /etc/nut/upsmon.conf

配置upsmon,配置如下:

RUN_AS_USER root
MONITOR tbox@localhost 1 admin secret master
MONITOR lads@localhost 1 admin secret master

编辑upsd.conf修改服务监听端口,因为局域网多台设备都需要Server下发对应指令

sudo vim /etc/nut/upsd.conf
#listen all interface
LISTEN 0.0.0.0 3493 

修改nut为server模式

~#sudo nano /etc/nut/nut.conf
MODE=netserver

配置nut用户名,用于其他客户端连接

~#sudo vim /etc/nut/upsd.users
[monuser]
  password = secret
  admin master

配置完毕,重启服务们~

~#sudo service nut-server restart
~#sudo service nut-client restart
~#sudo systemctl restart nut-monitor
~#sudo upsdrvctl stop
~#sudo upsdrvctl start

最装逼的地方来啦,配置web界面,添加UPS:

~#sudo vim /etc/nut/hosts.conf
MONITOR LADS@localhost "LADS GR1K 1000VA 800W UPS - Rack"
MONITOR SANTAK@localhost "SANTAK TG-BOX 850VA 510W UPS - Wall"

启用cgi支持,重启服务及配置完毕:

~#sudo a2enmod cgi
~#sudo systemctl restart apache2
~#sudo nano /etc/nut/upsset.conf

即可访问来查看:

http://IPADDRESS/cgi-bin/nut/upsstats.cgi

可以看到已经有两个ups已上线~

如果嫌弃官方的webui太丑的话,有一个开源项目做了bootstrap的界面:webNUT

可直接部署在服务器上,也可以使用docker安装: https://hub.docker.com/r/teknologist/webnut

推荐使用docker-compose来配置:

services:
  nut:
    image: teknologist/webnut
    container_name: webnut
    environment:
      - UPS_HOST=ip.address.of.nut.server
      - UPS_PORT=3493
      - UPS_USER=admin
      - UPS_PASSWORD=secret
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - proxy
    ports:
      - 6543:6543
networks:
  proxy:
    external: true

因为我偷懒,直接用Portainer了,需要注意的是添加四个变量和一个网络映射,效果如图:

已知问题:

  1. 该docker无法运行在ARM加购上,所以无法运行在树莓派上。