一、批量安装zabbix客户端 .拷贝sh脚本和.conf到远程服务器(也可以全量拷贝客户端) ansible all -m copy -a "src=/usr/local/zabbix_agents_3.2.0/scripts/php_status_code.sh dest=/usr/local/zabbix_agents_3.2.0/scripts/ mode=0755"
ansible all -m copy -a "src=/usr/local/zabbix_agents_3.2.0/scripts/start_php.sh dest=/usr/local/zabbix_agents_3.2.0/scripts/ mode=0755"
ansible all -m copy -a "src=/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/php-fpm_status.conf dest='/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/'" # 在ansible服务器上添加/data/www/.machine_no,然后添加批量赋权
ansible all -m copy -a "src=/data/www/.machine_no dest=/data/www/ mode=0644 owner=apache group=users" # 拷贝整个目录到目标服务器
ansible all -m copy -a "src=/usr/local/zabbix_agents_3.2.0/ dest=/usr/local/zabbix_agents_3.2.0/ mode=0755" .开启远程命令 ansible cmsnew -m shell -a "sed -i 's|# EnableRemoteCommands=0|EnableRemoteCommands=1|g' /etc/zabbix/zabbix_agentd.conf" # apache 添加配置 ansible all -m blockinfile -a 'path=/usr/local/httpd-2.2.26/conf/httpd.conf block="ExtendedStatus On\n<location /server-status>\n SetHandler server-status\n Order Allow,Deny\n Allow from 127.0.0.1\n</location>" insertbefore=EOF' # 重启apache
/etc/init.d/apache -t
/etc/init.d/apache restart # 添加sudo权限
ansible all -m blockinfile -a 'path=/etc/sudoers block="Defaults:zabbix !requiretty\nzabbix ALL=NOPASSWD: ALL\nzabbix ALL=NOPASSWD: /bin/bash /usr/local/rsync/bin/rsync\nzabbix ALL=NOPASSWD: /bin/bash /usr/local/nginx/sbin/nginx\nzabbix ALL=NOPASSWD: /bin/bash /usr/local/php/sbin/php-fpm\n" insertbefore=EOF' # 修改主机名
ansible all -m shell -a 'sed -i "s/Hostname\=zabbixclient/Hostname\=`hostname`/g" /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd.conf' ansible all -m shell -a "cd /usr/local/zabbix_agents_3.2.0 && sh agent.sh" ansible all -m shell -a "executable=/bin/bash /etc/init.d/zabbix_agentd restart" # 批量添加计划任务,批量新增时间同步任务
ansible all -m cron -a "minute=1 hour=* day=* month=* weekday=* name='ntpdate' job='/usr/sbin/ntpdate time.windows.com > /dev/null 2>&1'" ansible Europe_Tunesgo_web1 -m cron -a "minute=1 hour=* day=* month=* weekday=* name='ntpdate' job='/usr/sbin/ntpdate time.windows.com > /dev/null 2>&1'" # agent.sh
#!/bin/bash
#清理历史信息
rm -rf /usr/local/etc/zabbix_agent*
rm -f /etc/init.d/zabbix_agentd
rm -f /usr/bin/zabbix_*
rm -f /usr/sbin/zabbix_*
rm -f /usr/local/zabbix_agents_2.0.10.tar.gz
rm -rf /usr/local/zabbix_agents_2.0.10 /usr/sbin/groupadd zabbix
/usr/sbin/useradd -g zabbix zabbix
mkdir /var/log/zabbix
chown zabbix.zabbix /var/log/zabbix
cp init.d/zabbix_agentd /etc/init.d/
chmod /etc/init.d/zabbix_agentd zabbix_dir=/usr/local/zabbix_agents_3.2.0
#sed -i "s#BASEDIR=/usr/local#BASEDIR=$zabbix_dir#g" /etc/init.d/zabbix_agentd sed -i "s#tmp/zabbix_agentd.log#var/log/zabbix/zabbix_agentd.log#g" $zabbix_dir/conf/zabbix_agentd.conf
sed -i "s/# UnsafeUserParameters\=0/UnsafeUserParameters\=1/g" $zabbix_dir/conf/zabbix_agentd.conf
ln -s $zabbix_dir/conf/zabbix_agentd.conf /usr/local/etc
ln -s $zabbix_dir/conf/zabbix_agentd /usr/local/etc
ln -s $zabbix_dir/bin/* /usr/bin/
ln -s $zabbix_dir/sbin/* /usr/sbin/
chkconfig zabbix_agentd on
#service zabbix_agentd start