前提条件:
1. 防火墙关闭
2. 安装ansible
[root@centos1 ~]# yum install -y ansible
3. 如果centos是最小化安装,需要安装gcc
##安装gcc
yum install -y gcc*
4.配置zabbix服务端到各zabbix客户端的ssh免密钥通信
##配置ssh免密通信
[root@centos1 ~]# ssh-keygen
[root@centos1 ~]# ssh-copy-id 192.168.15.12
[root@centos1 ~]# ssh-copy-id 192.168.15.13
[root@centos1 ~]# ssh-copy-id 192.168.15.14
一、定义主机组
[root@centos1 ~]# cd /etc/ansible/
[root@centos1 ansible]# ls
ansible.cfg hosts roles
[root@centos1 ansible]# vim hosts
[zabbix_agent]
192.168.15.12
192.168.15.13
192.168.15.14
##查看主机组内的主机
[root@centos1 ansible]# ansible zabbix_agent --list-hosts
hosts (3):
192.168.15.12
192.168.15.13
192.168.15.14
二、测试能不能ping通各zabbix客户端,如下图所示
执行ansible all -m ping
三、向所有主机推送修改好的hosts文件
执行ansible all -m copy -a "src=/etc/hosts dest=/etc/hosts"
四、安装zabbix客户端
1. 主动方式
ansible 192.1.128.102 -a 'rpm -ivh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm'
ansible 192.1.128.102 -a 'yum install zabbix-agent -y'
ansible 192.1.128.102 -a 'rm -rf /etc/zabbix/zabbix_agentd.conf'
ansible 192.1.128.102 -a 'ls -l /etc/zabbix/'
ansible 192.1.128.102 -m copy -a "src=/etc/zabbix/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf"
ansible 192.1.128.102 -a 'systemctl start zabbix-agent'
ansible 192.1.128.102 -a 'systemctl enable zabbix-agent'
ansible 192.1.128.102 -a 'systemctl status zabbix-agent'
2. 被动方式
https://www.bbsmax.com/A/1O5EOjY3z7/
五、查看zbbix客户端的运行状态
执行 ansible all -m shell -a "ps -ef | grep zabbix_agentd"