# Ubuntu 安裝APC管理程式 : apcupsd ## 前情提要, 設備, 環境 * OS : Ubuntu 22.04 * UPS : APC BN650M1-TW (650VA/360W 離線式)  詳細介紹可參考網友的這篇文章: https://forum.gamer.com.tw/C.php?bsn=60030&snA=489621 APC的UPS在Windows平台下可以使用下面的[PowerChute Personal Edition](https://www.se.com/tw/zh/product-range/61934-powerchute-personal-edition-pcpe),︁使用起來很方便 但是其他平台下(linux)則必須使用**apcupsd**這套軟體才能監控  ## 設定apcupsd ### 安裝必要套件 ``` sudo apt-get -y install apcupsd apcupsd-cgi apache2 ``` ### 修改conf檔 ``` sudo vim /etc/apcupsd/apcupsd.conf ``` 須包含以下: * `UPSNAME XXX` UPS名稱 * `UPSCABLE usb` 以USB連接UPS * `UPSTYPE usb` 以USB連接UPS * `DEVICE` 設定裝置,︁**Ubuntu這邊不能使用預設的`DEVICE /dev/ttyS0`**,︁否則會無法連接 *  * `POLLTIME 60` 輪詢UPS狀態的時間間隔 ### 修改設定完成標記 ``` sudo vim /etc/default/apcupsd ``` 把`ISCONFIGURED=no`改成`ISCONFIGURED=yes` ## 終端機監控 查看目前的各項資訊 ``` apcaccess status ```  --- 執行測試,︁要先把apcupsd先關掉 ``` sudo systemctl stop apcupsd sudo apctest 選擇你要進行的測試 sudo systemctl start apcupsd ```  比較常會用的是2號,︁測試切換到電池供電有沒有問題 ## 網頁監控 把.cgi檔複製到 `/var/www/html/apcupsd` ``` cd /var/www/html sudo mkdir apcupsd sudo cp /usr/lib/cgi-bin/apcupsd/*.cgi /var/www/html/apcupsd ``` Apache2預設是不支援使用cgi的,︁啟用方法: ``` cd /etc/apache2/mods-enabled sudo ln -s ../mods-available/cgi.load cd /etc/apache2 sudo vim apache2.conf 最下方新增 "Include /etc/apache2/apcupsd.conf" ```  ``` sudo vim /etc/apache2/apcupsd.conf ``` 貼上以下內容 ```xml <Directory "/var/www/html/apcupsd"> Order allow,deny Allow from all AllowOverride None Options Indexes FollowSymLinks ExecCGI AddHandler cgi-script .cgi Require all granted </Directory> ``` 重啟Apache服務 ``` sudo service apache2 reload ``` 開啟網頁 http://localhost/apcupsd/  如果進不去,︁可能是因為還沒開啟`apache2` ``` sudo service apache2 start ``` 如果想要在開機時就啟動`apache2` ``` sudo systemctl enable apache2 ``` <details close> <summary> 可以從網頁上查看各項資訊: </summary> <a href="http://localhost/apcupsd/multimon.cgi">http://localhost/apcupsd/multimon.cgi</a><br> <img src="https://hackmd.io/_uploads/Bye_OEWZkx.png"> <hr> <a href="http://localhost/apcupsd/upsstats.cgi">http://localhost/apcupsd/upsstats.cgi</a><br> <img src="https://hackmd.io/_uploads/Byw5KEWWJg.png"> <hr> <a href="http://localhost/apcupsd/upsstats.cgi">http://localhost/apcupsd/upsstats.cgi</a><br> <img src="https://hackmd.io/_uploads/Hk6u_4b-1e.png"> </details> ## 參考資料 * https://help.ubuntu.com/community/apcupsd * https://stackoverflow.com/questions/28138997/cgi-script-downloads-instead-of-running * https://httpd.apache.org/docs/2.4/howto/cgi.html * https://askubuntu.com/questions/1326402/usb-trouble-shooting-for-apc-ups-not-accessible * https://forum.gamer.com.tw/C.php?bsn=60030&snA=489621 * https://stackoverflow.com/questions/28138997/cgi-script-downloads-instead-of-running
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up