在 CentOS6 上安装 Zabbix3.0 Agent 并开启客户端自动注册

时间:2023-03-08 22:55:15
在 CentOS6 上安装 Zabbix3.0 Agent 并开启客户端自动注册
 #!/bin/bash

 #
# 、配置yum源
# cat /etc/redhat-release |grep -i centos |grep '6.[[:digit:]]' &>/dev/null if [[ $? != ]]
then
echo -e "不支持的操作系统,该脚本只适用于CentOS 6.x 操作系统"
exit
fi os_m=$(uname -m)
za_rpm=$(curl -s http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/6/$os_m/ |grep release |awk -F '>|<' '{print $3}')
rpm -i --force http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/6/$os_m/$za_rpm if [[ $? != ]]
then
echo -e "yum源配置失败,请检查网络或者其他原因"
exit
fi sed -i 's@repo.zabbix.com@mirrors.aliyun.com/zabbix@' /etc/yum.repos.d/zabbix.repo #
# 、使用yum安装Zabbix
# yum install -y zabbix-agent zabbix-sender
chkconfig zabbix-agent on
iptables -I INPUT -m state --state NEW -p tcp --dport -j ACCEPT
/etc/init.d/iptables save ping -c $ &>/dev/null if [[ $? == ]]
then
sed -i 's/^Server=127.0.0.1/Server='$'/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^ServerActive=127.0.0.1/ServerActive='$'/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^Hostname=Zabbix server/Hostname='`hostname`'/' /etc/zabbix/zabbix_agentd.conf
sed -i '/^# HostMetadataItem=/a HostMetadataItem=system.uname' /etc/zabbix/zabbix_agentd.conf /etc/init.d/zabbix-agent start
else
sed -i 's/^Hostname=Zabbix server/Hostname='`hostname`'/' /etc/zabbix/zabbix_agentd.conf
sed -i '/^# HostMetadataItem=/a HostMetadataItem=system.uname' /etc/zabbix/zabbix_agentd.conf echo -e "\n\t请手动修改 '/etc/zabbix/zabbix_agentd.conf' 文件\n\n\t\tServer=Zabbix-Server_IP\n\t\tServerActive=Zabbix-Server_IP\n\n\t然后执行 '/etc/init.d/zabbix-agent start' 启动Zabbix-agent\n"
fi