部署机器 192.168.2.100-116
zabbix 服务器ip192.168.2.117
ansible 结构说明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
. ├── hosts # 部署客户端机器 ├── roles │ └── zabbix_agent │ ├── defaults │ ├── files │ ├── handlers │ ├── meta │ ├── tasks │ │ └── main.yml # ansible 部署zabbix_agent 脚本 │ ├── templates │ │ └── zabbix_agentd.conf.j2 # zabbix_agent 配置文件 │ └── vars └── zabbix_agent.yml # ansible 控制脚本 |
1 2 3 4 5 6 7 8 9 |
zabbix_agent.yml 内容说明 - hosts: code user: root vars: zabbix_serverip: 192.168.2.117 # zabbix 服务器IP zabbix_activeip: 192.168.2.117 # zabbix 服务器IP agent_ip: '{{ ansible_eth0.ipv4.address }}' # 客户端IP 根据实际情况修改自己的网卡名字eth0 改成自己服务器 roles: - zabbix_agent |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
main.yml 内容说明 - name: yum epel-release # 安装zabbix yum 源必须 yum: name=epel-release state=present - name: zabbix-release-3.2-1.el7.noarch.rpm get_url: url: #下载zabbix yum 源配置 dest: /tmp/zabbix-release-3.2-1.el7.noarch.rpm - name: rpm -qi zabbix-release-3.2-1.el7.noarch shell: rpm -qi zabbix-release-3.2-1.el7.noarch # 查看服务器是否安装zabbix3.2 register: result ignore_errors: True - name: zabbix-release-3.2-1.el7.noarch.rpm shell: rpm -Uvh /tmp/zabbix-release-3.2-1.el7.noarch.rpm # 安装zabbix 源码 when: result.rc == 1 - name: yum install zabbix-agent yum: name={{ item }} state=present # 安装zabbix-agent with_items: - zabbix-agent - zabbix-get - zabbix-sender - lineinfile: dest=/etc/services line="zabbix-agent 10050/tcp Zabbix Agent" - lineinfile: dest=/etc/services line="zabbix-agent 10050/udp Zabbix Agent" # 添加zabbix 端口到services 文件 - name: up zabbix-agent file client # 上传配置文件 template: src=zabbix_agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf - name: enabled service zabbix-agent # 打开zabbix-agent 开机启动 service: name=zabbix-agent.service enabled=yes - name: start service zabbix-agent # 启动zabbix-agent service: name=zabbix-agent state=started |
其它说明:
1 |
ansible-playbook -i hosts zabbix_agent.yml -verbose |