如何在电池电量不足时关闭 Debian 服务器和 UPS?

如何在电池电量不足时关闭 Debian 服务器和 UPS?

如何使用一个独立的 USB UPS 配置 Debian 服务器以:

  1. 电池电量低时,一分钟后启动 UPS 关闭电源。
  2. 自行关闭。
  3. 并确保当主电源恢复时(甚至在 UPS 电量耗尽之前)Debian 服务器将启动。

这些步骤描述于这个问题但没有解释如何实现它们。

我有:

  • 我的服务器配置为在电源恢复时始终启动。
  • 安装nut后,运行时upsc myups我可以看到 UPS 的信息,包括电池电量。因此我可以轻松编写脚本来监控电池并关闭服务器。

我的问题是:

如何向UPS发送关机命令?

UPS 是:伊顿 5E 650i

/etc/nut/nut.conf有:

MODE=standalone

/etc/nut/ups.conf有:

[myups]
    driver = usbhid-ups
    port = auto
    vendorid = 0463
    pollfreq = 30

upsc myups印刷:

Init SSL without certificate database
battery.charge: 100
battery.runtime: 1825
battery.type: PbAc
device.mfr: EATON
device.model: 5E 650i
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.parameter.vendorid: 0463
driver.version: 2.7.4
driver.version.data: MGE HID 1.39
driver.version.internal: 0.41
input.voltage: 230.0
outlet.1.status: on
outlet.desc: Main Outlet
outlet.id: 1
outlet.switchable: no
output.frequency: 49.9
output.frequency.nominal: 50
output.voltage: 230.0
output.voltage.nominal: 230
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.firmware: 03.08.0018
ups.load: 19
ups.mfr: EATON
ups.model: 5E 650i
ups.power.nominal: 650
ups.productid: ffff
ups.start.battery: yes
ups.status: OL
ups.timer.shutdown: -1
ups.vendorid: 0463

答案1

好的,我认为它现在起作用了。以下是我所做的:

apt-get install nut-server

apt-get install nut-client

nano /etc/nut/nut.conf

MODE=standalone

nano /etc/nut/ups.conf

[myups]
    driver = usbhid-ups
    port = auto
    vendorid = 0463
    pollfreq = 30

/sbin/upsdrvctl start

upsc myups 打印一些问题。

重启 /usr/sbin/shutdown -r now

现在执行时upsc myups您应该会看到 UPS 的信息:

Init SSL without certificate database
battery.charge: 86
battery.runtime: 956
battery.type: PbAc
device.mfr: EATON
device.model: 5E 650i
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.parameter.vendorid: 0463
driver.version: 2.7.4
driver.version.data: MGE HID 1.39
driver.version.internal: 0.41
input.voltage: 226.0
outlet.1.status: on
outlet.desc: Main Outlet
outlet.id: 1
outlet.switchable: no
output.frequency: 49.9
output.frequency.nominal: 50
output.voltage: 225.0
output.voltage.nominal: 230
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.firmware: 03.08.0018
ups.load: 27
ups.mfr: EATON
ups.model: 5E 650i
ups.power.nominal: 650
ups.productid: ffff
ups.start.battery: yes
ups.status: OL
ups.timer.shutdown: -1
ups.vendorid: 0463

如果/sbin/upsmon打印类似的东西:

Network UPS Tools upsmon 2.7.4
fopen /var/run/nut/upsmon.pid: No such file or directory
Using power down flag file /etc/killpower

Fatal error: insufficient power configured!

Sum of power values........: 0
Minimum value (MINSUPPLIES): 1

Edit your upsmon.conf and change the values.
    

尝试:nano /etc/nut/upsd.users

[upsmon]
    password  = mypassword
    upsmon master

chmod 640 /etc/nut/upsd.users

ls -lahrt /etc/nut/upsd.users

-rw-r----- 1 root nut 2,2K Dec 13 13:15 /etc/nut/upsd.users

nano /etc/nut/upsmon.conf

