zabbix监控远程主机
在Zabbix服务器上安装Zabbix代理程序
在远程主机上安装Zabbix代理程序。安装方式取决于操作系统,可以从Zabbix官网上下载相应的安装包进行安装。
监控agent1
在agent1上安装agent
yum install zabbix-agent
另外在zabbix server上要关闭防火墙和selinux,防止zabbix server无法监听,这是临时关闭
setenforce 0
永久关闭,进入配置文件修改,重启主机即可
vim /etc/selinux/config
SELINUX=disabled
在Zabbix服务器上创建一个新的主机,将远程主机添加为被监控的主机
首先来查看一下远程主机agent1的ip
[root@agent1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:63:ac:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.126.142/24 brd 192.168.126.255 scope global noprefixroute dynamic ens33
valid_lft 1123sec preferred_lft 1123sec
inet6 fe80::3615:945b:279f:489e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
添加模板才能查看主机信息
点击添加,点击更新
配置Zabbix代理程序以允许与Zabbix服务器通信。在代理程序的配置文件中,将“Server”和“ServerActive”参数设置为Zabbix服务器的IP地址
配置zabbix-agent端的配置文件,启动服务并做成开机自动启动
vim /etc/zabbix/zabbix_agentd.conf
97 Server= 修改成zabbix监控服务器的IP
[root@agent1 ~]# systemctl restart zabbix-agent
[root@agent1 ~]# systemctl enable zabbix-agent
[root@agent1 ~]# lsof -i:10050
报错:
没有连接上,检查下
无法连接服务器的10050端口
查看服务器日志:
[root@zabbixserver ~]# tail -f /var/log/zabbix/zabbix_server.log
19899:20230429:163718.113 server #32 started [preprocessing worker #2]
19898:20230429:163718.128 server #31 started [preprocessing worker #1]
19888:20230429:165734.514 Zabbix agent item "agent.ping" on host "agent1.cluster.com" failed: first network error, wait for 15 seconds
19889:20230429:165834.185 temporarily disabling Zabbix agent checks on host "agent1.cluster.com": host unavailable
19885:20230429:170622.288 Zabbix agent item "system.cpu.intr" on host "agent1.cluster.com" failed: first network error, wait for 15 seconds
19872:20230429:170719.522 executing housekeeper
19872:20230429:170719.650 housekeeper [deleted 0 hist/trends, 1 items/triggers, 14 events, 8 problems, 0 sessions, 0 alarms, 0 audit items in 0.121793 sec, idle for 1 hour(s)]
19889:20230429:170722.571 temporarily disabling Zabbix agent checks on host "agent1.cluster.com": host unavailable
查看远程主机代理程序状态:
[root@agent1 ~]# systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Agent
Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2023-04-29 17:13:17 CST; 19min ago
Main PID: 7778 (zabbix_agentd)
CGroup: /system.slice/zabbix-agent.service
├─7778 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
├─7779 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
├─7780 /usr/sbin/zabbix_agentd: listener #1 [waiting for connecti...
├─7781 /usr/sbin/zabbix_agentd: listener #2 [waiting for connecti...
├─7782 /usr/sbin/zabbix_agentd: listener #3 [waiting for connecti...
└─7783 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
4月 29 17:13:17 agent1.cluster.com systemd[1]: Stopped Zabbix Agent.
4月 29 17:13:17 agent1.cluster.com systemd[1]: Starting Zabbix Agent...
4月 29 17:13:17 agent1.cluster.com systemd[1]: PID file /run/zabbix/zabbix....
4月 29 17:13:17 agent1.cluster.com systemd[1]: Started Zabbix Agent.
Hint: Some lines were ellipsized, use -l to show in full.
可能agent主机端口被防火墙拦截了,关闭
systemctl stop firewalld && systemctl disable firewalld
成功连接