学习zabbix(五)
前言
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix组件主要分两个: zabbix-server和zabbix-agent。支持的监控协议有ICMP,IPMI,SNMP,HTTP以及zabbix协议(zabbix协议是最常使用的协议用来监控各被监控端)。
收集的数据存放在数据库中,数据库支持mysql,oracle等等。
第三个组件:zabbix web gui这个接口提供web页面来监控和管理各被监控端。
第四个组件:zabbix proxy(实现分布式监控专用组件非必要组件,被监控服务器超过一千以上可以使用此组件。)
本次实验逻辑架构如下
相关组件介绍
zabbix_get进程去客户端收集数据,
zabbix_agentd进程通过监听在一个套接字上接收
zabbix_get的请求,通过zabbix_sender将
数据收集发送给服务器端,数据保存在zabbix数据库中,
zabbix_get这种方法主要用于测试,通过写脚本或远程执行命令的方式。
zabbix server自己自动会周期性的去被监控端收集数据,收集哪些数据在服务器端事先定义。
zabbix server ,zabbix database,zabbix web gui 可以部署在一台服务器上,为了提升性能可以放在不同主机上。
zabbix一些常用术语
host(主机):要监控的网络设备,可由IP或DNS名称指定
host group(主机组):主机的逻辑容器,可以包含主机和模板,但同一个组内的主机和模板不能互相链接;主机组通常在给用户或用户组指派监控权限时使用(大致了解下就可以了)。
item(监控项):这个从名字上可以理解,具体要监控哪些指标由它定义。
trigger(触发器):就是超过了定义的合理范围,这家伙就会报警。
event(事件):这都是触发器产生的。
action(动作):对事件如何应对,比如要执行哪些操作。
escalation(报警升级):如果在定义的5分钟没反应,从warning级别升到high级别,就是要提醒别人要尽快处理。
media(媒介):发送报警的手段和通道,如Email。
remote command(远程命令):预定义的命令,可在被监控主机处于某个特定条件下时自动执行。
template(模板):用于快速定义被监控主机的预设条目集合,通常包含了item、trigger、graph、screen、application以及low-level discovery rule;模板可以直接链接至单个主机。(这个概念不理解不过没关系的,只要具体会怎么操作就可以了)
application(应用):一组item的集合。
以上术语的关系可以用下图表示(大致明白就行):
上图中的poller这个进程就是去各客户端获取数据的。
zabbix产生的数据主要由四部分组成:
配置数据(忽略)
历史数据:50bytes
历史趋势数据: 128bytes
事件数据:130bytes
历史数据:采样生成的数据
历史趋势数据:每小时的最大值、最小值、平均值、统计
通过对以上数据的计算,可以得出我们需要一个多大的zabbix数据库,来定制磁盘硬件。
具体算法:
假设有60000个监控项,那每秒中处理的数据就有60000/60=1000条
历史数据大小=天数X每秒钟处理的数据量X24X3600X50Bytes
趋势数据:
每一个趋势128Bytes,
大小=天数X监控项X24X128Bytes
事件数据:
每个占据130Bytes
大小:天数X86400X130(假设每秒中产生一个事件)
本次实验的zabbix软件版本
装下面这个版本,红框内选中的
http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/
实验所需机器3台,系统环境如下
3台机器,一台做zabbix-server,一台作为zabbix-agent,一台作为zabbix-proxy
1
2
3
4
5
|
[root@linux-node1 ~] # uname -rm 2.6.32-504.el6.x86_64 x86_64 [root@linux-node1 ~] # cat /etc/redhat-release CentOS release 6.6 (Final) [root@linux-node1 ~] # |
安装zabbix相关包
复制链接地址,下载wget
noarch表明与处理器无关,src是源码包需要编译
执行如下命令,在Zabbix Server和Zabbix Agent上
1
2
3
4
|
mkdir /tools -p cd /tools/ wget http: //repo .zabbix.com /zabbix/2 .4 /rhel/6/x86_64/zabbix-release-2 .4-1.el6.noarch.rpm rpm -ivh zabbix-release-2.4-1.el6.noarch.rpm |
查看这个包安装了哪些
1
2
3
4
5
6
|
[root@linux-node1 tools] # rpm -ql zabbix-release /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX /etc/yum .repos.d /zabbix .repo /usr/share/doc/zabbix-release-2 .4 /usr/share/doc/zabbix-release-2 .4 /GPL [root@linux-node1 tools] # |
它创建了一个zabbix.repo文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@linux-node1 tools] # cat /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=http: //repo .zabbix.com /zabbix/2 .4 /rhel/6/ $basearch/ enabled=1 gpgcheck=1 gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=http: //repo .zabbix.com /non-supported/rhel/6/ $basearch/ enabled=1 gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1 [root@linux-node1 tools] # |
Zabbix Server服务器安装如下包
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@linux-node1 tools] # yum install zabbix zabbix-server zabbix-web zabbix-server-mysql zabbix-web-mysql zabbix-agent -y Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Package zabbix-2.4.8-1.el6.x86_64 already installed and latest version Package zabbix-server-2.4.8-1.el6.x86_64 already installed and latest version Package zabbix-web-2.4.8-1.el6.noarch already installed and latest version Package zabbix-server-mysql-2.4.8-1.el6.x86_64 already installed and latest version Package zabbix-web-mysql-2.4.8-1.el6.noarch already installed and latest version Package zabbix-agent-2.4.8-1.el6.x86_64 already installed and latest version Nothing to do [root@linux-node1 tools] # |
由于Zabbix Server把数据存到mysql里,因此还需要安装mysql相关包
1
2
3
4
5
6
7
8
|
[root@linux-node1 tools] # yum install -y mysql-server mysql Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Package mysql-server-5.1.73-8.el6_8.x86_64 already installed and latest version Package mysql-5.1.73-8.el6_8.x86_64 already installed and latest version Nothing to do [root@linux-node1 tools] # |
启动mysqld
1
2
3
|
[root@linux-node1 tools] # /etc/init.d/mysqld start Starting mysqld: [ OK ] [root@linux-node1 tools] # |
复制配置文件替换默认的
1
2
3
|
[root@linux-node1 tools] # cp /usr/share/mysql/my-medium.cnf /etc/my.cnf cp : overwrite ` /etc/my .cnf'? y [root@linux-node1 tools] # |
在[mysqld]模块最后加入字符集的相关参数
1
2
3
|
character- set -server = utf8 init-connect = 'SET NAMES utf8' collation-server = utf8_general_ci |
加入之后如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[mysqld] port = 3306 socket = /var/lib/mysql/mysql .sock skip-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M character- set -server = utf8 init-connect = 'SET NAMES utf8' collation-server = utf8_general_ci |
重启mysql
1
2
3
4
|
[root@linux-node1 tools] # /etc/init.d/mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ] [root@linux-node1 tools] # |
登录mysql查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@linux-node1 tools] # mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73-log Source distribution Copyright (c) 2000, 2013, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and /or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> |
官网有关于Zabbix建库相关脚本
1
2
3
4
5
6
7
8
9
|
MySQL shell> mysql -uroot -p<password> mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>' ; mysql> quit; shell> mysql -uzabbix -p<password> zabbix < database /mysql/schema .sql # stop here if you are creating database for Zabbix proxy shell> mysql -uzabbix -p<password> zabbix < database /mysql/images .sql shell> mysql -uzabbix -p<password> zabbix < database /mysql/data .sql |
建库和授权用户操作如下
1
2
3
4
5
6
7
8
9
|
mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix' ; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye [root@linux-node1 tools] # |
导入脚本操作如下
1
2
3
4
5
6
7
8
9
|
[root@linux-node1 tools] # cd /usr/share/doc/zabbix-server-mysql-2.4.8/create/ data.sql images.sql schema.sql [root@linux-node1 tools] # cd /usr/share/doc/zabbix-server-mysql-2.4.8/create/ [root@linux-node1 create] # ls data.sql images.sql schema.sql [root@linux-node1 create] # mysql -uzabbix -pzabbix zabbix <schema.sql [root@linux-node1 create] # mysql -uzabbix -pzabbix zabbix <images.sql [root@linux-node1 create] # mysql -uzabbix -pzabbix zabbix <data.sql [root@linux-node1 create] # |
检查
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
[root@linux-node1 create] # mysql -uzabbix -pzabbix -e 'use zabbix;show tables;' +-----------------------+ | Tables_in_zabbix | +-----------------------+ | acknowledges | | actions | | alerts | | application_template | | applications | | auditlog | | auditlog_details | | autoreg_host | | conditions | | config | | dbversion | | dchecks | | dhosts | | drules | | dservices | | escalations | | events | | expressions | | functions | | globalmacro | | globalvars | | graph_discovery | | graph_theme | | graphs | | graphs_items | | group_discovery | | group_prototype | | groups | | history | | history_log | | history_str | | history_text | | history_uint | | host_discovery | | host_inventory | | hostmacro | | hosts | | hosts_groups | | hosts_templates | | housekeeper | | httpstep | | httpstepitem | | httptest | | httptestitem | | icon_map | | icon_mapping | | ids | | images | | interface | | interface_discovery | | item_condition | | item_discovery | | items | | items_applications | | maintenances | | maintenances_groups | | maintenances_hosts | | maintenances_windows | | mappings | | media | | media_type | | opcommand | | opcommand_grp | | opcommand_hst | | opconditions | | operations | | opgroup | | opmessage | | opmessage_grp | | opmessage_usr | | optemplate | | profiles | | proxy_autoreg_host | | proxy_dhistory | | proxy_history | | regexps | | rights | | screens | | screens_items | | scripts | | service_alarms | | services | | services_links | | services_times | | sessions | | slides | | slideshows | | sysmap_element_url | | sysmap_url | | sysmaps | | sysmaps_elements | | sysmaps_link_triggers | | sysmaps_links | | timeperiods | | trends | | trends_uint | | trigger_depends | | trigger_discovery | | triggers | | user_history | | users | | users_groups | | usrgrp | | valuemaps | +-----------------------+ [root@linux-node1 create] # |
配置文件修改
修改apache相关配置
zabbix Server默认用的apache,安装Zabbix Server时,它自动帮我们装好了apache
修改apache配置文件里zabbix.conf文件的时区,并取消注释。这里可以vim修改,也可以采用sed替换
1
2
3
4
5
6
7
8
9
|
[root@linux-node1 conf.d] # cd /etc/httpd/conf.d/ [root@linux-node1 conf.d] # ls mod_dnssd.conf php.conf README welcome.conf zabbix.conf [root@linux-node1 conf.d] # grep -n timezone zabbix.conf 19: # php_value date.timezone Europe/Riga [root@linux-node1 conf.d] # vim zabbix.conf [root@linux-node1 conf.d] # grep -n timezone zabbix.conf 19: php_value date .timezone Asia /Shanghai [root@linux-node1 conf.d] # |
查看下相关配置
1
2
3
4
5
6
7
8
9
10
11
|
[root@linux-node1 conf.d] # head -10 zabbix.conf # # Zabbix monitoring system php web frontend # Alias /zabbix /usr/share/zabbix <Directory "/usr/share/zabbix" > Options FollowSymLinks AllowOverride None Order allow,deny |
看看都有哪些东西
到这个目录下ls一下,看到都是php代码。zabbix前端都是php写的
它的server端是c和c++写的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@linux-node1 conf.d] # cd /usr/share/zabbix/ [root@linux-node1 zabbix] # ls acknow.php chart.php index.php report5.php actionconf.php charts.php items.php report6.php adm.gui.php conf js robots.txt adm.housekeeper.php conf. import .php jsLoader.php screenconf.php adm.iconmapping.php dashboard.php jsrpc.php screenedit.php adm.images.php dashconf.php latest.php screens.php adm.macros.php discoveryconf.php locale scripts_exec.php adm.other.php discovery.php maintenance.php scripts.php adm.regexps.php disc_prototypes.php map.php search.php adm.triggerdisplayoptions.php events.php maps.php services.php adm.triggerseverities.php fonts media_types.php setup.php adm.valuemapping.php graphs.php overview.php slideconf.php adm.workingtime.php history .php popup_bitem.php slides.php api_jsonrpc.php host_discovery.php popup_httpstep.php srv_status.php applications.php hostgroups.php popup_media.php styles audio hostinventoriesoverview.php popup_period.php sysmap.php auditacts.php hostinventories.php popup.php sysmaps.php auditlogs.php host_prototypes.php popup_right.php templates.php authentication.php host_screen.php popup_trexpr.php tr_comments.php browserwarning.php hosts.php popup_usrgrp.php tr_events.php chart2.php httpconf.php profile.php trigger_prototypes.php chart3.php httpdetails.php proxies.php triggers.php chart4.php httpmon.php queue.php tr_logform.php chart5.php image.php report1.php tr_status.php chart6.php images report2.php tr_testexpr.php chart7.php imgstore.php report3.php usergrps.php chart_bar.php include report4.php users .php [root@linux-node1 zabbix] # |
1
2
3
|
[root@linux-node1 conf.d] # /etc/init.d/httpd start Starting httpd: [ OK ] [root@linux-node1 conf.d] # |
修改Zabbix Server默认配置文件
因为zabbix存mysql数据,所以要改下server端的配置文件,server端和mysql打交道
1
2
3
4
|
[root@linux-node1 conf.d] # cd /etc/zabbix/ [root@linux-node1 zabbix] # ls web zabbix_agentd.conf zabbix_agentd.d zabbix_server.conf [root@linux-node1 zabbix] # vim zabbix_server.conf |
修改DBHost 和DBName
用户名和密码
通过浏览器安装配置zabbix-server
浏览器里输入如下链接
http://10.0.1.161/zabbix
看到如下界面进行安装
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312203910248-281363070.png)
给它起个名字zabbix,这是是可选的。默认端口就是10051
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312204120107-1820607809.png)
点击Finish自动跳转到了登录界面
默认的用户名是Admin,密码是zabbix
登录成功,第一件事就是改密码
zabbix server 还没运行,上面提示说明这个前端页面不仅仅访问数据库,还访问zabbix server
1
2
3
|
[root@linux-node1 zabbix] # /etc/init.d/zabbix-server start Starting Zabbix server: [ OK ] [root@linux-node1 zabbix] # |
Zabbix Server本身也要监控自己
接下来运行一个agent端,先修改agent配置文件
vim /etc/zabbix/zabbix_agentd.conf
启动agent
1
2
3
4
|
[root@linux-node1 ~] # vim /etc/zabbix/zabbix_agentd.conf [root@linux-node1 ~] # /etc/init.d/zabbix-agent start Starting Zabbix agent: [ OK ] [root@linux-node1 ~] # |
zabbix的web界面介绍
一些仪表盘解释
Actions 是故障了要通知,怎么通知呢,在这里配置
比如配置发短信,发邮件,还能配置让它执行命令,比如reboot
screens是一些图片效果
slide shows是幻灯片,比如你有3个大屏,但是只有一个屏幕,你可以让它来回切换
Maps 你可以做一个架构图
Discovery 和自动化部署有关,
IT services :sla(SLA:Service-Level Agreement的缩写,意思是服务等级协议),比如我保证网站可用率 99%。(管理体系相关)你今年的sla达标了么等
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312210804123-776728514.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312211111123-525466731.png)
1
2
3
4
5
6
|
[root@linux-node1 ~] # netstat -lntp |grep 100 tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 5846 /zabbix_agentd tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 5692 /zabbix_server tcp 0 0 :::10050 :::* LISTEN 5846 /zabbix_agentd tcp 0 0 :::10051 :::* LISTEN 5692 /zabbix_server [root@linux-node1 ~] # |
也可以使用lsof命令查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@linux-node1 ~] # lsof -i:10050 COMMAND PID USER FD TYPE DEVICE SIZE /OFF NODE NAME zabbix_ag 5846 zabbix 4u IPv4 24785 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5846 zabbix 5u IPv6 24786 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5848 zabbix 4u IPv4 24785 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5848 zabbix 5u IPv6 24786 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5849 zabbix 4u IPv4 24785 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5849 zabbix 5u IPv6 24786 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5850 zabbix 4u IPv4 24785 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5850 zabbix 5u IPv6 24786 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5851 zabbix 4u IPv4 24785 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5851 zabbix 5u IPv6 24786 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5852 zabbix 4u IPv4 24785 0t0 TCP *:zabbix-agent (LISTEN) zabbix_ag 5852 zabbix 5u IPv6 24786 0t0 TCP *:zabbix-agent (LISTEN) [root@linux-node1 ~] # lsof -i:10051 |
JMX 监控jvm的
IPMI监控硬件的。监控IPMI性能比较差,经常获取不到数据
监控项多了可能会慢,比如监控一项。温度,就不用监控风扇了。风扇不转了温度肯定上来了
Proxy:表示zabbix支持分布式的。
enabled勾选的话,表示打开监控。监控Zabbix Server,也可以不勾选,返回界面之后点击Enable
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312212549295-756511648.png)
宏
它在做snmp监控的时候用,简单来说,就是给一个变量设置一个值
主机资产,zabbix提供了一个资产管理的功能,默认是关闭状态,可以选manual手动填,也可以选
Automatic自动,在创建items的时候,可以把得到的值映射到资产里面,这个功能比较鸡肋,比如下面网卡只有两个,我服务器要是4个网卡呢
点击就启用了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312213000795-379222997.png)
application和item以及graph介绍
application类似items监控项的监控组,就是组的概念
监控间隔。60秒
历史保留的天数7天
趋势图保留的天数,365天
点一下enabled就把这一项关闭了,关闭后就不监控这一项了
如果有个东西老报警。你就可以把它关闭了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312213224311-933255629.png)
鼠标放触发器上,看到条件表达式,每五分钟,超过300 什么值就报警
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312213613232-608438098.png)
添加node2到监控里
在linux-node2上装zabbix客户端
1
2
3
4
5
|
mkdir /tools -p cd /tools/ wget http: //repo .zabbix.com /zabbix/2 .4 /rhel/6/x86_64/zabbix-release-2 .4-1.el6.noarch.rpm rpm -ivh zabbix-release-2.4-1.el6.noarch.rpm yum install zabbix-agent -y |
自定义监控和图表
zabbix服务端是不支持windows的,只有客户端支持windows
下面地址可以下载windows客户端监控。
它是个exe文件,配置个zabbix.conf文件
它有2个参数需要注意下
http://www.zabbix.com/download2
修改linux-node2的Zabbix agent配置文件
vim /etc/zabbix/zabbix_agentd.conf
启动agent
1
2
3
|
[root@linux-node2 tools] # /etc/init.d/zabbix-agent start Starting Zabbix agent: [ OK ] [root@linux-node2 tools] # |
另外让它开机启动,可以选择加入rc.local
1
2
|
[root@linux-node2 ~] # echo "/etc/init.d/zabbix-agent start" >>/etc/rc.local [root@linux-node2 ~] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312220141092-1724568722.png)
如下
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312220340920-77449206.png)
host-name这里必须写正确的,显示的名称可以随便写,但是建议规范点
选择模板
模板里带有好多监控项,触发器,图形。因为模板太多了。上百个,就搞成搜索的了
搜索linux
上面的是基于agent监控的,下面是基于snmp监控的,就不用装agent了
等一会变绿色了
在监控里查看主机是否有数据了
选择主机
通过拖动这里也可以改变时间范围,查看历史数据
点击这里可以隐藏下面的Zoom时间栏
这个agent ping 不是icmp的ping,而是通过agent ping的。agent发个请求看它返回不返回
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312222405811-1315413534.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312222521514-1308413008.png)
自定义监控项并加入到监控页面上
以上都是模板带的监控项,如何自定义一个监控项呢
自定义监控项有2个步骤
1、改配置文件,在里面写上自定义的监控项
2、web页面加上
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312222746451-429348010.png)
获取命令如下
1
2
3
4
5
|
[root@linux-node2 ~] # uptime 06:29:23 up 22 min, 1 user, load average: 0.00, 0.00, 0.00 [root@linux-node2 ~] # uptime | awk -F ' ' '{print $5}' 1 [root@linux-node2 ~] # |
修改linux-node2的配置文件
vim /etc/zabbix/zabbix_agentd.conf
修改下面地方
逗号隔开
保证这个key在整个系统是唯一的,command可以换成脚本
另外这个用户自定义的参数返回值最大是512KB,不能超过这个
UserParameter=login-user,uptime |awk -F ' ' '{print $4}'
这里注意下,下面截图是错的,应该是$4
保存,重启
1
2
3
4
5
|
[root@linux-node2 ~] # vim /etc/zabbix/zabbix_agentd.conf [root@linux-node2 ~] # /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@linux-node2 ~] # |
服务端测试下能否获取这个客户端自定义的值
zabbix-get命令。之前没装,补上
1
2
3
|
[root@linux-node1 ~] # zabbix_get - bash : zabbix-get: command not found [root@linux-node1 ~] # yum install zabbix-get -y |
查看帮助用法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@linux-node1 ~] # zabbix_get usage: zabbix_get [-hV] -s <host name or IP> [-p <port>] [-I <IP address>] -k <key> [root@linux-node1 ~] # zabbix_get --help Zabbix get v2.4.8 (revision 59539) (20 April 2016) usage: zabbix_get [-hV] -s <host name or IP> [-p <port>] [-I <IP address>] -k <key> Options: -s --host <host name or IP> Specify host name or IP address of a host -p --port <port number> Specify port number of agent running on the host. Default is 10050 -I -- source -address <IP address> Specify source IP address -k --key <key of metric> Specify key of item to retrieve value for -h --help Display help information -V --version Display version number Example: zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]" [root@linux-node1 ~] # |
获取方式如下
1
2
3
|
[root@linux-node1 ~] # zabbix_get -s 10.0.1.162 -k login-user 1 [root@linux-node1 ~] # |
客户端克隆一个会话,服务端继续取值,这就是一个自定义的key,当然你里面写什么都可以
1
2
3
|
[root@linux-node1 ~] # zabbix_get -s 10.0.1.162 -k login-user 2 [root@linux-node1 ~] # |
get命令获取成功,才能加。准备加到web上
点击进去
点击Items,显示如下
点击右上角的Create item
name可以和key不一样,但是key必须是之前设置的,右边select是选择系统自带的key
Data type 中decimal是10进制的意思
units 是单位的意思。zabbix默认会把1000换算成1k的
如果勾选这里,上面的数会乘以文本框里的东西
不太重要的key建议设置5分钟,太频繁没什么用,反而引起zabbix性能下降
下面设置了就以下面为准
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312224938342-1647159763.png)
描述的东西能写最好写
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312230211201-194708435.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312230233436-109445234.png)
点击Add
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312230506857-1740610336.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312230415357-721288132.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312230438154-1712348120.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312230544967-425507575.png)
有数据了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312234752811-2099829451.png)
点击+ 可以加入到收藏里,然后在仪表盘查看
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312234712248-852798332.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170312234852732-1870943664.png)
##########################################################################################
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140027120-1348941580.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140100916-821697297.png)
这里看到主机资产有数据了,这里的数据,就是来自下面的关联
上面的数据就是设置login-user时候设置的关联
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313141435932-1491284365.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313142124854-117154051.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140337245-329209960.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140354838-1087603197.png)
起个名字,添加个表达式
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140446182-143005767.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140519166-1284463014.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140842666-390282873.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313140949588-504881661.png)
查看另一个页面 --依赖
如果某件事发生了,就别报这个警了。比如如果主机down了就别报警了。先不加这个依赖
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313141023729-1506924340.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143107432-1614147954.png)
图形里也能看到
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143147588-1768978791.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143253088-500413396.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143346729-502964381.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143436854-100931556.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143544463-138830344.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143721182-1922231047.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313143904885-1388054495.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313185306245-475392617.png)
如果是发短信报警,要把上面的message改的短一些,改成70个字符以内
国内英文单词按字母算,汉字按个数算
精简下,最下面是恢复的时候再发个短信,把下面粘贴下放下面即可,生产环境是这么玩的
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313185656870-1704358620.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313185935432-202796572.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190021573-1755872784.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190137713-658912113.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190351073-1949319587.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190728479-787193672.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190822963-1708354062.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190906010-761605859.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313190935995-1819949554.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313191025979-171788148.png)
你可以写个脚本发邮件,发短信等,或者echo hehe,一般使用脚本是主流
AlertScriptsPath=/usr/lib/zabbix/alertscripts
这里配置了报警脚本的路径
把你写的脚本放这里就好了,这样它就能找到了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313192130682-227283478.png)
进入如下目录写一个脚本,内容如下。
这个zabbix脚本要接收3个参数
$1,$2,$3
$1是邮件地址
$2 邮件主题
$3 邮件内容
1
2
3
4
5
|
[root@linux-node1 alertscripts] # pwd /usr/lib/zabbix/alertscripts [root@linux-node1 alertscripts] # cat Send_Mail.sh echo $1 $2 $3 >> /tmp/test .log [root@linux-node1 alertscripts] # |
加上课执行权限
1
|
[root@linux-node1 alertscripts] # chmod +x Send_Mail.sh |
网页这里就可以这么写了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313195212401-523720447.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313195639495-1128368896.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313195824573-1786394759.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313203613385-27012646.png)
我的选择如下
Add之后
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313200314995-730852620.png)
1
2
3
4
|
[root@linux-node1 alertscripts] # tail -f /tmp/test.log 525031638@qq.com PROBLEM linux-node2:login-user): 3 ^C [root@linux-node1 alertscripts] # |
仪表盘里也能看到它自动执行了action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
[root@linux-node1 alertscripts] # pwd /usr/lib/zabbix/alertscripts [root@linux-node1 alertscripts] # ll total 8 -rwxr-xr-x 1 root root 714 Mar 13 20:16 pymail.py -rwxr-xr-x. 1 root root 30 Nov 29 23:20 Send_Mail.sh [root@linux-node1 alertscripts] # cat pymail.py #!/usr/bin/python #coding: utf-8 import smtplib import sys from email.mime.text import MIMEText from email.header import Header from email.Utils import COMMASPACE receiver = sys.argv[1] subject = sys.argv[2] mailbody = sys.argv[3] smtpserver = 'smtp.exmail.qq.com' username = 'test1@xxxxxx.com' password = '123456' sender = username msg = MIMEText(mailbody, 'html' , 'utf-8' ) #中文需参数‘utf-8’,单字节字符不需要 msg[ 'Subject' ] = Header(subject, 'utf-8' ) msg[ 'From' ] = username msg[ 'To' ] = receiver smtp = smtplib.SMTP() smtp.connect(smtpserver) smtp.login(username, password) smtp.starttls() smtp.sendmail(msg[ 'From' ], msg[ 'To' ], msg.as_string()) smtp.quit() [root@linux-node1 alertscripts] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313201929713-1089487069.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313202139698-1526089638.png)
解决告警之后又收到了恢复正常的邮件
看到邮件内容多了括号和空格,把下面多余的空格和括号删除即可
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313202851588-1222182792.png)
qq邮件可以绑定微信。对于使用微信的用户可以及时看到告警
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313205155620-370562240.png)
查看linux自带的模板
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313205238495-1147024302.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313205523823-1609791352.png)
创建自定义模板
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313205548166-1122228604.png)
给此模板命名为demo,同时把linux-node2加入到此模板里
link给一个模板
点击Update
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313210541791-2037248071.png)
点击Update之后,提示模板不能被通过此模板再去link给其它模板(这里不是很明白,有时间再研究下)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313210755073-826403465.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313212210057-1195407197.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313212346635-2003344240.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313212359276-77784924.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313212524776-1910842810.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313212756026-417422078.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313212902557-2007554096.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313213140135-1246122466.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313213202401-1536032093.png)
最后demo模板结果如下
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313213303010-491100053.png)
你可以把这个模板链接到任何一台机器上,这样模板里有的监控项,那个机器就有了
其实你自定义的监控项可以从配置文件里取出来,放下面目录下,然后在客户端主配置文件里include进去
1
2
3
4
|
[root@linux-node2 zabbix_agentd.d] # cd /etc/zabbix/zabbix_agentd.d/ [root@linux-node2 zabbix_agentd.d] # ls userparameter_mysql.conf [root@linux-node2 zabbix_agentd.d] # |
这个agent.conf自带include选项
生产环境都建议这么干。尽量不要修改原来的配置文件。更专业一点
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313214423495-1771624338.png)
1
2
3
4
5
6
7
|
[root@linux-node2 alertscripts] # cd /etc/zabbix/ [root@linux-node2 zabbix] # ls web zabbix_agentd.conf zabbix_agentd.d zabbix_server.conf [root@linux-node2 zabbix] # mkdir shells [root@linux-node2 zabbix] # cd shells/ [root@linux-node2 shells] # pwd /etc/zabbix/shells |
把脚本上传上去
1
2
3
4
5
6
7
8
9
|
[root@linux-node2 shells] # rz -E rz waiting to receive. [root@linux-node2 shells] # [root@linux-node2 shells] # ls zabbix_linux_plugin.sh [root@linux-node2 shells] # chmod +x zabbix_linux_plugin.sh [root@linux-node2 shells] # ./zabbix_linux_plugin.sh Usage: . /zabbix_linux_plugin .sh {tcp_status key|memcached_status key|redis_status key|nginx_status key} [root@linux-node2 shells] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313215608885-2081288508.png)
因此,运行此脚本需要给它2个参数
1
2
3
4
5
|
[root@linux-node2 shells] # ./zabbix_linux_plugin.sh tcp_status LISTEN 14 [root@linux-node2 shells] # ./zabbix_linux_plugin.sh tcp_status TIME-WAIT 52 [root@linux-node2 shells] # |
在下面目录下,创建一个文件,存放自定义的key和value,而value通过此脚本获取
key这里是linux_status[*] ,表示它支持列表
1
2
3
4
5
6
7
|
[root@linux-node2 zabbix_agentd.d] # pwd /etc/zabbix/zabbix_agentd .d [root@linux-node2 zabbix_agentd.d] # ls userparameter_mysql.conf zabbix-linux-plugin.conf [root@linux-node2 zabbix_agentd.d] # cat zabbix-linux-plugin.conf UserParameter=linux_status[*], /etc/zabbix/shells/zabbix_linux_plugin .sh "$1" "$2" "$3" [root@linux-node2 zabbix_agentd.d] # |
重启linux-node2的Zabbix agent
1
2
3
4
|
[root@linux-node2 zabbix_agentd.d] # /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@linux-node2 zabbix_agentd.d] # cd |
server端通过zabbix_get获取数据没问题
1
2
3
|
[root@linux-node1 zabbix] # zabbix_get -s 10.0.1.162 -k linux_status[tcp_status,ESTAB] 2 [root@linux-node1 zabbix] # |
注意,zabbix监控的时候,是使用的zabbix用户
1
2
3
|
[root@linux-node2 ~] # ll /tmp/netstat.tmp -rw-rw-r-- 1 zabbix zabbix 31 Mar 13 22:09 /tmp/netstat .tmp [root@linux-node2 ~] # |
接下来你要做的是,创建一种模板,tcp有11个状态,你要创建11个key
然后做个图,这里有别人做好的
配置--模板--导入
选择电脑上的模板文件
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313223750557-1208560640.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313225956370-436656621.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313231429885-760950227.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313231520901-1444656422.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313231551276-1003076513.png)
可以批量更改
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313231825338-978427114.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313231913963-925014338.png)
本来是300的,都变成了30秒
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313232009745-1393470532.png)
##############################################################################
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313233405151-102911409.png)
下面就是自动注册
在operations这里找到Add host
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313233733354-477754406.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234114182-924785052.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234156901-1972268864.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234500979-1250002320.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234518354-149196855.png)
创建1个2行2列的screen。
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234548620-1402975843.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234612916-908568000.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234629823-1982179987.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234744823-1084936407.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313234920682-1550799385.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313235127557-426152645.png)
加入进来了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313235149416-11043117.png)
从Monitor--Screens里也可以加
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170313235251010-763047123.png)
zabbix监控主动模式
默认情况下zabbix是运行在被动模式,这个主动和被动是针对zabbix-agent来说的
agent默认监听一个端口,10050,server会定期主动过来要数据。server端主动的发命令,告诉agent。取哪些数据
如果1万台机器,zabbix同时要发10000个请求到agent,问他们数据。这么弄肯定有问题
zabbix agent也支持主动模式,主动给服务器发消息,这时候用于分布式比较好了
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170314210837073-987765081.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170314210857916-750758156.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315130622479-159635241.png)
全部克隆
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315130652901-1931371948.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315131409526-414468219.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315131438713-513830849.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315131517448-963793298.png)
点击进去
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315131541557-1366369956.png)
点击Full clone
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315131559979-1811446189.png)
把克隆出来的改成如下名字,多了个Active用来区分,然后点击Add
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315133515791-1173997437.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315134125963-1978705555.png)
改成如下
以上更改仅仅是添加了新的模板,items这里并没改掉
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315134509073-1116778966.png)
批量修改
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315130449745-615121014.png)
下面这里改成Active的
右边的items这里都变成了Active的。上面没变的是link的另一个模板的,因此link的模板也要改
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315134605729-235104261.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315134705198-1047914006.png)
也改成active的
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315134926401-1603471541.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315135044073-1803039660.png)
删除之前的node2主机,改成主动模式添加
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315145406760-855485242.png)
下面是设置为0才表示agent开启主动监控模式
把ServerActive改成Zabbix Server的地址,把Hostname改成自己的主机名
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315145620729-875555381.png)
1
2
3
4
5
6
7
8
9
10
|
[root@linux-node2 ~] # grep '^[a-Z]' /etc/zabbix/zabbix_agentd.conf PidFile= /var/run/zabbix/zabbix_agentd .pid LogFile= /var/log/zabbix/zabbix_agentd .log LogFileSize=0 StartAgents=0 ServerActive=10.0.1.161 Hostname=linux-node2.example.com Include= /etc/zabbix/zabbix_agentd .d/ UserParameter=login-user,uptime | awk -F ' ' '{print $4}' [root@linux-node2 ~] # |
重启agent服务
1
2
3
4
|
[root@linux-node2 ~] # /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@linux-node2 ~] # |
看到不再监听端口了
1
2
3
4
5
6
7
8
9
10
11
|
[root@linux-node2 ~] # netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2075 /sshd tcp 0 0 :::22 :::* LISTEN 2075 /sshd [root@linux-node2 ~] # ps -ef | grep zabbix zabbix 76194 1 0 19:38 ? 00:00:00 zabbix_agentd -c /etc/zabbix/zabbix_agentd .conf zabbix 76195 76194 0 19:38 ? 00:00:00 zabbix_agentd: collector [idle 1 sec] zabbix 76197 76194 0 19:38 ? 00:00:00 zabbix_agentd: active checks #1 [idle 1 sec] root 76211 75384 0 19:42 pts /0 00:00:00 grep --colour=auto zabbix [root@linux-node2 ~] # |
网页里添加主机
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315194511870-1625467158.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315194706479-377368754.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315194819088-1446924269.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315194753901-1370764967.png)
1
2
3
4
|
mkdir /tools -p cd /tools/ wget http: //repo .zabbix.com /zabbix/2 .4 /rhel/6/x86_64/zabbix-release-2 .4-1.el6.noarch.rpm rpm -ivh zabbix-release-2.4-1.el6.noarch.rpm |
1
|
yum install -y zabbix-proxy zabbix-proxy-mysql mysql-server |
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@linux-proxy tools] # yum install -y zabbix-proxy zabbix-proxy-mysql mysql-server Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * extras: mirrors.cn99.com * updates: mirrors.cn99.com Package zabbix-proxy-2.4.8-1.el6.x86_64 already installed and latest version Package zabbix-proxy-mysql-2.4.8-1.el6.x86_64 already installed and latest version Package mysql-server-5.1.73-8.el6_8.x86_64 already installed and latest version Nothing to do [root@linux-proxy tools] # |
启动刚装的mysql,并设置密码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
[root@linux-proxy tools] # /etc/init.d/mysqld start Initializing MySQL database: WARNING: The host 'linux-proxy.example.com' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files /mysql .server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h linux-proxy.example.com password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql- test -run.pl cd /usr/mysql-test ; perl mysql- test -run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ] Starting mysqld: [ OK ] [root@linux-proxy tools] # /usr/bin/mysqladmin -uroot password 'zabbix' [root@linux-proxy tools] # mysql -uroot -pzabbix Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and /or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> |
创建zabbix_proxy库,并授权zabbix用户,导入数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
[root@linux-proxy tools] # rpm -ql zabbix-proxy-mysql /usr/sbin/zabbix_proxy_mysql /usr/share/doc/zabbix-proxy-mysql-2 .4.8 /usr/share/doc/zabbix-proxy-mysql-2 .4.8 /create /usr/share/doc/zabbix-proxy-mysql-2 .4.8 /create/schema .sql [root@linux-proxy tools] # /usr/bin/mysqladmin -uroot password 'zabbix' /usr/bin/mysqladmin : connect to server at 'localhost' failed error: 'Access denied for user ' root '@' localhost ' (using password: NO)' [root@linux-proxy tools] # mysql -uroot -pzabbix Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and /or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database zabbix_proxy character set utf8; Query OK, 1 row affected (0.00 sec) mysql> grant all on zabbix_proxy.* to zabbix@localhost identified by 'zabbix' ; Query OK, 0 rows affected (0.00 sec) mysql> use zabbix_proxy; Database changed mysql> source /usr/share/doc/zabbix-proxy-mysql-2 .4.8 /create/schema .sql Query OK, 0 rows affected (0.01 sec) Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 |
1
|
[root@linux-proxy tools] # vim /etc/zabbix/zabbix_proxy.conf |
看到如下注释,proxy也可以运行在Active和Passtive模式下,工作中主要还是运行在Active模式下
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315222832776-1780901130.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315223150776-85409832.png)
DBHost和DBName都没变,不用修改
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315223345338-878394599.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315223513573-2057909418.png)
检查配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@linux-proxy tools] # vim /etc/zabbix/zabbix_proxy.conf [root@linux-proxy tools] # grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf ProxyMode=0 Server=10.0.1.161 Hostname=node3-proxy LogFile= /var/log/zabbix/zabbix_proxy .log LogFileSize=0 PidFile= /var/run/zabbix/zabbix_proxy .pid DBName=zabbix_proxy DBUser=zabbix DBPassword=zabbix DBSocket= /var/lib/mysql/mysql .sock ExternalScripts= /usr/lib/zabbix/externalscripts [root@linux-proxy tools] # |
1
2
3
4
5
6
7
8
9
10
11
|
[root@linux-proxy tools] # /etc/init.d/zabbix-proxy start Starting Zabbix proxy: [ OK ] [root@linux-proxy tools] # netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2076 /sshd tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 13310 /zabbix_proxy tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 13219 /mysqld tcp 0 0 :::22 :::* LISTEN 2076 /sshd tcp 0 0 :::10051 :::* LISTEN 13310 /zabbix_proxy [root@linux-proxy tools] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224008323-1415170280.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224113635-383993138.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224214448-1229938454.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224557104-620250304.png)
下面这里要选择proxy
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224634370-2084341155.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224743198-472344358.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315224837698-1057567368.png)
还需要把node2的指向改成proxy
1
|
[root@linux-node2 ~] # vim /etc/zabbix/zabbix_agentd.conf |
下面改成proxy地址,因为它要把数据发给proxy
重启agent
1
2
3
4
|
[root@linux-node2 ~] # /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@linux-node2 ~] # |
1
2
3
4
5
6
7
8
9
10
11
|
[root@linux-proxy tools] # tail -f /var/log/zabbix/zabbix_proxy.log 13537:20170315:225713.912 proxy #17 started [http poller #1] 13542:20170315:225713.918 proxy #22 started [history syncer #4] 13531:20170315:225713.918 proxy #11 started [trapper #2] 13543:20170315:225713.918 proxy #23 started [self-monitoring #1] 13532:20170315:225713.918 proxy #12 started [trapper #3] 13528:20170315:225713.919 proxy #8 started [poller #5] 13533:20170315:225713.922 proxy #13 started [trapper #4] 13538:20170315:225713.941 proxy #18 started [discoverer #1] 13520:20170315:225813.966 sending heartbeat message to server failed: error: "negative response: " failed "" , info: "proxy " linux-proxy.example.com " not found" 13534:20170315:225858.853 cannot send list of active checks to [10.0.1.162]: host [linux-node2.example.com] not found |
1
2
3
4
5
6
7
8
9
10
11
|
[root@linux-proxy tools] # tail -f /var/log/zabbix/zabbix_proxy.log 13638:20170315:230149.414 proxy #17 started [http poller #1] 13642:20170315:230149.415 proxy #21 started [history syncer #3] 13634:20170315:230149.415 proxy #13 started [trapper #4] 13637:20170315:230149.420 proxy #16 started [housekeeper #1] 13641:20170315:230149.420 proxy #20 started [history syncer #2] 13633:20170315:230149.424 proxy #12 started [trapper #3] 13643:20170315:230149.426 proxy #22 started [history syncer #4] 13635:20170315:230149.431 proxy #14 started [trapper #5] 13639:20170315:230149.448 proxy #18 started [discoverer #1] 13620:20170315:230149.453 received configuration data from server, datalen 7423 |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315230816557-737045369.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170315230910791-636626789.png)
Zabbox自动化监控---自动注册
自动化监控分为:
agent自动注册
server端自动发现
通过zabbix api方式插入数据(比如从cmdb读取资产里的主机,然后通过Zabbix的api插入Zabbix数据库)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203101588-264582980.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203117026-991052582.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203218198-1434171183.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203242526-759067210.png)
1
2
|
[root@linux-node1 ~] # zabbix_get -s 10.0.1.161 -k system.uname Linux linux-node1.example.com 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 |
1
2
3
4
|
[root@linux-node2 ~] # /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@linux-node2 ~] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203402682-429676673.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203451323-133510329.png)
1
2
|
[root@linux-node1 ~] # zabbix_get -s 10.0.1.161 -k system.uname Linux linux-node1.example.com 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 |
这两个条件
注意你的条件是a and b,operation 表示你想让它干什么。添加这台主机,然后添加主机组,再link一个模板
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203612416-681257510.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203624620-2021218103.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203640541-1961394815.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203657823-1179380470.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203747495-1912984023.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203811198-187720488.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203838682-650622519.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203858198-850220638.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316203926463-122073929.png)
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@linux-node2 ~] # grep '^[a-Z]' /etc/zabbix/zabbix_agentd.conf PidFile= /var/run/zabbix/zabbix_agentd .pid LogFile= /var/log/zabbix/zabbix_agentd .log LogFileSize=0 Server=10.0.1.161 StartAgents=3 ServerActive=127.0.0.1 Hostname=linux-node2.example.com HostMetadataItem=system. uname Include= /etc/zabbix/zabbix_agentd .d/ UserParameter=login-user,uptime | awk -F ' ' '{print $4}' [root@linux-node2 ~] # |
1
2
3
4
|
[root@linux-node2 ~] # /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@linux-node2 ~] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204018838-1022849473.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204032776-640685428.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204048870-1058479531.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204056510-891096760.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204109948-30212365.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204116854-1706476825.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204132901-881484571.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204147276-360603516.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204201323-640172477.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204214682-821169666.png)
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170316204228729-3744792.png)
######################################################################################
Zabbix api
对于以上两种方式,有些人都不选,倾向于使用第三种:使用zabbix api加上这个监控
在把这台机器删除了,然后discovery和自动注册的都关闭了
再换一种方式把它加进去,zabbix api两个作用
1、管理zabbix
2、查询一些数,把一些zabbix报警的图形一块发邮件
它支持很多方法
api的配置,在httpd.conf目录下。如下编辑zabbix.conf
1
|
[root@linux-node1 ~] # vim /etc/httpd/conf.d/zabbix.conf |
1
2
3
4
5
6
|
[root@linux-node1 zabbix] # cd /usr/share/zabbix/ [root@linux-node1 zabbix] # ls api_jsonrpc.php api_jsonrpc.php [root@linux-node1 zabbix] # ls api_jsonrpc.php -l -rw-r--r-- 1 root root 2342 Apr 20 2016 api_jsonrpc.php [root@linux-node1 zabbix] # |
可以看到,首先它是个api,传输模式是rpc的,传输格式是json的
既然是api,那肯定有验证,给api发用户名密码,得返回token吧
后面拿这个token就可以继续请求了,和openstack类似
打开文档看
https://www.zabbix.com/documentation/2.4/manual/api/reference
第一步,因为涉及登录,找用户相关的
Authenticate a user.
Request:
1
2
3
4
5
6
7
8
9
|
{ "jsonrpc": "2.0", "method": "user.login", "params": { "user": "Admin", "password": "zabbix" }, "id": 1 } |
Response:
1
2
3
4
5
|
{ "jsonrpc": "2.0", "result": "0424bd59b807674191e7d77572075f33", "id": 1 } |
通过curl访问
-s 静默
-X POST
-H 接类型
-d 接内容,用单引号引起来
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "user.login" , "params" : { "user" : "Admin" , "password" : "zabbix" }, "id" : 1 }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php { "jsonrpc" : "2.0" , "result" : "5733cec620a75d1f7e2ebcf725c7ccec" , "id" :1}[root@linux-node2 ~] # [root@linux-node2 ~] # |
看着不舒服,给它处理下,调用python的工具处理下,命令如下
1
2
3
4
5
6
7
8
9
10
11
|
curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "user.login" , "params" : { "user" : "Admin" , "password" : "zabbix" }, "id" : 1 }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool |
执行如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' > > { > "jsonrpc" : "2.0" , > "method" : "user.login" , > "params" : { > "user" : "Admin" , > "password" : "zabbix" > }, > "id" : 1 > }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool { "id" : 1, "jsonrpc" : "2.0" , "result" : "d05f9fa13c8b182d61e462b8aaded670" } [root@linux-node2 ~] # |
上面为什么要设置id,因为可能又多个请求,给不同的会话设置不同的id
你才知道这个是你的
把这个字符串记录下来
d05f9fa13c8b182d61e462b8aaded670
你请求的时候还可以加个下面userdata为true,这样还能返回用户信息
命令如下
1
2
3
4
5
6
7
8
9
10
11
|
curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "user.login" , "params" : { "user" : "Admin" , "password" : "zabbix" , "userData" : true }, "id" : 1 }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool |
执行如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' > { > "jsonrpc" : "2.0" , > "method" : "user.login" , > "params" : { > "user" : "Admin" , > "password" : "zabbix" , > "userData" : true > }, > "id" : 1 > }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool { "id" : 1, "jsonrpc" : "2.0" , "result" : { "alias" : "Admin" , "attempt_clock" : "0" , "attempt_failed" : "0" , "attempt_ip" : "" , "autologin" : "1" , "autologout" : "0" , "debug_mode" : false , "gui_access" : "0" , "lang" : "en_GB" , "name" : "Zabbix" , "refresh" : "30" , "rows_per_page" : "50" , "sessionid" : "dbfdc9c932d15760f0ed05bb5955511b" , "surname" : "Administrator" , "theme" : "default" , "type" : "3" , "url" : "" , "userid" : "1" , "userip" : "10.0.1.162" } } [root@linux-node2 ~] # |
https://www.zabbix.com/documentation/2.4/manual/api/reference/user/get
找一个简单的,只获取hostid,注意auth是sessionid
1
2
3
4
5
6
7
8
9
10
|
curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "host.get" , "params" : { "output" : [ "hostid" ] }, "auth" : "dbfdc9c932d15760f0ed05bb5955511b" , "id" : 2 } ' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool |
执行结果如下,hostid是10084
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' > { > "jsonrpc" : "2.0" , > "method" : "host.get" , > "params" : { > "output" : [ "hostid" ] > }, > "auth" : "dbfdc9c932d15760f0ed05bb5955511b" , > "id" : 2 > } ' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool { "id" : 2, "jsonrpc" : "2.0" , "result" : [ { "hostid" : "10084" } ] } [root@linux-node2 ~] # |
hostid就是下面这里的
1
2
3
4
5
6
7
8
9
10
|
curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "host.get" , "params" : { "output" : [ "host" ] }, "auth" : "dbfdc9c932d15760f0ed05bb5955511b" , "id" : 2 } ' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool |
执行结果如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' > { > "jsonrpc" : "2.0" , > "method" : "host.get" , > "params" : { > "output" : [ "host" ] > }, > "auth" : "dbfdc9c932d15760f0ed05bb5955511b" , > "id" : 2 > } ' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool { "id" : 2, "jsonrpc" : "2.0" , "result" : [ { "host" : "Zabbix server" , "hostid" : "10084" } ] } [root@linux-node2 ~] # |
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170317155809682-647057229.png)
接下来使用api方式添加被监控主机
https://www.zabbix.com/documentation/2.4/manual/api/reference/host/create
创建的时候可以指定模板,以及主机组
在官网里看到实例如下,添加主机的时候可以指定模板,主机组,资产
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
{ "jsonrpc" : "2.0" , "method" : "host.create" , "params" : { "host" : "Linux server" , "interfaces" : [ { "type" : 1, "main" : 1, "useip" : 1, "ip" : "192.168.3.1" , "dns" : "" , "port" : "10050" } ], "groups" : [ { "groupid" : "50" } ], "templates" : [ { "templateid" : "20045" } ], "inventory_mode" : 0, "inventory" : { "macaddress_a" : "01234" , "macaddress_b" : "56768" } }, "auth" : "038e1d7b1735c6a5436ee9eae095879e" , "id" : 1 } |
查看linux servers这个主机组,它的组id是2
![](https://images2015.cnblogs.com/blog/1076878/201703/1076878-20170318204107526-786969577.png)
先获取授权的sessionid
1
2
3
4
5
6
7
8
9
10
11
|
curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "user.login" , "params" : { "user" : "Admin" , "password" : "zabbix" }, "id" : 1 }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool |
根据返回的sessionid来创建主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "user.login" , "params" : { "user" : "Admin" , "password" : "zabbix" }, "id" : 1 }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool { "id" : 1, "jsonrpc" : "2.0" , "result" : "4c0999123f2da1b09b6a079c02a363ad" } [root@linux-node2 ~] # |
执行命令如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
curl -s -X POST -H 'Content-Type:application/json' -d ' { "jsonrpc" : "2.0" , "method" : "host.create" , "params" : { "host" : "Linux server" , "interfaces" : [ { "type" : 1, "main" : 1, "useip" : 1, "ip" : "10.0.1.162" , "dns" : "" , "port" : "10050" } ], "groups" : [ { "groupid" : "2" } ], "templates" : [ { "templateid" : "10001" } ] }, "id" : 1, "auth" : "4c0999123f2da1b09b6a079c02a363ad" }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool |
执行结果如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
[root@linux-node2 ~] # curl -s -X POST -H 'Content-Type:application/json' -d ' > { > "jsonrpc" : "2.0" , > "method" : "host.create" , > "params" : { > "host" : "Linux server" , > "interfaces" : [ > { > "type" : 1, > "main" : 1, > "useip" : 1, > "ip" : "10.0.1.162" , > "dns" : "" , > "port" : "10050" > } > ], > "groups" : [ > { > "groupid" : "2" > } > ], > "templates" : [ > { > "templateid" : "10001" > } > ] > }, > "id" : 1, > "auth" : "4c0999123f2da1b09b6a079c02a363ad" > }' http: //10 .0.1.161 /zabbix/api_jsonrpc .php |python -mjson.tool { "id" : 1, "jsonrpc" : "2.0" , "result" : { "hostids" : [ "10116" ] } } [root@linux-node2 ~] # |
创建成功
点开看看
模板也自动加上了