Windows Server上安裝部署Zabbix agent


https://cloud.tencent.com/developer/article/1010422

 

Windows Server上安裝部署Zabbix agent

下載並解壓到指定目錄

Zabbix下載頁面:https://www.zabbix.com/download

# 到zabbix_agents_3.4.0.win.zip所在的目錄下執行,筆者使用了git bash,如果沒下載git,建議解壓到C盤並重命名為zabbix unzip zabbix_agents_3.4.0.win -d C:/zabbix 
  • 查看zabbix-agent解壓之后的目錄結構
# 移動到C盤,執行下面命令查看
> cd C: > tree zabbix

1、conf目錄存放是agent配置文件 2、bin文件存放windows下32位和64位安裝程序

配置zabbix-agent.win.conf

找到conf下的配置文件 zabbix_agentd.win.conf ,修改LogFile、Server、ServerActive 、Hostname這幾個參數。具體配置如下:

# 移動到C盤的zabbix目錄下conf目錄下,編輯zabbix_agentd.win.conf,修改下面幾個參數 LogFile=C:\zabbix\zabbix_agentd.log Server=192.168.1.134 ServerActive=192.168.1.134:10051 Hostname=Win-server-2016
  • 參數含義說明:
1、Server: zabbix server的ip地址, 2、ServerActive: zabbix 主動監控server的ip地址, 3、其中Server和ServerActive都指定zabbix Server的IP地址,不同的是,前者是被動后者是主動。也就是說Server這個配置是用來允許172.17.22.155這個ip來我這取數據。而ServerActive的172.17.22.155的意思是,客戶端主動提交數據給他。 4、Hostname 主機名,必須唯一,區分大小寫。Hostname必須和zabbix web上配置的一直,否則zabbix主動監控無法正常工作。因為agent拿着這個主機名去問server,我有配置主動監控項嗎?server拿着這個主機名去配置里面查詢,然后返回信息。 5、zabbix agent檢測分為主動(agent active)和被動(agent)兩種形式,主動與被動的說法均是相對於agent來討論的。 6、主動:agent請求server獲取主動的監控項列表,並主動將監控項內需要檢測的數據提交給server/proxy 7、被動:server向agent請求獲取監控項的數據,agent返回數據。

zabbix-agent 安裝

參考:https://www.zabbix.com/documentation/3.4/manual/appendix/install/windows_agent

  • 修改好配置文件后,用CMD(需有管理員權限)將Zabbix Agent安裝為Windows系統的服務,在windows控制台下執行以下命令:
> C:\zabbix\bin\win64\zabbix_agentd.exe -i -c C:\zabbix\conf\zabbix_agentd.win.conf
  • 控制台輸出信息如下,表示安裝成功:
zabbix_agentd.exe [4864]: service [Zabbix Agent] installed successfully zabbix_agentd.exe [4864]: event source [Zabbix Agent] installed successfully

啟動zabbix-agent客戶端

> C:\zabbix\bin\win64\zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -s
  • 控制台輸出下面信息,表示安裝成功:
zabbix_agentd.exe [11052]: service [Zabbix Agent] started successfully
  • 查看Windows端口監聽情況
C:\zabbix\bin\win64>netstat -ano | findstr "10050" TCP 0.0.0.0:10050 0.0.0.0:0 LISTENING 10624 ... ... ... #此處省略,詳情見下圖 TCP [::]:10050 [::]:0 LISTENING 10624 C:\zabbix\bin\win64>tasklist | findstr "10624" zabbix_agentd.exe 10624 Services 0 11,892 K
  • 查看任務管理器
  • 查看zabbix_agent的啟動日志zabbix_agentd.log:
 12660:20171218:194616.210 Starting Zabbix Agent [Win-server-2016]. Zabbix 3.4.0 (revision 71462). 12660:20171218:194616.220 **** Enabled features **** 12660:20171218:194616.231 IPv6 support: YES 12660:20171218:194616.241 TLS support: NO 12660:20171218:194616.250 ************************** 12660:20171218:194616.262 using configuration file: C:\zabbix\conf\zabbix_agentd.win.conf 12660:20171218:194616.282 agent #0 started [main process] 9412:20171218:194616.295 agent #1 started [collector] 8968:20171218:194616.306 agent #2 started [listener #1] 12644:20171218:194616.315 agent #3 started [listener #2] 11580:20171218:194616.327 agent #5 started [active checks #1] 12864:20171218:194616.337 agent #4 started [listener #3] 11580:20171218:194616.360 no active checks on server [192.168.1.134:10051]: host [Win-server-2016] not found 11580:20171218:194816.501 no active checks on server [192.168.1.134:10051]: host [Win-server-2016] not found

