ansible-playbook 批量安裝zabbix_agent
阿新 • • 發佈:2018-04-10
本機 批量安裝 本地測試 ada AC span scrip cal copy
zabbix_agent_install.yml
--- - hosts: 本地測試服務器 remote_user: root tasks: - name: Install packages yum: name={{ item }} state=present with_items: - gcc-c++ - curl - curl-devel - net-snmp - net-snmp-devel - mysql-devel - name: copy file copy: src={{ item.src }} dest={{ item.dest }} mode=‘0755‘ with_items: - {src: "/etc/ansible/scripts/zabbix_agent_install.sh", dest: "/data/scripts/zabbix_agent_install.sh"} - {src: ‘/etc/init.d/zabbix_agentd‘, dest: ‘/etc/init.d/zabbix_agentd‘ } - name: install zabbix_agent shell:/data/scripts/zabbix_agent_install.sh - name: starting zabbix_agentd service: name=zabbix_agentd state=started
zabbix_agent_install.sh
#!/bin/bash id zabbix &>/dev/null if [ ! $? -eq 0 ];then useradd -M -s /sbin/nologin zabbix fi #安裝zabbix agent wget -P /usr/local/src http://pkgs.fedoraproject.org/repo/pkgs/zabbix/zabbix-3.0.1.tar.gz/890d9eec69304ad552959fabe0a5d122/zabbix-3.0.1.tar.gzcd /usr/local/src tar xf zabbix-3.0.1.tar.gz cd zabbix-3.0.1 ./configure --prefix=/data/apps/zabbix --with-net-snmp --enable-agent make && make install #修改配置文件zabbix_agentd.conf IP="Zabbix Server" cd /data/apps/zabbix/etc/ sed -i "s/^Server=127.0.0.1/Server=127.0.0.1,$IP/" zabbix_agentd.conf sed -i "s/^ServerActive=127.0.0.1/ServerActive=$IP/" zabbix_agentd.conf sed -i "s/^# HostMetadata=/HostMetadata=siyouyun/" zabbix_agentd.conf sed -i "s;^# UnsafeUserParameters=0;UnsafeUserParameters=1;" zabbix_agentd.conf chown zabbix:zabbix /data/apps/zabbix/ sed -i "s;^# PidFile=/tmp/zabbix_agentd.pid;PidFile=/data/apps/zabbix/zabbix_agentd.pid;" zabbix_agentd.conf mkdir -p /data/logs/zabbixlogs chown zabbix:zabbix /data/logs/zabbixlogs sed -i "s;^LogFile=/tmp/zabbix_agentd.log;LogFile=/data/logs/zabbixlogs/zabbix_agentd.log;" zabbix_agentd.conf #獲取本機ip IPADDR=`ip add |grep eth|grep -oP ‘(?<=inet )(\d+).(\d+).(\d+).(\d+)‘|head -1` sed -i "s/^Hostname=Zabbix server/Hostname=$IPADDR/" /data/apps/zabbix/etc/zabbix_agentd.conf echo "Include=/data/apps/zabbix/etc/zabbix_agentd.conf.d/*.*" >> /data/apps/zabbix/etc/zabbix_agentd.conf #開機自啟 chkconfig zabbix_agentd on #配置環境變量 echo ‘#Set zabbix export PATH=$PATH:/data/apps/zabbix/sbin/:/data/apps/zabbix/bin/‘ >> /etc/profile source /etc/profile
ansible-playbook 批量安裝zabbix_agent