ANSIBLE部署ZABBIX客户端

本文介绍使用Ansible自动化配置及安装Zabbix Agent的过程。包括编译安装Zabbix Agent、配置Zabbix Agent并重启服务等内容。

agent_vars.yml  config-agent.yml  install-agent.yml  main.yml

cat main.yml

- hosts: 193.168.120.71
  become: yes


  vars_files:
    - agent_vars.yml


  tasks: 
    - name: complie && install zabbix_agent
      include: install-agent.yml
      tags: step1


    - name: config zabbix_agent
      include: config-agent.yml
      tags: step2


  handlers: 
    - name: restart zabbix_agentd
      service: name=zabbix_agentd state=restarted


cat agent_vars.yml

---
local_dir: /home/wn/example
tmp_dir: /tmp
install_dir: /usr/local/zabbix
server_ip: 193.168.120.56

cat install-agent.yml

#Step1: complie && install zabbix_agent
    - name: copy zabbix package
      copy: src={{local_dir}}/zabbix-3.0.3.tar.gz dest={{tmp_dir}}/zabbix-3.0.3.tar.gz
      
    - name: add zabbix
      shell: "groupadd zabbix; useradd -g zabbix zabbix"
      ignore_errors: true
      tags:
        - add


    - name: unpack zabbix package
      shell: "yum -y install gcc; cd {{tmp_dir}} && if [ ! -d zabbix-3.0.3 ]; then tar -zxvf zabbix-3.0.3.tar.gz; fi"
      ignore_errors: true
      tags:
        - unpack


    - name: install agent
      shell: "cd {{tmp_dir}}/zabbix-3.0.3 && ./configure --prefix={{install_dir}} --enable-agent && make install"
      tags: 
        - install

cat config-agent.yml 

---
#Step2: config zabbix_agent
    - name: modify the config
      shell: "sed -i 's/^Server=127.0.0.1/Server={{server_ip}}/' {{install_dir}}/etc/zabbix_agentd.conf && sed -i 's/^ServerActive=127.0.0.1/ServerActive={{server_ip}}/' {{install_dir}}/etc/zabbix_agentd.conf  && sed -i 's/^Hostname=Zabbix server/Hostname={{inventory_hostname}}/' {{install_dir}}/etc/zabbix_agentd.conf"
      tags:
        - agent-config
        - config
    
    - name: modify system config
      shell: "cp {{tmp_dir}}/zabbix-3.0.3/misc/init.d/tru64/zabbix_agentd /etc/init.d/ && chmod +x /etc/init.d/zabbix_agentd"
      tags:
        - system-config
        - config
      notify:
        - restart zabbix_agentd


    - name: create soft-link
      shell: "ln -s {{install_dir}}/sbin/* /usr/local/sbin/ && ln -s {{install_dir}}/bin/* /usr/local/bin/"
      tags: 
        - soft-link

ansible-playbook main.yml 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值