In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Batch deployment of Zabbix-agent to Linux
What we use here is ansible to deploy zabbix-agent in batches. Of course, scripts can also be used to deploy on Linux.
Environment ansible:10.127.0.133agent1:172.168.0.4agent2:172.168.0.5 carries out key authorization authentication to realize secret-free login.
In order to facilitate the management of agent hosts by ansible, it is necessary to authenticate ansible and agent with public key to achieve secret-free login.
Ssh-keygen-t rsassh-copy-id-I / root/.ssh/id_rsa.pub 172.168.0.4ssh-copy-id-I / root/.ssh/id_rsa.pub 172.168.0.5 add host information to ansible/hosts [Linux-agent] 172.168.0.4 172.168.0.5 Edit the playbook file of Linux-agent for batch deployment implementation steps: install rpm package of zabbix-agent4.2 install zabbix- using yum Agent modifies some variables in the agent configuration file Overwrite template file to agent configuration file restart zabbix-agent definition agent template
Create a template file that contains variable variables in agent, such as hostname and server address
[root@zabbix-server ~] # vim / etc/ansible/zabbix_agentd.confPidFile=/var/run/zabbix/zabbix_agentd.pidLogFile=/var/log/zabbix/zabbix_agentd.logLogFileSize=0Server= {{server}} ServerActive= {{server}} Hostname= {{hostname}} Include=/etc/zabbix/zabbix_agentd.d/*.confUnsafeUserParameters=1 write playbook file vim / etc/ansible/linux-agent.yml- hosts: zabbix-agent remote_user: root vars: server: 10.127.0.133 hostname: "{{ansible_hostname}}" tasks:-name: install rpm command: rpm-ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.1-1.el7.x86_64.rpm-name: install agent command: yum install zabbix-agent-y-name: cp templates zabbix_agentd.conf to zabbix agentd template: src=/etc/ansible/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd .conf-name: restart zabbix-agent command: systemctl restart zabbix-agent executes the playbook file for batch deployment
Ansible-playbook-I / etc/ansible/hosts / etc/ansible/linux-agent.yml
You can see that playbook has been executed successfully. Next, you can take a look at the configuration file of agent.
As you can see, the variables in the agent configuration file have also been modified
Create auto-discovery rules to automatically discover deployed hosts and add monitoring items to create automatic discovery rules
Add an autodiscover action
Configure actions after discovery
You can see that the auto-discovery rule is in effect and the Linux-OS template is linked
Batch deployment of Zabbix-agent to Windows
Batch deployment under Windows can be carried out through configuration management tools or domain controllers. Here I use ansible to batch deploy Windows hosts.
Environment ansible:10.127.0.133Windows server2012:172.168.0.6 depends on environment ansible depends on pywinrm > = 0.3.0
Pywinrm can be installed using pip by executing the following command
Pip install pywinrm > = 0.3.0Windows depends on PowerShell 3.0NET Framework 4.0 +
I use 2012 here. The above environment does not need to be configured. If you are using a server2008 or lower version that needs to be upgraded before you can use it, for more information about the upgrade, please visit the official ansible documentation to view it.
Https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#host-requirements
Install the winrm memory patch
Since ansible controls Windows not using ssh protocol, but using Windows's winrm service, winrm has an error that limits the amount of memory available, which needs to be fixed by installation script
Execute the following command on powershell
$url = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Install-WMF3Hotfix.ps1"$file =" $env:temp\ Install-WMF3Hotfix.ps1 "(New-Object-TypeName System.Net.WebClient). DownloadFile ($url, $file) powershell.exe-ExecutionPolicy ByPass-File $file-Verbose opens winrm service port and agent service port on the firewall
You can view the current listening port of winrm by executing the following command on powershell
Winrm enumerate winrm/config/Listener
Winrm service defaults to port 5985, while zabbix-agent uses port 10050, so you need to open ports 5985 and 10050 on the firewall or turn off the firewall directly
Download Windows-agent 's package
First of all, you need to download the Windows-agent package and decompress it to the ansible host.
Download address: https://www.zabbix.com/download_agents
Add host information in ansible/hosts
You need to specify the configuration information for connecting to Windows in hosts. Ntlm authentication is used by default. If you want to get more information about winrm authentication, you can visit https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html.
[windows] 172.168.0.6 ansible_python_interpreter=/usr/bin/python ansible_user= "administrator" ansible_password= "asd.123" ansible_port=5985 ansible_connection= "winrm" ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore edits Windows-agent 's playbook file for batch deployment: copy the downloaded agent file from ansible to Windows to modify some variables of the agent configuration file, and overwrite the template file to the agent configuration file Template file is the same as Linux installation zabbix-agent startup zabbix-agent write playbook file vim / etc/ansible/windows-agent.yml- hosts: windows remote_user: administrator vars: server: 10.127.0.133 hostname: "{{ansible_host}}" tasks:-name: cp zabbix-agent win_copy: src: / etc/ansible/windows_agent/ dest: C:\ windows_agent\-name: cp templates zabbix _ agentd.conf to zabbix agentd win_template: src: / etc/ansible/zabbix_agentd.conf dest: C:\ windows_agent\ conf\-name: install zabbix-agent win_command: zabbix_agentd.exe-I-c C:\ windows_agent\ conf\ zabbix_agentd.conf args: chdir: C:\ windows_agent\ bin\-name: start zabbix-agent win_command: zabbix_agentd.exe-s-c C:\ windows _ agent\ conf\ zabbix_agentd.conf args: chdir: C:\ windows_agent\ bin\ execute the playbook file for batch deployment
Ansible-playbook-I / etc/ansible/hosts / etc/ansible/linux-agent.yml
You can see that playbook has been successfully executed. Check the service of Windows. Zabbix-agent has also been started.
Configure actions to automatically discover deployed hosts and add monitoring items to add automatic discovery actions
Configure actions after discovery
You can see that the auto-discovery rule is in effect and the Windows-OS template is linked
Welcome to Master Chen.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.