"Zabbix"-Use Ansible to deploy zabbix-agent services in batches@20210226

Problem Description

Need to deploy zabbix monitoring for multiple Linux hosts in the intranet 50.x network, the work content is as follows:

Install zabbix agent service

Due to the extreme confusion of asset management, it is necessary to identify the Linux host first and exclude the Windows/ESXi host.
When installing the zabbix agent service, you need to identify the release version (CentOS 6/7)

Add host in zabbix server

Add the host to the zabbix server
and add a monitoring template for the host

Solution

Install zabbix agent service

Use Ansible to deploy in batches to avoid repeated installation tasks.

Add host in zabbix server

Use Zabbix automatic discovery to avoid repeated configuration tasks.

Precautions

This note is only a brief description of the process, used to record the operation process, not a detailed operation method. Different scenarios require specific issues that require specific analysis.

Environment overview

Network: 10.10.50.0/25
Host: Linux / Windows / ESXi, but we only deploy Linux monitoring
system: CentOS 6.x / CentOS 7.x

The first step is to configure automatic discovery (Active agent autoregistration)

Refer to Active agent autoregistration notes for configuration

Create automatic registration rules (Auto registration)

To use automatic registration, you need to add a rule: Event source => Auto registration

Filter auto-registered hosts (Conditions)

In this network, there are Windows/Linux/ESXi hosts at the same time. We only deploy Linux monitoring and need to prevent other hosts from automatically registering.

Therefore, it is necessary to configure the HostMetadata parameter (add Linux string) in zabbix agent, and then filter in Conditions (Host metadata contains Linux). In this step, we need to configure the filter conditions, and configure the HostMetadata parameters in the next step (Configure the Zabbix Agent service) to complete.

Add automatic registration operations (Operations)

Add Add host, Add to host groups, Link to templates, etc. to Operations as needed to specify the actions that need to be performed when starting automatic registration.

The second step, deploy zabbix agent service

Identify the CentOS host and create a manifest file

Use the fping command to find all surviving hosts ( 00-fping-scan.sh ) => Get all the Linux hosts on the intranet, with port 22 open as the standard ( 01-port22-detecting.sh ) => Obtain by testing the redhat-release file All CentOS hosts on the intranet ( 02-linux-detecting.sh ) => Finally, create a host manifest file:

[all:vars]
ansible_user=root
ansible_ssh_private_key_file=config/ssh-private-key/id_rsa
ansible_ssh_common_args="-oStrictHostKeyChecking=no"

[centos]
# 省略主机列表......

Execute the ansible centos -i inventory.txt -m ping command to test whether the host can be accessed normally.

Script Playbook

The Playbook script needs to complete the following tasks:
1) Install the Zabbix repository (pay attention to distinguish the CentOS 6/7 release)
2) Install the zabbix agent service
3) Deploy the configuration file: zabbix_agentd.conf (The configuration file only contains the key configuration)
4) Start Service, boot (note the distinction between CentOS 6/7 release)

Complete service deployment

Execute the Playbook script to complete the service deployment.

Note, it is recommended to use a certain host for testing, and then apply the Playbook script to all target hosts after the test is completed. To prevent configuration errors caused by mistakes, which may lead to the destruction of other hosts.

The third step, verify the monitoring status

Visit Zabbix monitoring to see if all hosts have been automatically registered.

references

How do I make ssh fail rather than prompt for a password if the public-key authentication fails?
How to set host_key_checking=false in ansible inventory file?

Guess you like

Origin blog.csdn.net/u013670453/article/details/114147061