码迷,mamicode.com
首页 > 其他好文 > 详细

ansible 批量安装zabbix agentd客户端

时间:2016-04-04 01:18:59      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

 

目录结构

ansible/
├── ansible.cfg
├── hosts
├── roles
│   └── zabbix-agentd
│       ├── files
│       │   ├── install_zabbix.sh
│       │   └── zabbix-3.0.1.tar.gz
│       ├── handlers
│       ├── tasks
│       │   └── main.yml
│       └── templates
└── site.yml

 

[root@localhost ansible]# more site.yml 
---
- name: Install Zabbix-agentd
  hosts: zabbix-agentd
  remote_user: root

  roles:
    - zabbix-agentd

 

[root@localhost ansible]# more roles/zabbix-agentd/tasks/main.yml 
- name: copy zabbix_tar_gz to client
  copy: src=zabbix-3.0.1.tar.gz dest=/tmp/zabbix-3.0.1.tar.gz

- name: copy install_shell to client
  copy: src=install_zabbix.sh dest=/tmp/install_zabbix.sh

- name: install zabbix
  shell: /bin/bash /tmp/install_zabbix.sh

 

[root@localhost ansible]# more roles/zabbix-agentd/files/install_zabbix.sh 
#######client install#############
yum install -y gcc make libselinux-python


grep -q "zabbix" /etc/group
GROUP_IS=$?
if [ $GROUP_IS == 1 ];then
  groupadd zabbix
fi

grep -q "zabbix" /etc/passwd
USER_IS=$?
if [ $USER_IS == 1 ];then
  useradd -g zabbix zabbix -M -s /sbin/nologin
fi

mv /usr/local/zabbix /usr/local/zabbix_old-$(date +%Y%m%d)
rm -rf /etc/zabbix
cd /tmp
tar zxvf zabbix-3.0.1.tar.gz
cd zabbix-3.0.1
./configure --prefix=/usr/local/zabbix --enable-agent
make install
ln -s /usr/local/zabbix/etc /etc/zabbix
ln -s /usr/local/zabbix/sbin/zabbix_agentd /usr/local/sbin/
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf-$(date +%Y%m%d)

cat >/etc/zabbix/zabbix_agentd.conf<<EOF
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
Server=172.31.x.x
ServerActive=172.31.x.x
ListenPort=10050
ListenIP=0.0.0.0
EnableRemoteCommands=1
UnsafeUserParameters=1
LogFileSize=10
Timeout=30
#UserParameter=key,script
EOF

/etc/init.d/zabbix_agentd start
chkconfig zabbix_agentd on

 

 

[root@localhost ansible]# ansible-playbook site.yml

ansible 批量安装zabbix agentd客户端

标签:

原文地址:http://www.cnblogs.com/caoguo/p/5351153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!