MONITOR myups@localhost 1 upsmon mypassword master

systemctl enable nut-monitor

/sbin/upsmon

Network UPS Tools upsmon 2.7.4
fopen /var/run/nut/upsmon.pid: No such file or directory
UPS: myups@localhost (master) (power value 1)
Using power down flag file /etc/killpower

这是我通过切断电源进行测试时在 syslog 中看到的内容:

Dec 13 15:47:01 pc upsmon[604]: UPS myups@localhost on battery
... 12 minutes later
Dec 13 15:59:32 pc upsmon[604]: UPS myups@localhost battery is low
Dec 13 15:59:32 pc upsd[601]: Client upsmon@::1 set FSD on UPS [myups]
Dec 13 15:59:32 pc upsmon[604]: Executing automatic power-fail shutdown
Dec 13 15:59:32 pc upsmon[604]: Auto logout and shutdown proceeding
Dec 13 15:59:37 pc systemd[1]: nut-monitor.service: Succeeded.
Dec 13 15:59:37 pc systemd[1]: unattended-upgrades.service: Succeeded.
Dec 13 15:59:37 pc systemd[1]: Stopping Session 39 of user a.
Dec 13 15:59:37 pc systemd[1]: Stopped target Graphical Interface.
Dec 13 15:59:37 pc upsd[601]: mainloop: Interrupted system call
Dec 13 15:59:37 pc systemd[1]: Stopped target Multi-User System.
Dec 13 15:59:37 pc upsd[601]: Signal 15: exiting
Dec 13 15:59:37 pc systemd[1]: Stopping Network UPS Tools - power devices information server...
Dec 13 15:59:37 pc systemd[1]: postgresql.service: Succeeded.
Dec 13 15:59:37 pc systemd[1]: Stopped PostgreSQL RDBMS.
Dec 13 15:59:37 pc systemd[1]: Stopping PostgreSQL Cluster...
Dec 13 15:59:37 pc systemd[1]: Stopping The Apache HTTP Server...
Dec 13 15:59:37 pc systemd[1]: Stopping LSB: disk temperature monitoring daemon...
Dec 13 15:59:37 pc systemd[1]: sysstat.service: Succeeded.
Dec 13 15:59:37 pc systemd[1]: Stopped Resets System Activity Data Collector.
Dec 13 15:59:37 pc smartd[392]: smartd received signal 15: Terminated
Dec 13 15:59:37 pc smartd[392]: Device: /dev/sda [SAT], state written to /var/lib/smartmontools/smartd.xxx.ata.state
Dec 13 15:59:37 pc smartd[392]: Device: /dev/sdb [SAT], state written to /var/lib/smartmontools/smartd.yyy.ata.state
Dec 13 15:59:37 pc smartd[392]: smartd is exiting (exit status 0)
Dec 13 15:59:37 pc systemd[1]: Stopping Self Monitoring and Reporting Technology (SMART) Daemon...
Dec 13 15:59:37 pc systemd[1]: Stopping Regular background program processing daemon...
Dec 13 15:59:37 pc systemd[1]: Stopped target Login Prompts.
Dec 13 15:59:37 pc systemd[1]: Stopping OpenBSD Secure Shell server...
... when power is on again
Dec 13 16:01:28 pc kernel: [    0.000000] Linux version 4.19.0-9-amd64 ([email protected]) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP Debian 4.19.1$

启动后执行时upsmon我看到以下内容:

/sbin/upsmon

Network UPS Tools upsmon 2.7.4
Fatal error: A previous upsmon instance is already running!
Either stop the previous instance first, or use the 'reload' command.

我想这意味着它正在运行并且一切都很好:)

您可以在此处看到 打印的变量的含义upsc,例如ups.statusups.timer.shutdownbattery.chargehttps://networkupstools.org/docs/user-manual.pdf

另一个有用的 URL 是:https://risc-a-day.blogspot.com/2014/09/getting-my-ups-to-work-with-linux.html

相关内容