ansible 批量部署 zabbix_agent

该博客介绍了如何利用Ansible自动化工具,进行批量安装Zabbix_Agent的过程。首先,在CentOS上安装Ansible,然后通过ssh-copy-id实现无密登录目标主机。接着,配置Ansible的hosts文件,并创建一个名为yum_zabbix_agent_for_centos.yml的Playbook文件,该文件包含了下载Zabbix_Agent的RPM包、配置Agent以连接指定服务器、启动及设置服务开机启动的任务。最后,执行Ansible playbook完成批量部署。

单台安装zabbix_agent

rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/6/x86_64/zabbix-release-4.4-1.el6.noarch.rpm      安装zabbix yum源
yum -y install zabbix-agent  安装Zabbix_agent

准备配置文件并修改
vim /etc/zabbix/zabbix_agentd.conf

sed -i 's/^Server=127.0.0.1/Server=192.168.254.31,127.0.0.1/'  /etc/zabbix/zabbix_agentd.conf 
sed -i 's/^ServerActive=127.0.0.1/ServerActive=192.168.254.31/'  /etc/zabbix/zabbix_agentd.conf 

启动服务
service zabbix-agent start
chkconfig zabbix-agent on
 

使用ansible批量安装zabbix_agent

1、准备一台centos,安装ansible

yuminstall ansible –y     

2、ssh-copy-id 免密传输

ssh-keygen    

ssh-copy-id  192.168.254.77

ssh-copy-id  192.168.254.78

ssh-copy-id  192.168.254.79

ssh-copy-id  192.168.254.80

3、修改/etc/ansible/hosts 添加 zabbix分组

4、新建 yum_zabbix_agent_for_centos.yml 文件

---
 - hosts : zabbix
   remote_user : root
   tasks :
   - name : down zabbix_agent4.4 centos6    
     shell : rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/6/x86_64/zabbix-release-4.4-1.el6.noarch.rpm
     when :  ansible_distribution_major_version  == "6"
     ignore_errors : yes
   - name : down zabbix_agent4.4 centos7
     shell : rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.1-1.el7.x86_64.rpm
     when : ansible_distribution_major_version  == "7"
     ignore_errors : yes
   - name : yum zabbix_agent4.4
     yum : name=zabbix-agent
   - name : config zabbix_agent4.4
     shell : sed -i {{ item }}  /etc/zabbix/zabbix_agentd.conf
     with_items : 
      - 's/^Server=127.0.0.1/Server=192.168.254.31,127.0.0.1/'
      - 's/^ServerActive=127.0.0.1/ServerActive=192.168.254.31/'
     notify : 
         restart zabbix_agent
   - name : start service
     service : name=zabbix-agent state=started enabled=yes
   handlers :
   - name : restart zabbix_agent
     service : name=zabbix-agent state=restarted

5、执行批量部署安装:

ansible-playbook  zabbix -C yum_zabbix_agent_for_centos.yml

 

语法通过后执行:

ansible-playbook  zabbix yum_zabbix_agent_for_centos.yml 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值