目录
1.准备工作:主机说明
主机 | ip |
c82(zabbix服务机) | 192.168.187.134 |
c83 | 192.168.187.131 |
windows10 | 192.168.187.1 |
# 这里我们分别准备了
一台zabbix服务机(已部署好zabbix服务,实现效果图) 详情部署参考前面的文章!
一台zabbix受控机
还有我们本机windows系统(使用VMnet8的ipv4地址)
2.部署zabbix受控机
# 1.我们在zabbix官网上下载zabbix_agent服务软件包
# 这是目前最新版v6.4.6
[root@c82 ~]# wget wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
[root@c82 ~]# ls
anaconda-ks.cfg zabbix-6.4.6.tar.gz
[root@c82 ~]# tar xf zabbix-6.4.6.tar.gz
[root@c82 ~]# ls
anaconda-ks.cfg zabbix-6.4.6 zabbix-6.4.6.tar.gz
# 2.创建zabbix用户与组
[root@c82 ~]# groupadd --system zabbix
[root@c82 ~]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
# 3.下载编译工具与服务依赖
[root@c82 ~]# yum -y install gcc gcc-c++ make pcre-devel
# 4.查询编译zabbix-agent所需的依赖
[root@c82 zabbix-6.4.6]# ./configure --help | grep agent
--enable-agent Turn on build of Zabbix agent and client utilities
--enable-agent2 Turn on build of Zabbix agent 2
# 这里选择第一个
# 开始编译
[root@c82 zabbix-6.4.6]# ./configure --enable-agent
.....省略
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
# 5.让我们立即输入make install 进行安装
# 6.安装完成后可以在/usr/local/etc下看到agent的主配置文件
[root@c82 zabbix-6.4.6]# cd /usr/local/etc/
[root@c82 etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
# 7.编辑agent主配置文件
[root@c82 etc]# vim zabbix_agentd.conf
# 编写配置文件中的这三行
Server=192.168.187.134 # 指定zabbix服务端的ip
ServerActive=192.168.187.134 # 指定zabbix服务端的ip
Hostname=c82 # 自定义命名,以后在服务端用这个名字来连接这台主机
# 8.启动zgent服务,查看端口号
[root@c82 zabbix-6.4.6]# zabbix_agentd
[root@c82 zabbix-6.4.6]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
# 9.关闭本机的防火墙与selinux
[root@c82 etc]# systemctl disable --now firewalld
[root@c82 etc]# setenforce 0
[root@c82 etc]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
3.部署window系统受控
# 1.在官网下载agent软件包在本地并解压,这里我是直接解压在c盘
D:\zabbix
# 2.编辑c:\zabbix\conf\zabbix_agentd.conf
# 编写配置文件中的这三行
Server=192.168.187.134 # 指定zabbix服务端的ip
ServerActive=192.168.187.134 # 指定zabbix服务端的ip
Hostname=win10 # 自定义命名,以后在服务端用这个名字来连接这台主机
# 3.以管理员身份进入命令行模式
C:\Windows\system32>cd C:\zabbix\bin
# 4.查看帮助文档
C:\zabbix\bin>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
# 5.根据帮助文档注释安装agent
C:\zabbix\bin>zabbix_agentd.exe -c "C:\zabbix\conf\zabbix_agentd.conf" -i
zabbix_agentd.exe [2960]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [2960]: event source [Zabbix Agent] installed successfully
# 6.安装成功后打开本地的服务
# 发现有一个名为Zabbix Agent的服务,点击启动服务
# 7.在命令行查看启动的端口号
C:\zabbix\bin>netstat -an
活动连接
协议 本地地址 外部地址 状态
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:902 0.0.0.0:0 LISTENING
TCP 0.0.0.0:912 0.0.0.0:0 LISTENING
TCP 0.0.0.0:10050 0.0.0.0:0 LISTENING
# 这里可以看到10050端口出来了
4. zabbix控制机部署
# 在网页界面的左边Monitoring选项下面的Hosts
# 点击右上角的Create host
# 2台主机做同样的操作
# 关闭windows上的防火墙或自定义一个放行规则
# 最终效果图
# 下面的ZBX亮绿灯表示成功
5.添加监控项目
# 准备工作,在受控端的/tmp/下面创建一个名为hehehe的文件并随便写入内容
# 1.创建文件并写入内容,查看md5码
[root@c82 ~]# cd /tmp/
[root@c82 tmp]# vim hehehe
[root@c82 tmp]# cat hehehe
weqeq
1eqweqe
rqerwqe
[root@c82 tmp]# md5sum hehehe
b78c96e04b3b8510d8cd3633f665b901 hehehe
# md5码说明:
linux中每个文件都会有1个md5值。 当两个文件的md5值相同,表示这两个文件完全相同。 md5值常用于大型文件的完整性检查,即给予方给出文件的同时给出md5值,接收方收到文件后再次计算md5值,如果两个md5值相同,说明文件在传输过程中没有损坏。
# 如果文件内容被进行增删改,则文件的md5码会进行变化,用变化的md5码就可以对文件来进行监控
# 2.对文件进行修改
[root@c83 tmp]# cat hehehe
weqeq
1eqweqe
rqerwqe
wqeqeq
eqweqeq
[root@c83 tmp]# md5sum hehehe
51d912c8bfed56b6a6a1c13efb9658a9 hehehe
# 这里可以清楚的看到文件的md5码进行了变化
# 点开主机的items选项,然后点击右上交的Create item进行创建监控项目
# 创建完成后就可以在host的items中看到新增的监控项
6.自定义触发规则
# 刚刚我们定义了新的监控项目,但是还没有定义触发规则,所以修改了文件他也不会触发
# 现在我们来定义触发规则
# 点击host的Triggers,右上角点击创建触发器
# 然后我们就可以在下面找到自定义的监控项目与触发规则
# 这时我们再修改一下文件
[root@c83 tmp]# echo "qwer" >> hehehe
# 然后在首页过一分钟就可以看到报警