Linux记录-批量安装zabbix(转载)
同一文件夹下建立pwd.txt,格式如下:
ip username password
ip username password
#!/bin/bash cat pwd.txt | while read line do hostip=`echo $line | cut -d" " -f1` uname=`echo $line | cut -d" " -f2` pwd=`echo $line | cut -d" " -f3` /usr/bin/expect <<-EOF set timeout 600 spawn scp -r /tmp/zabbix-3.4.12.tar.gz $uname@$hostip:/tmp/ expect { "*yes/no" { send "yes\r"; exp_continue } "*password:" { send "$pwd\r" } } spawn scp -r /tmp/3.sh $uname@$hostip:/tmp/ expect { "*yes/no" { send "yes\r"; exp_continue } "*password:" { send "$pwd\r" } } spawn ssh $uname@$hostip expect { "*yes/no" { send "yes\r"; exp_continue } "*password:" { send "$pwd\r" } } expect "*]#" send "chmod +x /tmp/3.sh\r" expect "*]#" send "sh /tmp/3.sh\r" expect "*]#" send "exit\r" interact expect eof EOF done
3.sh
#!/bin/bash yum -y install pcre* egrep "^zabbix" /etc/group >& /dev/null if [ $? -ne 0 ] then groupadd zabbix fi egrep "^zabbix" /etc/passwd >& /dev/null if [ $? -ne 0 ] then useradd -g zabbix zabbix -s /sbin/nologin fi cd /tmp/ tar -zxvf /tmp/zabbix-3.4.12.tar.gz cd /tmp/zabbix-3.4.12/ ./configure --prefix=/usr/local/zabbix-agent --enable-agent make make install cd /tmp/zabbix-3.4.12/misc cp init.d/tru64/zabbix_agentd /etc/init.d/ chmod +x /etc/init.d/zabbix_agentd cp -r /etc/init.d/zabbix_agentd /tmp/zabbix_agentd.bak sed -i 's/DAEMON=\/usr\/local\/sbin\/zabbix_agentd/DAEMON=\/usr\/local\/zabbix-agent\/sbin\/zabbix_agentd/g' /etc/init.d/zabbix_agentd sed -i '/#!\/bin\/sh/a\#chkconfig: 345 95 95' /etc/init.d/zabbix_agentd sed -i '/#chkconfig: 345 95 95/a\#description: Zabbix_Server' /etc/init.d/zabbix_agentd chkconfig zabbix_agentd on sed -i 's/Server=127.0.0.1/Server=193.168.120.77/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf sed -i 's/ServerActive=127.0.0.1/ServerActive=193.168.120.77/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf HOSTNAME=`hostname` sed -i 's/Hostname=Zabbix server/Hostname='$HOSTNAME'/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf sed -i 's/LogFile=\/tmp\/zabbix_agentd.log/LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf mkdir -p /var/log/zabbix chown -R zabbix.zabbix /var/log/zabbix/ chown -R zabbix.zabbix /usr/local/zabbix-agent/ /etc/init.d/zabbix_agentd start