QQ_1723279401909

应用场景

1
2
3
4
5
1.一台Server管理的agent过多
2.需要管理的agent在不同的国家或者地区,有网络波动
# 重新加载缓存
[root@zabbix5-server ~]# zabbix_server -R config_cache_reload

zabbix-proxy特征

proxy
轻量级(Lightweight) yes
图形界面(GUI) no
独立工作(Works independently) yes
易于维护(Easy maintenance) yes
自动生成数据库(Automatic DB creation)1 yes
本地管理(Local administration) no
准备嵌入式硬件 (Ready for embedded hardware) yes
单向TCP连接(One way TCP connections) yes
集中配置(Centralised configuration) yes
生成通知(Generates notifications) no

1.zabbix proxy 数据库必须和 server 分开,否则数据会被破坏。

2.从Zabbix server数据库直接更新最新配置的proxy可能会比Zabbix server新,而Zabbix server的 配置由于CacheUpdateFrequency 的原因而无法快速更新。因此,proxy收集发送Zabbix server数 据可能会被忽略。

zabbix proxy 是一个数据收集器,它不计算触发器、不处理事件、不发送报警。

有关proxy功能的概述, 如下表:

QQ_1723280852820

1
2
3
4
1.无法设置触发器
2.无法处理事件
3.无法发送告警
4.无法使用自愈模式

代理场景

QQ_1723280897596

部署zabbix-proxy

主机名 WanIP LanIP 角色 应用
Zabbix5-server 10.0.0.71 172.16.1.71 服务端 Zabbix-server、 Zabbix-agent
web01 10.0.0.7 172.16.1.7 zabbix5客户端 Zabbix-agent
web02 10.0.0.8 172.16.1.8 zabbix5客户端 Zabbix-agent
10.0.0.7,10.0.0.8 172.16.1.7,172.16.1.8 Zabbix客户端 收集 Java监控数据 Zabbix-java-gateway
zabbix_proxy73 10.0.0.73 172.16.1.73 代理web01 zabbix-proxy
zabbix_proxy74 10.0.0.74 172.16.1.74 代理web02 zabbix-proxy

下载链接:https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/

配置proxy73和web01

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
# 1.安装zabbix-proxy
[root@zabbix-proxy ~]# yum install -y https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-proxy-mysql-5.0.42-1.el7.x86_64.rpm

# 2.连接数据库 (zabbix -71执行 有数据库)
[root@zabbix5-server ~]# mysql
create database zabbix_proxy73 charset utf8;
create database zabbix_proxy74 charset utf8;

#3.导入数据
zcat /usr/share/doc/zabbix-proxy-mysql-5.0.42//schema.sql.gz |mysql -uzabbix -p123 -h172.16.1.71 zabbix_proxy73

zcat /usr/share/doc/zabbix-proxy-mysql-5.0.42//schema.sql.gz |mysql -uzabbix -p123 -h172.16.1.71 zabbix_proxy74

# 4.修改zabbix-proxy配置文件
[root@zabbix-proxy ~]# vim /etc/zabbix/zabbix_proxy.conf
Server=172.16.1.71
Hostname=zabbix_proxy73
DBHost=172.16.1.71
DBName=zabbix_proxy73
DBUser=zabbix
DBPassword=123



# 5.配置agent指向proxy
[root@web01 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=172.16.1.73
ServerActive=172.16.1.73
Hostname=web01

# 6.重启agent
[root@web01 ~]# systemctl restart zabbix-agent


#重启代理
#7.最后重启zabbix-proxy (如果最后数据没有显示,重启zabbix-proxy)
systemctl start zabbix-proxy
systemctl enable zabbix-proxy

#zabbix-proxy代理要在 zabbix服务端,客户端重启之后 最后重启

web界面操作

创建代理

QQ_1723338047556

QQ_1723338284210

停用自动注册动作,没有则忽略

QQ_1723338342003

QQ_1723338415805

QQ_1723338495182

回到主机,刷新

QQ_1723338515005

查看监控板里数据

QQ_1723338699914

调取zabbix的API

zabbix官方:API (zabbix.com)

1
准备Postman,注册登录后用于调取zabbix接口使用

使用curl调取接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
curl -X POST http://10.0.0.71/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1,
"auth": null
}'


#返回值,其中result值是token 每次token都不一样
{"jsonrpc":"2.0","result":"17d3a8bddc03d4f6cdc752527e91d03b","id":1}

使用postman调取接口

QQ_1723340719798

QQ_1723340820336

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
http://10.0.0.71/api_jsonrpc.php

{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1,
"auth": null
}


e4b67c3d6c13c9470c9ec56350552c2d


#获得token后,每次查询带上token即可

QQ_1723340900158

获得主机组ID

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
#在Postman里查询
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": "e4b67c3d6c13c9470c9ec56350552c2d"
}



#返回值
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10460",
"host": "web01",
"interfaces": [
{
"interfaceid": "22",
"ip": "172.16.1.7"
}
]
}
],
"id": 2
}

获取模板ID

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
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Template OS Linux by Zabbix agent"
]
}
},
"auth": "e4b67c3d6c13c9470c9ec56350552c2d",
"id": 1
}


##返回值
{
"jsonrpc": "2.0",
"result": [
{
"proxy_hostid": "0",
"host": "Template OS Linux by Zabbix agent",
"status": "3",
"disable_until": "0",
"error": "",
"available": "0",
"errors_from": "0",
"lastaccess": "0",
"ipmi_authtype": "-1",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"ipmi_disable_until": "0",
"ipmi_available": "0",
"snmp_disable_until": "0",
"snmp_available": "0",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"ipmi_errors_from": "0",
"snmp_errors_from": "0",
"ipmi_error": "",
"snmp_error": "",
"jmx_disable_until": "0",
"jmx_available": "0",
"jmx_errors_from": "0",
"jmx_error": "",
"name": "Template OS Linux by Zabbix agent",
"flags": "0",
"templateid": "10001",
"description": "Official Linux template. Requires agent of Zabbix 3.0.14, 3.4.5 and 4.0.0 or newer.\r\n\r\nKnown Issues:\r\n\r\n Description: Network discovery. Zabbix agent as of 4.2 doesn't support items such as net.if.status, net.if.speed.\r\n\r\nYou can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/387225-discussion-thread-for-official-zabbix-template-for-linux\r\n\r\nTemplate tooling version used: 0.39",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": "",
"proxy_address": "",
"auto_compress": "1"
}
],
"id": 1
}

添加主机

1
模板机ID,主机组ID(groupid)上面已获取
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
curl -X POST http://10.0.0.71/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "Linux server",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "10.0.0.9",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"tags": [
{
"tag": "Host name",
"value": "Linux server"
}
],
"templates": [
{
"templateid": "20045"
},
{
"templateid": "10001"
}
],
"macros": [
{
"macro": "{$USER_ID}",
"value": "123321"
},
{
"macro": "{$USER_LOCATION}",
"value": "0:0:0",
"description": "latitude, longitude and altitude coordinates"
}
],
"inventory_mode": 0,
"inventory": {
"macaddress_a": "01234",
"macaddress_b": "56768"
}
},
"auth": "e4b67c3d6c13c9470c9ec56350552c2d",
"id": 1
}'