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.gz cd /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
原文:https://www.cnblogs.com/wenzhaojun/p/8780318.html