收起左侧

本来可正常识别的UPS,飞牛突然无法识别UPS的一种解决方案

0
回复
111
查看
[ 复制链接 ]

2

主题

1

回帖

0

牛值

江湖小虾

我本人也遇到了这个问题,不知怎么触发的突然UPS断开连接,设置里识别不到UPS,重启UPS,重启飞牛,都不好使。

经过排查,结合AI辅助,发现是因为 /etc/nut/ups.conf 中的UPS序列号错乱,内容是乱码,长度不对,双引号不匹配。
通过手动修改序列号,并重启nut服务,成功识别UPS。具体操作步骤如下。

0. ssh登录系统,切换root用户,(执行后提示输入密码,仍然输入本人的密码,不需要知道root的密码)

sudo -i

1. 查看 /etc/nut/ups.conf,定位问题,执行

cat /etc/nut/ups.conf

回显 (省略大段注释文本)

[1413031]
driver                           = "usbhid-ups"
port                             = "/dev/bus/usb/001/006"
vendorid                         = "051D"
vendor                           = "American Power Conversion"
productid                        = "0002"
product                          = "Back-UPS BK650M2-CH FW:294803G -292804G"
serial                           = """0102000?""
bus                              = "001"
desc                             = ""
override.x.additional.lowbatt    = "15"
override.x.additional.devicetype = "USB"

可以看到serial字段明显出问题了,我们手动连接UPS看看是不是这个问题,执行

upsc -l 查看当前UPS的 ID (或者叫什么码?反正就是一个唯一标识)

回显

Init SSL without certificate database
1413031

继续执行尝试手动连接UPS /lib/nut/usbhid-ups -a 1413031 -DDD (这里的 1413031 换成你自己的)

回显

USB communication driver (libusb 1.0) 0.43
addchar: discarding invalid character (0x0a)!
   0.000000     [D1] debug level is '3'
   0.001836     [D2] Initializing an USB-connected UPS with library libusb-1.0.26 (API: 0x1000109) (NUT subdriver name='USB communicatio
   0.001845     [D1] upsdrv_initups (non-SHUT)...
   0.004700     [D2] Checking device 1 of 5 (1D6B/0003)
   0.004723     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.004727     [D2] Checking device 2 of 5 (8087/0AA7)
   0.004736     [D1] Failed to open device (8087/0AA7), skipping: Access denied (insufficient permissions)
   0.004740     [D2] Checking device 3 of 5 (3151/6000)
   0.004749     [D1] Failed to open device (3151/6000), skipping: Access denied (insufficient permissions)
   0.004753     [D2] Checking device 4 of 5 (051D/0002)
   0.006645     [D2] - VendorID: 051d
   0.006653     [D2] - ProductID: 0002
   0.006656     [D2] - Manufacturer: American Power Conversion
   0.006659     [D2] - Product: Back-UPS BK650M2-CH FW:294803G -292804G
   0.006663     [D2] - Serial Number: 9B2133A18027
   0.006666     [D2] - Bus: 001
   0.006669     [D2] - Device: unknown
   0.006672     [D2] - Device release number: 0106
   0.006675     [D2] Trying to match device
   0.006679     [D2] match_function_subdriver (non-SHUT mode): matching a device...
   0.006684     [D3] match_function_regex: matching a device...
   0.006792     [D2] match_function_regex: failed match of Serial: 9B2133A18027
   0.006796     [D2] Device does not match - skipping
   0.006805     [D2] Checking device 5 of 5 (1D6B/0002)
   0.006818     [D1] Failed to open device (1D6B/0002), skipping: Access denied (insufficient permissions)
   0.006822     [D2] libusb1: No appropriate HID device found
   0.006826     libusb1: Could not open any HID devices: insufficient permissions on everything
   0.006829     No matching HID UPS found

可以看到明显的报错信息 failed match of Serial: 9B2133A18027,说明就是这个导致的,虽然不知道是什么原因,先手动给他改回去看看。
从上面报错信息显然可以得出,我这个UPS的真实的USB序列号是9B2133A18027,当然你的应该是和我不一样的,这个要改成你自己的

2. 确定当前处于英文输入法,执行命令打开编辑器

vi /etc/nut/ups.conf

用上下左右键定位到你要修改的位置,然后按 i 进入编辑模式,进行修改,修改后的文件如下,只需要修改序列号字段,匹配你自己的真实序列号,其他地方是自动识别到的,不需要和我展示的一模一样

(省略大段注释文本)

maxretry = 3

[1413031]
driver                           = "usbhid-ups"
port                             = "auto"
vendorid                         = "051D"
vendor                           = "American Power Conversion"
productid                        = "0002"
product                          = "Back-UPS BK650M2-CH FW:294803G -292804G"
serial                           = "9B2133A18027"
bus                              = "001"
desc                             = ""
override.x.additional.lowbatt    = "15"
override.x.additional.devicetype = "USB"

3. 修改完成后,确定当前处于英文输入法ESC 键退出编辑模式,依次按下 : w q 回车 四个按键完成保存,可以再次执行 cat /etc/nut/ups.conf 查看是否修改正确

4. 最后重启nut服务,执行

systemctl restart nut-server

5. 查看服务状态确定是否成功识别,执行:

systemctl status nut-server

回显:

● nut-server.service - Network UPS Tools - power devices information server
     Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; preset: enabled)
     Active: active (running) since Sun 2025-10-19 02:24:44 CST; 17s ago
   Main PID: 21031 (upsd)
      Tasks: 1 (limit: 18664)
     Memory: 624.0K
        CPU: 4ms
     CGroup: /system.slice/nut-server.service
             **─21031 /lib/nut/upsd -F

Oct 19 02:24:44 N52 nut-server[21031]: fopen /run/nut/upsd.pid: No such file or directory
Oct 19 02:24:44 N52 nut-server[21031]: Could not find PID file '/run/nut/upsd.pid' to see if previous upsd instance is already running!
Oct 19 02:24:44 N52 nut-server[21031]: listening on ::1 port 3493
Oct 19 02:24:44 N52 nut-server[21031]: listening on 127.0.0.1 port 3493
Oct 19 02:24:44 N52 upsd[21031]: listening on ::1 port 3493
Oct 19 02:24:44 N52 upsd[21031]: listening on 127.0.0.1 port 3493
Oct 19 02:24:44 N52 nut-server[21031]: Connected to UPS [1413031]: usbhid-ups-1413031
Oct 19 02:24:44 N52 upsd[21031]: Connected to UPS [1413031]: usbhid-ups-1413031
Oct 19 02:24:44 N52 upsd[21031]: Running as foreground process, not saving a PID file
Oct 19 02:24:44 N52 nut-server[21031]: Running as foreground process, not saving a PID file

6. 可以看到已经正确连接(Connected to UPS [1413031]: usbhid-ups-1413031),可以关闭ssh终端了,在页面等待一会刷新后,设置中可以发现已经成功识别UPS。

收藏
送赞
分享
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则