zabbix batch deploy Windows and Linux agent

Batch deploy on Linux Zabbix-agent

We used here is ansible to deploy the bulk of zabbix-agent, of course, you can also use a script to complete the deployment on Linux

surroundings

ansible:10.127.0.133
agent1:172.168.0.4
agent2:172.168.0.5

For key authorization and authentication to achieve free secret landing

To facilitate the management of the agent ansible host, ansible and the agent will be required to achieve the free public key authentication secret landing

ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub 172.168.0.4
ssh-copy-id -i /root/.ssh/id_rsa.pub 172.168.0.5

Add the host information ansible / hosts in

[Linux-agent]
172.168.0.4
172.168.0.5

Editing Linux-agent's playbook batch file deployment

Implementation steps:

  1. Installation rpm packages zabbix-agent4.2
  2. Installation zabbix-agent using yum
  3. Some variables modify the agent configuration file will overwrite the template file to the agent profile
  4. Restart zabbix-agent

Defined template agent

Create a template file, which contains the agent in variable variables such as: host name and server address

[root@zabbix-server ~]# vim /etc/ansible/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server={{server}}
ServerActive={{server}}
Hostname={{hostname}}
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UnsafeUserParameters=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

Batch file execution playbook deployment

ansible-playbook -i /etc/ansible/hosts /etc/ansible/linux-agent.yml
zabbix batch deploy Windows and Linux agent

You can see the playbook has been performed successfully, the next can look at the agent's profile
zabbix batch deploy Windows and Linux agent

You can see, agent configuration file variables changes are complete

Create a rule to automatically discover hosts deployed automatically discover and add monitored items

Create automatic discovery rules

zabbix batch deploy Windows and Linux agent

Add auto-discovery action

zabbix batch deploy Windows and Linux agent

After the discovery operation configuration

zabbix batch deploy Windows and Linux agent

You can see the automatic discovery rules in force, and links to the Linux-OS template
zabbix batch deploy Windows and Linux agent

Windows batch deployment of Zabbix-agent

Batch deployment in Windows can be done by configuration management tool or a domain controller, here ansible I used to deploy the bulk of the Windows Host

surroundings

ansible:10.127.0.133
Windows server2012:172.168.0.6

Depend on the environment

ansible dependence

pywinrm>=0.3.0

pywinrm can use pip to install, execute the following command

pip install pywinrm>=0.3.0

Windows relies

PowerShell 3.0
NET Framework 4.0+

我这里使用的是2012,上面的环境是不需要做配置的,如果是使用的server2008或更低版本需要进行升级之后才能使用,获取升级的详细信息可以访问ansible官方文档查看
https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#host-requirements

安装winrm内存修补程序

由于ansible控制Windows不是使用的ssh协议,而是用的Windows的winrm服务,而winrm有一个限制可用内存量的错误,需要安装脚本进行修复
在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

在防火墙上开启winrm服务端口和agent服务端口

可以在powershell上执行下面的命令查看winrm当前的监听端口

winrm enumerate winrm/config/Listener

winrm服务默认是5985端口,zabbix-agent使用的是10050端口,因此需要在防火墙上开启5985和10050端口或直接关闭防火墙

下载Windows-agent的包

首先需要下载Windows-agent的压缩包并解压到ansible主机下
下载地址:https://www.zabbix.com/download_agents

在ansible/hosts中添加主机信息

需要在hosts中指定与Windows连接的配置信息,默认情况下使用ntlm认证,如果想要获取关于winrm认证的详细信息,可以访问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

编辑Windows-agent的playbook文件进行批量部署

实现步骤:

  1. 从ansible复制下载好的agent文件到Windows
  2. Some variables modify the agent configuration file will overwrite the template file to the same agent configuration file, the template file with Linux
  3. Installation zabbix-agent
  4. Start 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\

Batch file execution playbook deployment

ansible-playbook -i /etc/ansible/hosts /etc/ansible/linux-agent.yml
zabbix batch deploy Windows and Linux agent

You can see the successful implementation of the playbook, view the Windows services, Zabbix-agent has started
zabbix batch deploy Windows and Linux agent

Host configuration actions deployed automatically discover and add monitored items

Add auto-discovery action

zabbix batch deploy Windows and Linux agent

After the discovery operation configuration

zabbix batch deploy Windows and Linux agent

You can see the automatic discovery rules in force, and links to the Windows-OS Templates
zabbix batch deploy Windows and Linux agent


I welcome you to focus on personal micro-channel public number "is not the story of Master Chen"
zabbix batch deploy Windows and Linux agent

Guess you like

Origin blog.51cto.com/12970189/2438057