#!/bin/bash
##安装agent
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install zabbix-agent -y
##修改主机名及服务器IP
sed -i "s/Hostname=Zabbix server/Hostname=$(hostname)/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/Server=127.0.0.1/Server=192.168.150.19/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/ServerActive=127.0.0.1/ServerActive=192.168.150.19/g" /etc/zabbix/zabbix_agentd.conf
##显示修改配置
cat /etc/zabbix/zabbix_agentd.conf |grep -v -E "(^#|^$)"
##iptables开放 10050端口
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
##加入的配置文件
num=$(grep -nr 'dport 22 ' /etc/sysconfig/iptables | awk -F ':' '{print $1}')
numa=$num"a"
sed -i "N;$numa -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT" /etc/sysconfig/iptables
##这个有时可以用自动插入,有时不行,不知道为什么?
systemctl start zabbix-agent
systemctl enable zabbix-agent