单台安装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 

 

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