Windows Server上安装部署Zabbix agent

未分类

下载并解压到指定目录
Zabbix下载页面:https://www.zabbix.com/download

当前最新版本zabbix-agent下载
https://www.zabbix.com/downloads/3.4.0/zabbix_agents_3.4.0.win.zip

解压到C盘,并重命名目录为zabbix

# 到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
1
控制台输出信息如下,表示安装成功:
zabbix_agentd.exe [4864]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [4864]: event source [Zabbix Agent] installed successfully
1
2
启动zabbix-agent客户端
> C:\zabbix\bin\win64\zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -s
1
控制台输出下面信息,表示安装成功:
zabbix_agentd.exe [11052]: service [Zabbix Agent] started successfully
1
查看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的解压目录,注意防火墙问题,配置文件问题

参考:https://www.cnblogs.com/xqzt/p/5130469.html

发表回复