遠程服務器狀態監控


目的:實現對遠端服務器的狀態進行監控

首先貼貼出github地址:https://github.com/BotoX/ServerStatus/

通過主服務器監控遠端的服務器的狀態.

安裝和使用:

主服務器

注意事項:

切換到非特權用戶或創建一個。端口35601需要空閑並轉發/打開才能運行服務器。

git clone https://github.com/BotoX/ServerStatus.git
cd ServerStatus/server
make
./sergate

如果安裝完成,修改配置文件,只需要編輯config.json就可以了.

{"servers":
    [
        {
            "username": "s01",
            "name": "Mainserver 1",
            "type": "Dedicated Server",
            "host": "GenericServerHost123",
            "location": "Austria",
            "password": "some-hard-to-guess-copy-paste-password"
        },
    ]
}

如果你暫時不需要啟動服務,在配置文件中添加即可.

"disabled": true

相關的命令參數的查看,只需要在運行二進制文件時天劍-h參數.

    -h, --help            Show this help message and exit
    -v, --verbose         Verbose output
    -c, --config=<str>    Config file to use
    -d, --web-dir=<str>   Location of the web directory
    -b, --bind=<str>      Bind to address
    -p, --port=<int>      Listen on port

然后:不要忘記復制或者移動web目錄(ServerStatus/status)到你的webserver能找到的地方.

運行:

可以通過啟動腳本來運行主服務器.

Debian和其他基於init.d的系統.

復制the init.d script to /etc/init.d

cp ServerStatus/other/sergate.initd /etc/init.d/sergate

使用編輯器添加下列行

# Change this according to your setup!
DAEMON_PATH="/usr/local/share/ServerStatus/server"
WEB_PATH="/var/www/botox.bz/status"
DAEMON="sergate"
OPTS="-d $WEB_PATH"
RUNAS="www-data"

以root方式運行

service sergate start

設置自啟動

update-rc.d sergate defaults

Arch Linux and other systemd based systems

復制systemd service to /etc/systemd/system

cp ServerStatus/other/sergate.service /etc/systemd/system/sergate.service

使用編輯器添加下列行

WorkingDirectory=/usr/local/share/ServerStatus/server
User=botox.bz
Group=http
ExecStart=/usr/local/share/ServerStatus/server/sergate -d /home/botox.bz/status

啟動:

systemctl start sergate

設置自啟動

systemctl enable sergate

注意:確保運行主服務器的用戶可以訪問Web路徑並可以寫入$web_path/json。

客戶端

三種實現方式

  • Python2 [preferred]
  • Python2-psutil
  • Bash

三種方式都非常容易實現.

Python2和Bash客戶端只支持GNU/Linux.Python2-psutil支持很多的操作系統,比如BSD or Window.

自動安裝

自動安裝,你需要獲得證書,可以這樣運行

wget https://raw.github.com/BotoX/ServerStatus/master/other/client-setup.sh
bash client-setup.sh

常規的安裝

再啟動文件中添加下列行

Python Client

SERVER = "status.botox.bz"
PORT = 35601
USER = "s01"
PASSWORD = "some-hard-to-guess-copy-paste-password"
INTERVAL = 1 # Update interval

Python2-psutil Client

SERVER = "status.botox.bz"
PORT = 35601
USER = "s01"
PASSWORD = "some-hard-to-guess-copy-paste-password"
INTERVAL = 1 # Update interval

客戶端的操作系統必須支持psutil project.

Windows系統

要么使用預編譯的自包含版本,要么安裝python2和psutil。預編譯版本已使用py2exe生成。如果您想自己構建安裝腳本,則會包含它。安裝完所有依賴項后,

運行“python setup.py py2exe”

Windows配置的工作方式不同,使預編譯版本和自包含版本都可以。根據您的設置編輯client.cfg文件

[client]
SERVER = status.botox.bz
PORT = 35601
USER = s01
PASSWORD = some-hard-to-guess-copy-paste-password
INTERVAL = 1

Bash客戶端

SERVER="status.botox.bz"
PORT=35601
USER="s01"
PASSWORD="some-hard-to-guess-copy-paste-password"
INTERVAL=1 # Update interval

運行

確保你的客戶端已經配置正確,運行.可以通過啟動腳本或cronjob使其自動啟動,也可以手動啟動.

nohup ./client.py &> /dev/null &

Debian 和其他基於init.d的系統

添加下列文件到/etc/rc.local

su -l $USERNAME -c "/path/to/client.py &> /dev/null &"

Arch Linux 和其他基於systems的系統

創建文件/etc/systemd/system/serverstatus.service來創建新的systemd服務:

[Unit]
Description=ServerStatus Client
After=network.target

[Service]
Type=simple
IgnoreSIGPIPE=no
User=$USERNAME
ExecStart=/path/to/client.py

[Install]
WantedBy=multi-user.target

注意:

ignoresigpipe=no對於bash客戶機很重要,當缺少此行時,它將不會重新連接,而且會損壞管道錯誤淹沒日志.

如果主服務器出現故障,也不用擔心客戶機,他們將繼續嘗試重新連接,直到他們能夠再次訪問主服務器。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM