Actual combat--Playbook batch deployment of zabbix-agent

To build a zabbix-server server, it is required to install zabbix-agent on hundreds of servers, monitor the performance of each server, specify the port to be monitored, etc. This must be achieved with automated scripts to complete this work more efficiently.

I believe everyone is familiar with Ansible, an automated operation and maintenance tool, so let's not say much, let's start deployment.

test environment:

192.168.20.85 zabbix-server

192.168.20.39  zabbix-agent

[root@k8s-master ~]# vim /etc/ansible/hosts 

 [web]

## alpha.example.org

## beta.example.org

k8s-master ansible_ssh_host=192.168.20.40

k8s-node3  ansible_ssh_host=192.168.20.39

1. Configure zabbix-agent script

[root@k8s-master ~]# more zabbix-agent.sh 

#!/bin/bash

if [ ! -f /etc/yum.repos.d/zabbix.repo ]

then 

  rpm -ivh /root/zabbix-release-4.2-2.el7.noarch.rpm

be

Zabbix_Agent=`rpm -qa |grep zabbix-agent|wc -l`

if [ $Zabbix_Agent -eq 0 ];then

 yum -y install zabbix-agent 

be

sed -i 's/Server=127.0.0.1/Server=192.168.20.40/g' /etc/zabbix/zabbix_agentd.conf

sed -i 's/ServerActive=127.0.0.1/ServerActive=192.168.20.40/g' /etc/zabbix/zabbix_agentd.conf

systemctl restart zabbix-agent

Remember to execute the script first if there are errors, execute the playbook in batches

2, placement zabbix-agent.yml

[root@k8s-master ~]# more zabbix-agent.yml 

---

- hosts: all

  tasks:

  - name: copy zabbix-agent.repo

    copy: src=/root/zabbix-release-4.2-2.el7.noarch.rpm dest=/root/

  - name: install zabbix-agent

copy: src=/root/zabbix-agent.sh dest=/root/zabbix-agent.sh mode=755

  - name: run script

    shell: sh /root/zabbix-agent.sh

    register: result

  - debug: var=result

3. Perform installation in batches

[root@k8s-master ~]# ansible-playbook  zabbix-agent.yml 

image.png

image.png

image.png

image

4. Check the server zabbix-agent port

[root@k8s-master ~]# netstat -nltp |grep 10050

tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      11634/zabbix_agentd 

tcp6       0      0 :::10050                :::*                    LISTEN      11634/zabbix_agentd 

image

[root@k8s-node3 ~]# netstat -nltp|grep 10050

tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      14587/zabbix_agentd 

tcp6       0      0 :::10050                :::*                    LISTEN      14587/zabbix_agentd 

image


Related Reading:

1. Actual combat-Playbook batch change server hostname

2. Welcome to join the technical exchange


image


Guess you like

Origin blog.51cto.com/15127516/2657651