批量安装:
#!/bin/sh Server=10.16.8.8 ServerActive=10.16.8.8:10050 ip_array=("hostnamerenwole1" "hostnamerenwole2") for ip in ${ip_array[*]} do zabbix=$(ssh $ip 'find /etc -name zabbix_agentd.conf') if [ -f $zabbix ];then ssh $ip 'rpm -ivh //repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm ; yum -y install zabbix-agent' else echo "Already exist, no need to install" fi ssh $ip ' sed -i "s#Server=.*#Server='$Server'#" /etc/zabbix/zabbix_agentd.conf sed -i "s#ServerActive=.*#ServerActive='$ServerActive'#" /etc/zabbix/zabbix_agentd.conf sed -i "s#Hostname=.*#Hostname='$ip'#" /etc/zabbix/zabbix_agentd.conf sed -i "s/# UserParameter=/UserParameter=/g" /etc/zabbix/zabbix_agentd.conf sed -i "s#UserParameter=.*#UserParameter=pro.check,sh /renwole/Apps/check.sh|wc -c#" /etc/zabbix/zabbix_agentd.conf chmod -R 777 /etc/zabbix/zabbix_agentd.conf systemctl restart zabbix-agent ' done
交互式安装:
#cat /renwole/bin/Zabbix_Agent_Single.sh #!/bin/sh read -p "Please enter the HostName:" HostName Server=10.16.8.8 ServerActive=10.16.8.8:10050 zabbix=$(ssh $HostName 'find /etc -name zabbix_agentd.conf') if [ -f $zabbix ];then ssh $HostName 'rpm -ivh //repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm ; yum -y install zabbix-agent' else echo "Already exist, no need to install" fi ssh $HostName ' sed -i "s#Server=.*#Server='$Server'#" /etc/zabbix/zabbix_agentd.conf sed -i "s#ServerActive=.*#ServerActive='$ServerActive'#" /etc/zabbix/zabbix_agentd.conf sed -i "s#Hostname=.*#Hostname='$HostName'#" /etc/zabbix/zabbix_agentd.conf sed -i "s/# UserParameter=/UserParameter=/g" /etc/zabbix/zabbix_agentd.conf sed -i "s#UserParameter=.*#UserParameter=pro.check,sh /renwole/Apps/check.sh|wc -c#" /etc/zabbix/zabbix_agentd.conf systemctl restart zabbix-agent '