• Ansible部署zabbix-agent


    playbook目录

    zabbix/
    ├── hosts             ##定义的主机列表
    ├── install_zabbix_agent.yml          ##安装入口文件
    └── roles
        ├── install_zabbix_agent
           ├── files
           │   ├── zabbix-release-3.2-1.el7.noarch.rpm
           │   └── zabbix-release_3.2-1+trusty_all.deb
           ├── tasks
           │   └── main.yml            ##安装文件
           ├── templates
           │   ├── zabbix-agentd.conf.j2
           │   └── zabbix-agentd.conf.j2.bak
           └── vars
               └── main.yml
    

    install_zabbix_agent.yml

    - hosts: xiaozhan
      roles:
      - install_zabbix_agent
      vars:
      - zabbix_centos: zabbix-release-3.2-1.el7.noarch.rpm
      - zabbix_ubuntu: zabbix-release_3.2-1+trusty_all.deb

    roles/install_zabbix_agent/tasks/main.yml

    - name: copy zabbix file
      copy: src={{ zabbix_centos }} dest=/root/
      when: ansible_distribution == 'CentOS'
    - name: rpm -ivh zabbix-agent
      shell: rpm -ivh /root/{{ zabbix_centos }}
      when: ansible_distribution == 'CentOS'
    - name: install zabbix-agent
      shell: yum -y install zabbix-agent
      when: ansible_distribution == 'CentOS'
    - name: copy zabbix-agent.conf
      template: src=zabbix-agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf
      when: ansible_distribution == 'CentOS'
    - name: start zabbix-agent
      shell: systemctl start zabbix-agent
      when: ansible_distribution == 'CentOS'
    - name: copy  zabbix file
      copy: src={{ zabbix_ubuntu }} dest=/root/
      when: ansible_distribution == 'Ubuntu'
    - name: install zabbix
      shell: dpkg -i /root/{{ zabbix_ubuntu }}
      when: ansible_distribution == 'Ubuntu'
    - name: apt-get update
      shell: apt-get update
      when: ansible_distribution == 'Ubuntu'
    - name: install zabbix
      shell: apt-get install zabbix-agent
      when: ansible_distribution == 'Ubuntu'
    - name: copy zabbix-agent.conf
      template: src=zabbix-agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf
      when: ansible_distribution == 'Ubuntu'
    - name: start zabbix
      service: name=zabbix-agent state=restarted
      when: ansible_distribution == 'Ubuntu'

    roles/install_zabbix_agent/templates/zabbix-agentd.conf.j2

    PidFile=/var/run/zabbix/zabbix_agentd.pid
    LogFile=/var/log/zabbix/zabbix_agentd.log
    LogFileSize=0
    Server=serverip
    ServerActive=serverip
    HostnameItem=system.hostname   ##自动获取主机名
    Include=/etc/zabbix/zabbix_agentd.d/

    roles/install_zabbix_agent/vars/main.yml

    zabbix_server_ip: *.*.*.*

    执行

    ansible-playbook -i hosts install_zabbix_agent.yml
     
  • 相关阅读:
    Mysql中自增字段(AUTO_INCREMENT)的一些常识
    MyBatis动态传入表名
    Linux创建连接命令 ln -s创建软连接
    leaflet 使用turfjs实现前端自定义插值
    java后台@RequestBody和@RequestParam
    在jeecg-boot中密码的使用
    在jeecg-boot中使用代码生成器&mybatis-plus
    Pyppeteer 爬取实战
    【转】GitHub不再支持密码验证解决方案
    【转】pyppeteer+chromium手动安装Mac版本
  • 原文地址:https://www.cnblogs.com/Z-style/p/7279476.html
Copyright © 2020-2023  润新知