Centos7 安装Zabbix Agent 3.4-日常笔记

Zabbix Server 系统版本:Centos7  3.10.0-514.21.2.el7.x86_64

Zabbix Server版本:Zabbix 3.4.2

准备被监控的主机的系统版本:Centos7

一、导入Zabbix源

Zabbix官方提供了源,目录:http://repo.zabbix.com/zabbix/。需要根据自己使用的Zabbix Server版本与系统版本选择匹配的源。

比如博主Zabbix Server是3.4.2,Agent 操作系统是Centos7,博主就选择了下面的源。

rpm -ihv http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

如果不小心装错了可以使用下面呢命令卸载源:

rpm -e zabbix-release-3.4-2.el7.noarch

并更新yum源:

yum clean all
yum makecache

 

二、安装Agent客户端

yum install zabbix-agent -y

三、修改配置文件

vim /etc/zabbix/zabbix_agentd.conf

需要修改该文件以下内容:

Server=192.168.1.132   # 用于被动模式,数据获取
ListenPort=10050
ServerActive=192.168.1.132  # 用于主动模式,数据提交
Hostname=rd_upsource  # 此名称必须与服务器端的配置一致
EnableRemoteCommands = 1  #允许远程执行命令

四、启动Agent

systemctl start zabbix-agent

启动的时候可能会无法启动,提示:ob for zabbix-agent.service failed because a configured resource limit was exceeded. See “systemctl status zabbix-agent.service” and “journalctl -xe” for details.

经过本人研究需要关闭SELinux,才能启动Agent。

临时关闭:

setenforce 0

永久关闭:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可

五、自动部署脚本

echo "Welcome to use the zabbix-agent automatic installation script."
echo "by yaping.yang 2018/01/24"
echo "Please input zabbix-server IP:"
read zabbix_server_ip
echo "Please input zabbix-agent hostname:"
read zabbix_agent_hostname
echo "You zabbix server ip is     :$zabbix_server_ip"
echo "You zabbix agent hostname is:$zabbix_agent_hostname"
echo "Please confirm the above information(yes|no,y|n):"
read confirm_input
if [[ $confirm_input == "yes" || $confirm_input == "y" ]];then
    echo "Start..."
else
    echo "exit"
    exit
fi
# install zabbix
rpm -ihv http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum install zabbix-agent -y

# configuation zabbix
sed -i "s/Server=.*/Server=$zabbix_server_ip/" /etc/zabbix/zabbix_agentd.conf
sed -i 's/# ListenPort=.*/ListenPort=10050/' /etc/zabbix/zabbix_agentd.conf
sed -i "s/ServerActive=.*/ServerActive=$zabbix_server_ip/" /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=.*/Hostname=$zabbix_agent_hostname/" /etc/zabbix/zabbix_agentd.conf
sed -i 's/# EnableRemoteCommands=.*/EnableRemoteCommands=1/' /etc/zabbix/zabbix_agentd.conf


# disable SELINUX
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
# autoboot agent
systemctl enable zabbix-agent
systemctl restart zabbix-agent
systemctl status zabbix-agent

# allow to through firewalld
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --add-port 10050/tcp --permanent
sudo firewall-cmd --reload

 

分享到:更多 ()