首页 » 监控 » 正文

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

发表评论