Windows server 系統防火牆開放10050端口

控制面板–windows 防火牆–高級設置–入站規則–新建規則, 詳細步驟參考下圖:

根據上圖步驟,依次添加,完成入站規則的添加

  • 設置zabbix_agentd服務自啟動

win+R,運行services.msc,默認是自動

zabbix_agentd.exe命令說明

$ ./zabbix_agentd.exe -h usage: zabbix_agentd.exe [-c config-file] zabbix_agentd.exe [-c config-file] -p zabbix_agentd.exe [-c config-file] -t item-key zabbix_agentd.exe [-c config-file] -i [-m] zabbix_agentd.exe [-c config-file] -d [-m] zabbix_agentd.exe [-c config-file] -s [-m] zabbix_agentd.exe [-c config-file] -x [-m] zabbix_agentd.exe -h zabbix_agentd.exe -V A Zabbix daemon for monitoring of various server parameters. Options: -c --config config-file Path to the configuration file (default: "C:\zabbix_agentd.conf") -f --foreground Run Zabbix agent in foreground -p --print Print known items and exit -t --test item-key Test specified item and exit -m --multiple-agents For -i -d -s -x functions service name will include Hostname parameter specified in configuration file Functions: -i --install Install Zabbix agent as service -d --uninstall Uninstall Zabbix agent from service -s --start Start Zabbix agent service -x --stop Stop Zabbix agent service -h --help Display this help message -V --version Display version number Example: zabbix_agentd -c C:\zabbix\zabbix_agentd.conf

批處理腳本agentd.bat

筆者參考別人文章的腳本,下面為Windows批處理腳本zabbix-agentd.bat對客戶端服務器上的zabbix_agentd進行安裝、啟動、停止、卸載

  • 前提:
    • 1、解壓zabbix_agents_3.4.0.win.zip 到C:\zabbix目錄
    • 2、手動修改過參數文件c:\zabbix\conf\zabbix_agentd.win.conf
  • zabbix-agentd.bat腳本內容如下:
@echo off

CHCP 65001

echo **************************************** echo *****Zabbix Agentd Operation************ echo **************************************** echo ** a. start Zabbix Agentd******** echo ** b. stop Zabbix Agentd******** echo ** c. restart Zabbix Agentd******** echo ** d. install Zabbix Agentd******** echo ** e. uninstall Zabbix Agentd******** echo ** f. exit Zabbix Agentd******** echo **************************************** :loop choice /c abcdef /M "please choose" if errorlevel 6 goto :exit if errorlevel 5 goto uninstall if errorlevel 4 goto install if errorlevel 3 goto restart if errorlevel 2 goto stop if errorlevel 1 goto start :start c:\zabbix\bin\win64\zabbix_agentd.exe -c c:\zabbix\conf\zabbix_agentd.win.conf -s goto loop :stop c:\zabbix\bin\win64\zabbix_agentd.exe -c c:\zabbix\conf\zabbix_agentd.win.conf -x goto loop :restart c:\zabbix\bin\win64\zabbix_agentd.exe -c c:\zabbix\conf\zabbix_agentd.win.conf -x c:\zabbix\bin\win64\zabbix_agentd.exe -c c:\zabbix\conf\zabbix_agentd.win.conf -s goto loop :install c:\zabbix\bin\win64\zabbix_agentd.exe -c c:\zabbix\conf\zabbix_agentd.win.conf -i goto loop :uninstall c:\zabbix\bin\win64\zabbix_agentd.exe -c c:\zabbix\conf\zabbix_agentd.win.conf -d goto loop :exit exit

在Zabbix Web UI創建主機,查看監控結果

Configuration – Hosts – Create hosts

創建主機並關聯模板比較簡單,筆者沒做詳細記錄

  • 查看監控結果

安裝心得

根據自己環境定義zabbix的解壓目錄,注意防火牆問題,配置文件問題


免責聲明!

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



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