Connecting a UPS (USB) to Alt Linux Alt Workstation
Имеем ИБП APC SE Back-UPS CS 350VA (BK350EI).
Для подключения ИБП к USB порту используем дата кабель apc 940-0127e [usb-rj50(10P10C)] для других моделей UPS Communications Cable Simple Signalling USB to RJ45 AP9827
Информация о системе
lsb_release -a
cat /etc/*-release*
LSB Version: n/a
Distributor ID: ALT
Description: ALT Workstation 10.1 (Autolycus)
Release: 10.1
Codename: Autolycus
Устанавливаем утилиту для работы с USB
apt-get upgrade
install usbutils
Смотрим что у нас подключено на USB шине
lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
lsusb -D /dev/bus/usb/002/004
Device: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x051d American Power Conversion
idProduct 0x0002 Uninterruptible Power Supply
bcdDevice 0.06
iManufacturer 3 American Power Conversion
iProduct 1 Back-UPS CS 350 FW:807.q5.I USB FW:q5
iSerial 2 BB0448012193
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0022
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 33 US
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 1216
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0006 1x 6 bytes
bInterval 100
Device Status: 0x0001
Self Powered
Для бесперебойников ИБП фирмы APC установим apcupsd
apt-cache search apcupsd
apcupsd - Power management software for APC UPS hardware
gapcmon - графический монитор состояния ИБП для apcupsd
apcupsd-doc - apcupsd documentation
apcupsd-multiups - apcupsd's configuration for monitoring multiple UPSes on one host
hass-core - Home automation platform
apt-get install apcupsd gapcmon
Редактирование файл настроек apcupsd
sudo cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.default
nano /etc/apcupsd/apcupsd.conf
## apcupsd.conf v1.1 ##
UPSCABLE usb
UPSTYPE usb
DEVICE
LOCKFILE /var/lock
UPSCLASS standalone
UPSMODE disable
-----------
echo "ISCONFIGURED=yes" > /etc/default/apcupsd
APC UPS old configuration file found
Включение запуск службы apcupsd
systemctl enable apcupsd.service
systemctl start apcupsd
systemctl status apcupsd
Узнать состояние ИБП можно с помощью программы-клиента apcaccess
find -name apcaccess
./sbin/apcaccess
./usr/sbin/apcaccess
find -name apctest
./sbin/apctest
./usr/sbin/apctest
apcupsd предлагает удобный веб-интерфейс для мониторинга вашего ИБП. Чтобы установить его, откройте терминал и введите
sudo apt install apcupsd apcupsd-cgi apache2
sudo a2enmod cgi
sudo systemctl restart apache2
firefox localhost/cgi-bin/apcupsd/multimon.cgi
Если на Astra Linux apache2 выдаёт ошибку 500 проверить less /var/log/apache2/error.log
Authentication not configured Веб-сервер Apache2 в ОС Astra Linux Special Edition работает только с принудительной аутентификацией. https://wiki.astralinux.ru/pages/viewpage.action?pageId=238749508
nano /etc/apache2/apache2.conf
AstraMode off
systemctl restart apache2
Мониторинг состояния ИБП с помощью NUT (Network UPS Tools) networkupstools.org
Установите NUT и зависимости
apt-get install nut nut-cgi nut-driver nut-driver-usb nut-server
Определение драйвера для ИБП
nut-scanner
IPMI library not found. IPMI search disabled.
Scanning USB bus.
No start IP, skipping SNMP
No start IP, skipping NUT bus (old connect method)
Scanning NUT bus (avahi method).
[nutdev1]
driver = "usbhid-ups"
port = "auto"
vendorid = "051D"
productid = "0002"
bus = "002"
Находим устройство в выводе команды
lsusb
Bus 002 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
редактированию конфигурационных файлов.
Начнем с ups.conf. Выполняем в консоли
nano /etc/nut/ups.conf
# APC BK650 is compatible with the usbhid driver
option driver usbhid-ups
# auto detect USB port
option port auto
config listen_address
option ::1
config upsd upsd
Запуск авто-сканирование nut-scanner
nut-scanner
IPMI library not found. IPMI search disabled.
Scanning USB bus.
No start IP, skipping SNMP
No start IP, skipping NUT bus (old connect method)
Scanning NUT bus (avahi method).
[nutdev1]
driver = "usbhid-ups"
port = "auto"
vendorid = "051D"
productid = "0002"
product = "Back-UPS CS 350 FW:807.q5.I USB FW:q5"
vendor = "American Power Conversion"
bus = "002"
Настройка — Установим режим standalone, который подразумевает запуск трех компонентов driver, upsd, upsmon.
nano /etc/nut/nut.conf
MODE=standalone
Настройка driver (nut-driver.service) — загружает драйвер, запускается по требованию nut-server.service
nano /lib/systemd/system/nut-driver.service
[Unit]
Description=Network UPS Tools - power device driver controller
After=local-fs.target network.target systemd-udev-settle.service
#Wants=systemd-udev-settle.service <----- comment strin
StopWhenUnneeded=yes
[Service]
ExecStart=/sbin/upsdrvctl start
ExecStop=/sbin/upsdrvctl stop
Type=forking
Настройка upsd (nut-server.service) — загружает демон, обеспечивающий сетевой интерфейс для взаимодействие с ИБП.
LISTEN 127.0.0.1 3493
Добави ИБП в файл /etc/nut/ups.conf
nano /etc/nut/ups.conf
maxretry = 3
[apc350]
driver = usbhid-ups
port = auto
vendorid = 051d
productid = 0002
desc = "APC Back-UPS CS 350"
Перезапускаем upsd
systemctl restart nut-server.service
systemctl status nut-server.service
● nut-server.service - Network UPS Tools - power devices information server
Loaded: loaded (/lib/systemd/system/nut-server.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2023-11-17 18:28:32 MSK; 2s ago
Main PID: 4727 (upsd)
Tasks: 1 (limit: 4642)
Memory: 624.0K
CPU: 11ms
CGroup: /system.slice/nut-server.service
└─ 4727 /usr/sbin/upsd -F -u upsd -r /var/lib/nut
ноя 17 18:28:32 alt systemd[1]: Started Network UPS Tools - power devices information server.
ноя 17 18:28:32 alt upsd[4727]: fopen /var/lib/upsd/upsd.pid: No such file or directory
ноя 17 18:28:32 alt upsd[4727]: listening on 127.0.0.1 port 3493
ноя 17 18:28:32 alt upsd[4727]: listening on 127.0.0.1 port 3493
ноя 17 18:28:32 alt upsd[4727]: Connected to UPS [apc350]: usbhid-ups-apc350
Необходимо создать пользователя для upsmon для мониторинга и правления
nano /etc/nut/upsd.users
[upsmon]
password = 123456789
upsmon master
[admin]
password = 987654321
actions = SET
instcmds = ALL
Поулчаем данные ИБП
upsc -l
apc350
upsc apc350
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 50
battery.date: 2023/11/14
battery.mfr.date: 2023/11/14
battery.runtime: 1230
battery.runtime.low: 120
battery.temperature: 29.2
battery.type: PbAc
battery.voltage: 13.7
battery.voltage.nominal: 12.0
device.mfr: American Power Conversion
device.model: Back-UPS CS 350
device.serial: BB0448012193
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.productid: 0002
driver.parameter.synchronous: no
driver.parameter.vendorid: 051d
driver.version: 2.7.4
driver.version.data: APC HID 0.96
driver.version.internal: 0.41
input.sensitivity: low
input.transfer.high: 278
input.transfer.low: 160
input.voltage: 216.0
input.voltage.nominal: 230
output.frequency: 50.0
output.voltage: 230.0
output.voltage.nominal: 230.0
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.firmware: 807.q5.I
ups.firmware.aux: q5
ups.load: 52.0
ups.mfr: American Power Conversion
ups.mfr.date: 2004/11/24
ups.model: Back-UPS CS 350
ups.productid: 0002
ups.realpower.nominal: 210
ups.serial: BB0448012193
ups.status: OL
ups.test.result: No test initiated
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.timer.start: 0
ups.vendorid: 051d
PowerCom pcm IMPerial IMD-625AP подклчюеие через USB кабель
Powercom Software https://pcm.ru/support/soft/
https://networkupstools.org/docs/man/powercom.html
https://www.linux.org.ru/forum/admin/14350294
https://www.linuxquestions.org/questions/linux-hardware-18/trouble-running-network-ups-tools-on-linux-ubuntu-10-10-a-897117/
Astra linux SE 1.7.5.9
Установлен NUT Network UPS Tools 2.7.4-13
Просмотр портов
lsusb
Bus 002 Device 008: ID 0d9f:0002 Powercom Co., Ltd Black Knight PRO / WOW Uninterruptible Power Supply (Cypress HID->COM RS232)
Vendor ID : 0d9f
Device ID : 0002
Теперь меняем права, где цифры — номера шины (Bus) и устройства (Device) из предыдущей команды:
chown root:nut /dev/bus/usb/002/008
ls -la /dev/bus/usb/002/008
ls -la /dev/ttyUSB0
crw-rw—- 1 root dialout 188, 0 ноя 22 23:03 /dev/ttyUSB0
—
просмотр групп пользователя nut
adduser nut dialout
groups nut
nut : nut dialout
Расширенная информация об устройстве usb
lsusb -D /dev/bus/usb/002/008
Device: ID 0d9f:0002 Powercom Co., Ltd Black Knight PRO / WOW Uninterruptible Power Supply (Cypress HID->COM RS232)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0d9f Powercom Co., Ltd
idProduct 0x0002 Black Knight PRO / WOW Uninterruptible Power Supply (Cypress HID->COM RS232)
bcdDevice 0.00
iManufacturer 1 POWERCOM CO., LTD.
iProduct 2 USB to Serial
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0029
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 4 Sample HID
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.00
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 37
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10
can’t get debug descriptor: Resource temporarily unavailable
Device Status: 0x0000
(Bus Powered)
———-
dmesg
[19542.451606] usb 2-3: HID->COM RS232 Adapter converter now attached to ttyUSB0
———
Если ИБП подключен к COM порту, то можно посмотреть номера COM портов командой:
————-
Поиск параметров устройства
/lib/nut/powercom -a powercom -u root -DDDDDD -x type=IMP
Запуск авто-сканирование поиск ИБП
nut-scanner
Neon library not found. XML search disabled.
IPMI library not found. IPMI search disabled.
Scanning USB bus.
No start IP, skipping SNMP
No start IP, skipping NUT bus (old connect method)
—-
Файл nano /etc/nut/nut.conf
MODE=standalone
—
Файл Настройка driver
nano /lib/systemd/system/nut-driver.service
[Unit]
Description=Network UPS Tools — power device driver controller
After=local-fs.target network.target systemd-udev-settle.service
#Wants=systemd-udev-settle.service <—— Закомментировать строчку
StopWhenUnneeded=yes
[Service]
ExecStart=/sbin/upsdrvctl start
ExecStop=/sbin/upsdrvctl stop
Type=forking
——-
Настройка upsd
Файл nano /etc/nut/upsd.conf
MAXAGE 25
LISTEN 127.0.0.1 3493 <—— По умолчанию слушает localhost
На всякий случай явно укажу 127.0.0.1
LISTEN 192.168.1.8 3493
——
Настройка драйвера.
файл nano /etc/nut/ups.conf
[powercom]
#driver = usbhid-ups
#driver = blazer_ups
driver = powercom
port = auto
# port = /dev/ttyUSB0
type = IMP
——-
Необходимо создать пользователя для upsmon
файл /etc/nut/upsd.users
[upsmon]
password = 123456789
upsmon master
[admin]
password = 987654321
actions = SET
instcmds = ALL
————
Перезапускаем upsd
systemctl restart nut-server.service
systemctl status nut-server.service
nut-server.service — Network UPS Tools — power devices information server
Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-11-22 22:21:30 MSK; 10s ago
Process: 5728 ExecStart=/sbin/upsd (code=exited, status=0/SUCCESS)
Main PID: 5729 (upsd)
Tasks: 1 (limit: 4915)
Memory: 464.0K
CPU: 11ms
CGroup: /system.slice/nut-server.service
└─5729 /lib/nut/upsd
ноя 22 22:21:30 astra systemd[1]: Starting Network UPS Tools — power devices information server…
ноя 22 22:21:30 astra upsd[5728]: fopen /run/nut/upsd.pid: No such file or directory
ноя 22 22:21:30 astra upsd[5728]: listening on 127.0.0.1 port 3493
ноя 22 22:21:30 astra upsd[5728]: listening on 127.0.0.1 port 3493
ноя 22 22:21:30 astra upsd[5728]: Can’t connect to UPS [powercom] (powercom-powercom): No such file or directory
ноя 22 22:21:30 astra upsd[5728]: Can’t connect to UPS [powercom] (powercom-powercom): No such file or directory
ноя 22 22:21:30 astra upsd[5729]: Startup successful
ноя 22 22:21:30 astra systemd[1]: Started Network UPS Tools — power devices information server.
——-
файл /etc/nut/ups.conf
[powercom]
port = /dev/ttyUSB0
systemctl status nut-server.service
● nut-server.service — Network UPS Tools — power devices information server
Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-11-22 22:29:37 MSK; 2s ago
Process: 5919 ExecStart=/sbin/upsd (code=exited, status=0/SUCCESS)
Main PID: 5920 (upsd)
Tasks: 1 (limit: 4915)
Memory: 480.0K
CPU: 8ms
CGroup: /system.slice/nut-server.service
└─5920 /lib/nut/upsd
ноя 22 22:29:37 astra systemd[1]: Starting Network UPS Tools — power devices information server…
ноя 22 22:29:37 astra upsd[5919]: fopen /run/nut/upsd.pid: No such file or directory
ноя 22 22:29:37 astra upsd[5919]: listening on 127.0.0.1 port 3493
ноя 22 22:29:37 astra upsd[5919]: listening on 127.0.0.1 port 3493
ноя 22 22:29:37 astra upsd[5919]: Connected to UPS [powercom]: powercom-powercom
ноя 22 22:29:37 astra upsd[5919]: Connected to UPS [powercom]: powercom-powercom
ноя 22 22:29:37 astra upsd[5920]: Startup successful
ноя 22 22:29:37 astra upsd[5920]: Data for UPS [powercom] is stale — check driver
ноя 22 22:29:37 astra systemd[1]: Started Network UPS Tools — power devices information server.
—
Получить список ИБП
upsc -l
# Получить данные
upsc powercom
Init SSL without certificate database
Error: Driver not connected
——-
upsdrvctl start
Network UPS Tools — UPS driver controller 2.7.4
Network UPS Tools — PowerCom protocol UPS driver 0.17 (2.7.4)
writing error
—-
upsdrvctl start
Network UPS Tools — UPS driver controller 2.7.4
Network UPS Tools — PowerCom protocol UPS driver 0.17 (2.7.4)
Duplicate driver instance detected! Terminating other driver!
writing error
——-
upsdrvctl start
Network UPS Tools — UPS driver controller 2.7.4
Network UPS Tools — Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
This Powercom device (0d9f/0002) is not supported by usbhid-ups.
Please use the ‘powercom’ driver instead.
No matching HID UPS found
Driver failed to start (exit status=1)
Network UPS Tools — Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
This Powercom device (0d9f/0002) is not supported by usbhid-ups.
Please use the ‘powercom’ driver instead.
No matching HID UPS found
Driver failed to start (exit status=1)
Network UPS Tools — Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
This Powercom device (0d9f/0002) is not supported by usbhid-ups.
Please use the ‘powercom’ driver instead.
No matching HID UPS found
Driver failed to start (exit status=1)
——-
Подобрав настройки файла nano /etc/nut/ups.conf
systemctl restart nut-server.service
systemctl status nut-server.service
Теперь можем получить данные о состоянии ИБП командой:
upsc powercom
upsc powercom@localhost
Error: Connection failure: Connection refused
root@astra:~# upsdrvctl stop
Network UPS Tools — UPS driver controller 2.7.4
root@astra:~# systemctl restart nut-server.service
root@astra:~# upsc powercom
Init SSL without certificate database
battery.charge: 84.0
device.mfr: PowerCom
device.model: IMP-625AP
device.serial: Unknown
device.type: ups
driver.name: powercom
driver.parameter.pollinterval: 2
driver.parameter.port: /dev/ttyUSB0
driver.parameter.synchronous: no
driver.parameter.type: IMP
driver.version: 2.7.4
driver.version.internal: 0.17
input.frequency: 50.00
input.voltage: 210.0
input.voltage.nominal: 220
output.frequency: 50.00
output.voltage: 210.0
ups.load: 3.0
ups.mfr: PowerCom
ups.model: IMP-625AP
ups.model.type: IMP
ups.serial: Unknown
ups.status: OL
—-
просмотр открытх сетевых портов
ss -tulpn | grep 3493
tcp LISTEN 0 16 127.0.0.1:3493 0.0.0.0:* users:((«upsd»,pid=4766,fd=5))
tcp LISTEN 0 16 192.168.1.8:3493 0.0.0.0:* users:((«upsd»,pid=4766,fd=4))
—
Настройка службы мониторинга в Windows
WinNUT-Client https://github.com/gawindx/WinNUT-Client
Настройки: указываем адрес и порт сервера, имя драйвера, логин и пароль.