Zabbix agentd install Script

#!/bin/bash
echo "nameserver 8.8.8.8\nnameserver 8.8.4.4" >/etc/resolv.conf
/sbin/iptables -F
chkconfig iptables off
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/sysconfig/selinux
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config
setenforce 0
yes|cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
yum -y install ntp openssh-clients rsync expect
sed -i 's/^server 0.centos.pool.ntp.org iburst/\server stdtime.gov.hk prefer/g' /etc/ntp.conf
ntpdate stdtime.gov.hk
/etc/init.d/ntpd start
chkconfig ntpd on
read -p "Please input the ip address of zabbix server: " IP
echo $IP
read -p "Please input the password of zabbix server: " PASSWORD
command1="rsync -avu $IP:/usr/local/etc/zabbix_agentd.conf /usr/local/etc/"
command2="rsync -avu $IP:/etc/init.d/zabbix_agentd /etc/init.d/"
command3="rsync -avu $IP:/usr/local/sbin/zabbix_agentd /usr/local/sbin/"
expect -c "
        spawn $command1;
        expect {
                \"Are you sure you want to continue connecting (yes/no)?\" {send \"yes\r\"; exp_continue}
                \"$IP's password:\" {send \"$PASSWORD\r\"; exp_continue}
                }
        spawn $command2;
        expect {
                \"Are you sure you want to continue connecting (yes/no)?\" {send \"yes\r\"; exp_continue}
                \"$IP's password:\" {send \"$PASSWORD\r\"; exp_continue}
                }
        spawn $command3;
        expect {
                \"Are you sure you want to continue connecting (yes/no)?\" {send \"yes\r\"; exp_continue}
                \"$IP's password:\" {send \"$PASSWORD\r\"; exp_continue}
                }
        "
sed -i "s/Server=127.0.0.1/Server="$IP"/g" /usr/local/etc/zabbix_agentd.conf
useradd -s /sbin/nologin -M zabbix
touch /var/log/zabbix_agentd.log
chown zabbix.zabbix /var/log/zabbix_agentd.log
/etc/init.d/zabbix_agentd restart
chkconfig zabbix_agentd on

你可能感兴趣的:(script,zabbix,agentd)