站长资源服务器
Linux平台Zabbix Agent的安装配置方法
这里简单总结一下Linux平台Zabbix Agent的安装配置,实验测试的Zabbix版本比较老了(Zabbix 3.0.9),不过版本虽然有点老旧,但是新旧版本的安装步骤、流程基本差别不大。这里的总结仅仅当成一个操作手册,后续会更新或添加部分内容。
Linux版本众多,下面文档仅仅在RHEL、CentOS几个版本测试过。不同版本可能安装等有所差别,后续再补充完善。
1:首先检查zabbix_server的版本
# zabbix_server --version zabbix_server (Zabbix) 3.0.9 Revision 67444 19 April 2017, compilation time: Apr 23 2017 18:05:43 Copyright (C) 2017 Zabbix SIA License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it according to the license. There is NO WARRANTY, to the extent permitted by law
2:检查被监控服务器的Linux发行版本
例如 RHEL或CentOS
# more /etc/redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
# more /etc/issue
Oracle Linux Server release 5.7
Kernel \r on an \m
3: 根据Zabbix Server的版本和Linux发行版本选择去下载对应的Zabbix Agent安装包
这个测试环境,我们就选择下载zabbix-agent-3.0.9-1.el5.x86_64.rpm这个RMP包,下载地址为http://repo.zabbix.com/zabbix/3.0/rhel/5/x86_64/
# rpm -ivh zabbix-agent-3.0.9-1.el5.x86_64.rpm warning: zabbix-agent-3.0.9-1.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 79ea5ed4 Preparing... ########################################### [100%] 1:zabbix-agent ########################################### [100%]
当然,如果服务器可以访问外网,也可以使用下面命令直接安装。
#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/5/x86_64/zabbix-agent-3.0.9-1.el5.x86_64.rpm
或者你配置了yum源,那就更简单方便
#yum -y install zabbix-agent
我们知道,默认情况下Zabbix Server一般从客户端主动获取数据,当然客户端也可以主动将数据推送给服务端,客户端通过zabbix_sender指令来实现向服务端主动推送数据。这里不介绍zabbix_sender的安装、配置。后续打算单独介绍。
4:修改Zabbix-Agent的配置文件
首先找到zabbix_agentd.conf的位置,可以使用 rpm -ql zabbix-agent或 rpm -ql zabbix-agent | grep zabbix_agentd.conf
# rpm -ql zabbix-agent /etc/init.d/zabbix-agent /etc/logrotate.d/zabbix-agent /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf /usr/sbin/zabbix_agentd /usr/share/doc/zabbix-agent-3.0.9 /usr/share/doc/zabbix-agent-3.0.9/AUTHORS /usr/share/doc/zabbix-agent-3.0.9/COPYING /usr/share/doc/zabbix-agent-3.0.9/ChangeLog /usr/share/doc/zabbix-agent-3.0.9/NEWS /usr/share/doc/zabbix-agent-3.0.9/README /usr/share/man/man8/zabbix_agentd.8.gz /var/log/zabbix /var/run/zabbix # rpm -ql zabbix-agent | grep zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf
编辑参数文件zabbix_agentd.conf
### Option: Server
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.
#
# Mandatory: no
# Default:
# Server=
Server=127.0.0.1 #用Zabbix_Server的IP地址替换127.0.0.1
### Option: ServerActive
# List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=
ServerActive=127.0.0.1 #用Zabbix_Server的IP地址替换127.0.0.1
### Option: Hostname
# Unique, case sensitive hostname.
# Required for active checks and must match hostname as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=
Hostname=Zabbix server #Zabbix客户端主机名替换Zabbix server
5:启动Zabbix-agent服务
启动Zabbix-Agent的几种方式,注意实际环境,有些Linux版本并不支持下面的一些方式。
方式1:
# service zabbix-agent start Starting Zabbix agent: [ OK ] # service zabbix-agent stop Shutting down Zabbix agent: [ OK ] # service zabbix-agent status zabbix_agentd (pid 8120) is running...
方式2:
systemctl start zabbix-agent.service systemctl stop zabbix-agent.service
方式3:
/etc/init.d/zabbix-agent start /etc/init.d/zabbix-agent stop /etc/init.d/zabbix-agent status
6: 设置zabbix-agent服务开机自启动
# chkconfig --add zabbix-agent # chkconfig --list | grep zabbix-agent zabbix-agent 0:off 1:off 2:off 3:off 4:off 5:off 6:off
7: 检查被监控的Linux服务器防火墙是否开通tcp 10050端口
这个非常简单,不做过多阐述。但是必须检查确认,否则Zabbix Server没法获取数据。
如果使用iptables管理管理防火墙,例如(CentOS 5,6)
修改配置文件,防火墙的配置文件/etc/sysconfig/iptables,新增下面这样的一条配置
-A RH-Firewall-1-INPUT -p tcp --dport 10050 -j ACCEPT
重启防火墙service iptables restart
如果使用firewalld管理防火墙(例如,CentOS 7.x)
firewall-cmd --zone=public --add-port=10050/tcp --permanent 添加端口
firewall-cmd --reload 重启防火墙服务
firewall-cmd --query-port=10050/tcp,查询某个端口是否开放
版本问题:
注意事项:关于Zabbix Server和Zabbix Agent的版本是否要一致问题,这个尽量一致,版本一致,可以避免杂七杂八的问题出现。官方文档也有相关说明:Zabbix Server对Zabbix Agent是向下兼容的。但是要注意有些参数需要修改。请注意,高于3.0的Zabbix代理不能与Zabbix服务器3.0一起使用。具体如下所示:
12 Version compatibility
Supported agents
Zabbix agents from previous Zabbix versions are compatible with Zabbix 3.0. However, you may need to review the configuration of older agents as some parameters have changed, for example, parameters related to logging for versions before 3.0.
To take full advantage of new and improved items, improved performance and reduced memory usage, use the latest 3.0 agent.
Note that Zabbix agent newer than 3.0 cannot be used with Zabbix server 3.0.
虽然官方文档提示高于3.0的Zabbix代理不能与Zabbix服务器3.0一起使用,但是不清楚是指大版本还是小版本,对于小版本。例如,我的测试环境Zabbix Server为3.0.9,客户端也可以安装zabbix-agent-3.0.28这个版本,测试暂未发现问题。
总结