zabbix_server的自動發現,實現批量添加主機,並鏈接到模板


一、需求

  zabbix 服務器可以手動加入zabbix-agent客戶端,對於少量的機器,這沒有什么。但到了線上,我們有大量的服務器需要監控時,如果再一個個的手動加的話,工作量勢必會增加很多。這時,zabbix-server 的Discovery 自動發現 功能便派上了用場。

二、條件

  1.zabbix server 已經部署好,所需要加入的服務器zabbix-agent已經安裝。

  2.防火牆都開放端口,主要是10050、10051端口,或者關閉整個iptables

三、zabbix-agent客戶端的設置

  1.打開zabbix-agent.conf配置文件,只需要修改2處配置.大批量的修改,可以利用自動化部署工具、如saltstack、ansible等。我用的是saltstack推送文件的方式進行修改,在本實驗環境中,我用的是國產的一個批量工具CheungSSH。

  2.批量執行的命令

sed -i 's/Server=127.0.0.1/Server=10.8.0.22/g' /etc/zabbix/zabbix_agentd.conf sed -i 's/ServerActive=127.0.0.1/ServerActive=10.8.0.22/g' /etc/zabbix/zabbix_agentd.conf grep "Server" /etc/zabbix/zabbix_agentd.conf | grep -v '^#' service zabbix-agent restart

  上述命令完成后,要在zabbix-server上創建discover規則

四、zabbix-server 登陸web界面進行設置,創建規則,並自動加入,自動鏈接模板


  1.Configuration-->Discovery-->Create discovery rule


下面是創建規則時的具體參數,來自官網:

 

Parameter

Description

Name

Unique name of the rule. For example, “Local network”.

Discovery by proxy

What performs discovery:
no proxy - Zabbix server is doing discovery
<proxy name> - this proxy performs discovery

IP range

The range of IP addresses for discovery. It may have the following formats:
Single IP: 192.168.1.33
Range of IP addresses: 192.168.1-10.1-255. The range is limited by the total number of covered addresses (less than 64K).
IP mask: 192.168.4.0/24
supported IP masks:
/16 - /30 for IPv4 addresses
/112 - /128 for IPv6 addresses
List: 192.168.1.1-255, 192.168.2.1-100, 192.168.2.200, 192.168.4.0/24
Since Zabbix 3.0.0 this field supports spaces, tabulation and multiple lines.

Delay (in sec)

This parameter defines how often Zabbix will execute the rule.
Delay is measured after the execution of previous discovery instance ends so there is no overlap.

Checks

Zabbix will use this list of checks for discovery.
Supported checks: SSH, LDAP, SMTP, FTP, HTTP, HTTPS, POP, NNTP, IMAP, TCP, Telnet, Zabbix agent, SNMPv1 agent, SNMPv2 agent, SNMPv3 agent, ICMP ping.
A protocol-based discovery uses the net.tcp.service[] functionality to test each host, except for SNMP which queries an SNMP OID. Zabbix agent is tested by querying an item. Please see agent items for more details.
The 'Ports' parameter may be one of following:
Single port: 22
Range of ports: 22-45
List: 22-45,55,60-70

Device uniqueness criteria

Uniqueness criteria may be:
IP address - no processing of multiple single-IP devices. If a device with the same IP already exists it will be considered already discovered and a new host will not be added.
Type of discovery check - either SNMP or Zabbix agent check.

Enabled

With the check-box marked the rule is active and will be executed by Zabbix server.
If unmarked, the rule is not active. It won't be executed.

  2.添加動作。自動添加主機到linux server 組,並鏈接模板Linux Os 。
  選擇【Configuration】->【Actions】,在右邊“Event source”選擇“Discovery”,然后創建Action規則如下圖所示:

  設置動作的 name:

  添加觸發的Action的條件

A: ip 范圍,或者某個ip,可以添加多個網段

D:agent的狀態是up

C:服務類型是 zabbix-agent

 

  下面就是配置操作(Operations)。即符合條件后,進行的操作。

  操作主要有三個,添加主機、添加到server組、鏈接OS Liunx 模板,點擊Add。后續的還可以添加sendmessage 等。

  3.觀察MonitoringàDiscovery中,有沒有機器加入進來。為了便於觀察,我們之前設置的發現輪詢的時間是60秒。如圖:

上面是掃描發現的主機。6台客戶端都已發現,下面的是自動鏈接到組和模板。

 

 

轉自:http://www.cnblogs.com/hanyifeng/p/5363864.html

感謝作者


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM