自宅LinuxサーバにUPS(無停電電源装置)導入

Linux

概要

  • UPSが1万5000円ぐらいなのでこのblogが動いているLinuxサーバに導入してみました。
  • UPSとは、「Uninterruptible Power Supply」の略で、日本語では「無停電電源装置」と訳します。
  • APC RS 550 BR550S-JP Eを買いました。あまり商品リサーチはしてません。APCは老舗なのでまぁ、安心かなと。
APC 無停電電源装置 UPS 550VA/330W BR550S-JP E ラインインタラクティブ給電 長寿命バッテリ 正弦波
4534387200174

物理的なセットアップ

まず最初に、UPSの蓋を開けてバッテリーのケーブルを接続します。初期状態ではケーブルが外れた状態になっています。バイクのバッテリーみたいな電池が入ってました。

そして、こんな感じに適当にケーブルを接続してセットアップ。

残り時間は27分と出ています。

サーバであんまり電力消費しないはずなのに想定より短い感じです。今回は常時70Wぐらい使われています。mac miniでは5wしか消費されていなかたのに全然違う。。。

付属のUSBケーブルでUPSと接続しておきます。

ソフトウェア設定

apcupsdというデーモンで管理します。これによって、UPSの電池が切れそうになったらLinuxが自動的にシャットダウンされます。

aptで入るのでインストールします。

matsu@dell ~> sudo apt install apcupsd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apcupsd-doc
Suggested packages:
  apcupsd-cgi
The following NEW packages will be installed:
  apcupsd apcupsd-doc
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 532 kB of archives.
After this operation, 1,743 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.riken.jp/Linux/ubuntu focal/universe amd64 apcupsd-doc all 3.14.14-3build1 [328 kB]
Get:2 http://ftp.riken.jp/Linux/ubuntu focal/universe amd64 apcupsd amd64 3.14.14-3build1 [204 kB]
Fetched 532 kB in 3s (212 kB/s)
Selecting previously unselected package apcupsd-doc.
(Reading database ... 256476 files and directories currently installed.)
Preparing to unpack .../apcupsd-doc_3.14.14-3build1_all.deb ...
Unpacking apcupsd-doc (3.14.14-3build1) ...
Selecting previously unselected package apcupsd.
Preparing to unpack .../apcupsd_3.14.14-3build1_amd64.deb ...
Unpacking apcupsd (3.14.14-3build1) ...
Setting up apcupsd (3.14.14-3build1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/apcupsd.service → /lib/systemd/system/apcupsd.service.
Setting up apcupsd-doc (3.14.14-3build1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.6) ...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US:en",
        LC_ALL = (unset),
        LC_CTYPE = "UTF-8",
        LC_COLLATE = "C",
        LC_TERMINAL = "iTerm2",
        LANG = "C"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US:en",
        LC_ALL = (unset),
        LC_CTYPE = "UTF-8",
        LC_COLLATE = "C",
        LC_TERMINAL = "iTerm2",
        LANG = "C"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
 23 files changed, 816 insertions(+)
 create mode 100755 apcupsd/apccontrol
 create mode 100644 apcupsd/apcupsd.conf
 create mode 100755 apcupsd/changeme
 create mode 100755 apcupsd/commfailure
 create mode 100755 apcupsd/commok
 create mode 100644 apcupsd/hosts.conf
 create mode 100755 apcupsd/killpower
 create mode 100644 apcupsd/multimon.conf
 create mode 100755 apcupsd/offbattery
 create mode 100755 apcupsd/onbattery
 create mode 100755 apcupsd/ups-monitor
 create mode 100644 default/apcupsd
 create mode 100755 init.d/apcupsd
 create mode 120000 init.d/ups-monitor
 create mode 120000 rc0.d/K01apcupsd
 create mode 120000 rc1.d/K01apcupsd
 create mode 120000 rc2.d/S01apcupsd
 create mode 120000 rc3.d/S01apcupsd
 create mode 120000 rc4.d/S01apcupsd
 create mode 120000 rc5.d/S01apcupsd
 create mode 120000 rc6.d/K01apcupsd
 create mode 120000 systemd/system/multi-user.target.wants/apcupsd.service

インストール直後は勝手にデーモンが立ち上がって稼働しだします。初期設定を1つもしていないのに。。。

結果的には初期設定で普通に動く設定になっているのでこれだけで設定項目は実質終わりです。

余談ですが、デーモンが立ち上がった直後は、以下のメッセージがブロードキャストされてびっくります。。。。

しかし、これは誤送信っぽいです。

Broadcast message from root@dell (somewhere) (Tue Apr 13 16:57:46 2021):
Warning communications lost with UPS

設定されているパラメータを確認

apctestコマンドでステータスを表示できます。ステータスを表示するとlockファイルが作成できないというエラーがある表示が出るのですが、ちゃんと動いています。どうやら、/var/lock/LCK.. というファイルがapcupsdが作っているファイルのようです。startすると作成されてstopすると消えます。なので、ちゃんと動いていそうな感じはします。

matsu@dell ~> sudo apctest
[sudo] password for matsu:
2021-04-13 18:08:20 apctest 3.14.14 (31 May 2016) debian
Checking configuration ...
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
apctest FATAL ERROR in apctest.c at line 311
Unable to create UPS lock file.
  If apcupsd or apctest is already running,
  please stop it and run this program again.
apctest error termination completed

設定ファイルのパラメータを覗いてみます。ファイルは /etc/apcupsd/apcupsd.conf にあります。

UPSCABLE usb

UPSとの通信を何で行っているかです。USBなのでそのままでOK。

BATTERYLEVEL 5

電池の残りが5%になったらshutdown -hを実行するということ。

MINUTES 3

電池の残りが3分以下になったらshutdown -hを実行するということ。上記とor条件かなと思います。

ANNOY 300

シャットダウンの300秒前から、broadcastメッセージを出してユーザにログアウトを促す。

停電のテスト

商用電源を抜き差ししてみます。

流石にシャットダウンされては困るので短時間抜き差ししてみます。

抜いてみたときのログ。/var/log/syslog

Apr 13 17:06:20 dell apcupsd[18732]: Power failure.
Apr 13 17:06:26 dell apcupsd[18732]: Running on UPS batteries.

同時にメールがrootに飛びます。

商用電源を復帰させたときのログ

Apr 13 17:06:55 dell apcupsd[18732]: Mains returned. No longer on UPS batteries.
Apr 13 17:06:55 dell apcupsd[18732]: Power is back. UPS running on mains.

コメント