Zabbix学习(1)-监控服务与Zabbix介绍
Zabbix学习(2)-Zabbix安装和基础使用
Zabbix学习(3)-Zabbix监控入门
分布式监控文档
Zabbix 通过 Zabbix proxies 为 IT 基础设施提供有效和可用的分布式监控。代理(proxies)可用于代替 Zabbix server 本地收集数据,然后将数据报告给服务器。
zabbix 作为一个分布式监控系统(分布式监控解决方案),支持通过代理(proxy)收集zabbix agent 的监控数据然后由 zabbix proxy 再把数据发送给 zabbix server,也就是 zabbix proxy 可以代替 zabbix server 收集监控数据,然后把数据汇报给zabbix server,所以 zabbix proxy 可以在一定程度上分担了 zabbix server 的数据收集压力,从而降低了数据的采集时间、也相应的增加了 zabbix server 的监控能力。另外 zabbix proxy 也区分主动模式和被动模式,通信方式与 zabbix server主动模式和被动模式一样,区别是 zabbix proxy 由于没有 zabbix agent 的配置,所以 zabbix proxy 在主动模式下要周期性的向 zabbix server 申请获取 zabbix agent的监控项信息,zabbix proxy 在被动模式下也是等待 zabbix server 的连接并接受 zabbix server 发送的监控项指令,然后再由 zabbix proxy 向 zabbix agent发起请求获取数据。
zabbix proxy MYSQL用于临时存储收集的信息资源数据
对比表格:
功能\server | zabbxy proxy | zabbix server |
---|---|---|
轻量级 | 是 | 相对重量级 |
图形 | 无 | 带图形控制界面 |
独立工作 | 是,可以独立采集数据并存储 | 是,即数据采集、存储、分析、展示于一体 |
易维护 | 是,配置完成后基本无需管理 | 维护也不难 |
独立数据库 | 保留少量最近数据 | 保留指定时间内的所有数据 |
报警通知 | 否,代理服务器不发送邮件通知 | 支持邮件、短信等告警机制 |
本地管理 | 不支持 | 支持 |
在使用 proxy 做分布式监控时 zabbix proxy 的大版本必须要和 zabbix server版本一致,否则会导致出现 zabbix server 与 zabbix proxy 不兼容问题,出现类似以下的错误提示:
proxy "zabbix-proxy-active" protocol version x.x differs from server version x.x
官方安装参考手册
ubuntu18.04系统
主机准备:
主机类型 | IP地址 |
---|---|
zabbix-server | 172.20.32.101 |
zabbix-proxy-1(主动) | 172.20.32.102 |
zabbix-proxy-2(被动) | 172.20.32.103 |
zabbix-Mysql-master | 172.20.32.104 |
zabbix-Mysql-slave | 172.20.32.105 |
zabbix-WEB-1 | 172.20.32.106 |
zabbix-WEB-2 | 172.20.32.107 |
这里有两种方式安装对应的应用,这里在主动模式下用apt安装 在被动模式下用编译安装
root@Zabbix-proxy-active:~# wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-3+bionic_all.deb
root@Zabbix-proxy-active:~# dpkg -i zabbix-release_4.0-3+bionic_all.deb
root@Zabbix-proxy-active:~# apt update
上面的源在国外,可能比较慢,所以可以替换成阿里云的源
阿里开源参考
阿里云镜像源
root@Zabbix-proxy-active:~# vim /etc/apt/sources.list.d/zabbix.list
#deb http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main
#deb-src http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main
deb http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic main
deb-src http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic main
root@Zabbix-proxy-active:~# apt update
Get:1 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic InRelease [7,096 B]
Get:2 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main Sources [1,182 B]
Get:3 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main amd64 Packages [2,683 B]
Get:4 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main i386 Packages [2,684 B]
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:6 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:7 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:8 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 13.6 kB in 2s (6,013 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
251 packages can be upgraded. Run 'apt list --upgradable' to see them.
可以看到上面的链接是到了阿里云上面
查看并且安装proxy-mysql
root@Zabbix-proxy-active:~# apt-cache madison zabbix-proxy-mysql
zabbix-proxy-mysql | 1:4.0.20-1+bionic | http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main amd64 Packages
zabbix-proxy-mysql | 1:3.0.12+dfsg-1 | http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
zabbix | 1:4.0.20-1+bionic | http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main Sources
root@Zabbix-proxy-active:~# apt install zabbix-proxy-mysql -y
Host | 172.20.32.102 | 172.20.32.102 |
---|---|---|
数据库名 | zabbix_proxy_active | zabbix_proxy_passive |
用户名 | proxy | kaivi |
密码名 | 123456 | 123456 |
数据库主机172.20.32.104
这里创建对应的主动和被动代理的数据库名称以及用户和密码。
root@Mysql-master:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 789
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, 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_active CHARACTER SET UTF8 COLLATE UTF8_BIN;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON zabbix_proxy_active.* TO proxy@'172.20.32.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> CREATE DATABASE zabbix_proxy_passive CHARACTER SET UTF8 COLLATE UTF8_BIN;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON zabbix_proxy_passive.* TO kaivi@'172.20.32.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
编译安装 zabbix proxy 时直接使用 zabbix 的源码包,通过指定编译参数来编译 proxy。
root@Zabbix-proxy-passive:~# cd /usr/local/src/
root@Zabbix-proxy-passive:/usr/local/src# rz -E
rz waiting to receive.
root@Zabbix-proxy-passive:/usr/local/src# ll
total 16820
drwxr-xr-x 2 root root 4096 Apr 30 23:25 ./
drwxr-xr-x 10 root root 4096 Oct 26 2019 ../
-rw-r--r-- 1 root root 17215217 Apr 29 13:41 zabbix-4.0.20.tar.gz
root@Zabbix-proxy-passive:/usr/local/src# tar xf zabbix-4.0.20.tar.gz
root@Zabbix-proxy-passive:/usr/local/src# cd zabbix-4.0.20/
#解决数据库依赖关系
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# apt install libmysqld-dev libmysqlclient-dev libxml2-dev libxml2 snmp libsnmp-dev libevent-dev curl libcurl4-openssl-dev -y
#编译安装
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# ./configure --prefix=/apps/zabbix_proxy --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
......
checking for pthread.h... (cached) yes
checking for process shared libpthread support... yes
checking for javac... no
configure: error: Unable to find "javac" executable in path
#因为--enable-java参数所以需要解决Java依赖
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# apt install openjdk-8-jdk -y
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# ./configure --prefix=/apps/zabbix_proxy --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# make install
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# ll /apps/zabbix_proxy/
total 28
drwxr-xr-x 7 root root 4096 May 1 01:04 ./
drwxr-xr-x 3 root root 4096 May 1 01:04 ../
drwxr-xr-x 2 root root 4096 May 1 01:04 bin/
drwxr-xr-x 4 root root 4096 May 1 01:04 etc/
drwxr-xr-x 3 root root 4096 May 1 01:04 lib/
drwxr-xr-x 3 root root 4096 May 1 01:04 sbin/
drwxr-xr-x 4 root root 4096 May 1 01:04 share/
在机器172.20.32.103中测试是否可以连到远程数据库
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# mysql -ukaivi -p123456 -h172.20.32.104
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 897
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, 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 |
| zabbix_proxy_passive |
+----------------------+
2 rows in set (0.00 sec)
mysql>
导入数据
这里只需要导入数据schema.sql 即可
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# pwd
/usr/local/src/zabbix-4.0.20
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# mysql -ukaivi -p123456 -h172.20.32.104 zabbix_proxy_passive < database/mysql/schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20#
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# mysql -ukaivi -p123456 -h172.20.32.104 zabbix_proxy_passive
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 937
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, 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 tables;
+--------------------------------+
| Tables_in_zabbix_proxy_passive |
+--------------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
......
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+--------------------------------+
144 rows in set (0.00 sec)
主动模式是用apt安装的proxy。把主动模式下的启动文件拷贝到被动模式下
root@Zabbix-proxy-active:~# ll /lib/systemd/system/zabbix-proxy.service
-rw-r--r-- 1 root root 491 Dec 18 18:46 /lib/systemd/system/zabbix-proxy.service
root@Zabbix-proxy-active:~# scp /lib/systemd/system/zabbix-proxy.service 172.20.32.103:/lib/systemd/system/zabbix-proxy.service
The authenticity of host '172.20.32.103 (172.20.32.103)' can't be established.
ECDSA key fingerprint is SHA256:0ze4VLdSnOsoO+pl/Hj+Ln8kc5lPyF1En6W6MEV22jM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.32.103' (ECDSA) to the list of known hosts.
[email protected]'s password:
zabbix-proxy.service 100% 491 762.0KB/s 00:00
root@Zabbix-proxy-active:~#
#编辑启动文件
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# vim /lib/systemd/system/zabbix-proxy.service
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# cat /lib/systemd/system/zabbix-proxy.service
[Unit]
Description=Zabbix Proxy
After=syslog.target
After=network.target
#After=mysql.service
#After=mysqld.service
#After=mariadb.service
[Service]
Environment="CONFFILE=/apps/zabbix_proxy/etc/zabbix_proxy.conf"
EnvironmentFile=-/etc/default/zabbix-proxy
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_proxy.pid
KillMode=control-group
ExecStart=/apps/zabbix_proxy/sbin/zabbix_proxy -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# useradd zabbix
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# chown zabbix.zabbix /apps/zabbix_proxy/ -R
配置并使用被动模式(Passive Proxy Mode)的 zabbix proxy 收集 zabbix agent 监控数据。
zabbix server : 172.20.32.101
zabbix proxy passive : 172.20.32.103
web server : 172.20.32.104
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# vim /apps/zabbix_proxy/etc/zabbix_proxy.conf
# 注意,配置文件的选项后接注释会报错,注释从头开始
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# grep "^[a-Z]" /apps/zabbix_proxy/etc/zabbix_proxy.conf
ProxyMode=1 # 0为主动,1为被动
Server=172.20.32.101 # zabbix server服务器的地址或主机名
Hostname=kaivi-zabbix-proxy-passive # 代理服务器名称,需要与zabbix server添加代理时候的 proxy name是一致的!
ListenPort=10051 # zabbix proxy监听端口
LogFile=/tmp/zabbix_proxy.log
EnableRemoteCommands=1 # 允许zabbix server执行远程命令
PidFile=/tmp/zabbix_proxy.pid
DBHost=172.20.32.104
DBName=zabbix_proxy_passive
DBUser=kaivi
DBPassword=123456
DBPort=3306
ProxyLocalBuffer=720 # 已经提交到zabbix server的数据保留时间
ProxyOfflineBuffer=720 # 未提交到zabbix server的时间保留时间
ConfigFrequency=5 # 一般设置较长,此处5秒是为了看效果 一般300s
StartPollers=10 # 启动的数据采集器数量
JavaGateway=172.20.32.102 # java gateway服务器地址,当需要监控java的时候必须配置否则监控不到数据
JavaGatewayPort=10052
StartJavaPollers=10
CacheSize=16M # 保存监控项而占用的最大内存
HistoryCacheSize=128M # 保存监控历史数据占用的最大内存
HistoryIndexCacheSize=16M # 历史索引缓存的大小
Timeout=30 # 监控项超时时间,单位为秒
LogSlowQueries=3000 # 毫秒,多久的数据库查询会被记录到日志
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl status zabbix-proxy
● zabbix-proxy.service - Zabbix Proxy
Loaded: loaded (/lib/systemd/system/zabbix-proxy.service; disabled; vendor preset: enabled)
Active: inactive (dead)
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl daemon-reload
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl start zabbix-proxy
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl enable zabbix-proxy
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-proxy.service → /lib/systemd/system/zabbix-proxy.service.
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl status zabbix-proxy
● zabbix-proxy.service - Zabbix Proxy
Loaded: loaded (/lib/systemd/system/zabbix-proxy.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-05-01 02:12:23 CST; 15s ago
Main PID: 34160 (zabbix_proxy)
Tasks: 37 (limit: 2216)
CGroup: /system.slice/zabbix-proxy.service
.......
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# tail /tmp/zabbix_proxy.log
34104:20200501:020939.688 proxy #30 started [poller #6]
34100:20200501:020939.688 proxy #26 started [poller #2]
34103:20200501:020939.689 proxy #29 started [poller #5]
34106:20200501:020939.690 proxy #32 started [poller #8]
34102:20200501:020939.692 proxy #28 started [poller #4]
34107:20200501:020939.693 proxy #33 started [poller #9]
34101:20200501:020939.694 proxy #27 started [poller #3]
34108:20200501:020939.697 proxy #34 started [poller #10]
34109:20200501:020939.699 proxy #35 started [unreachable poller #1]
34110:20200501:020939.700 proxy #36 started [icmp pinger #1]
配置之文件中DBName=zabbix_proxy_passive,最好保持一致
这里为了效果明显,复用数据库的172.20.32.104的数据库服务器添加一个agent代理服务器
在172.20.32.104机器
#从172.20.32.102拷贝deb包到172.20.32.104
root@Zabbix-proxy-active:~# scp zabbix-release_4.0-3+bionic_all.deb 172.20.32.104:/root
The authenticity of host '172.20.32.104 (172.20.32.104)' can't be established.
ECDSA key fingerprint is SHA256:0ze4VLdSnOsoO+pl/Hj+Ln8kc5lPyF1En6W6MEV22jM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.32.104' (ECDSA) to the list of known hosts.
[email protected]'s password:
zabbix-release_4.0-3+bionic_all.deb
#安装
root@Mysql-master:~# dpkg -i zabbix-release_4.0-3+bionic_all.deb
root@Mysql-master:~# apt update
root@Mysql-master:~# apt install zabbix-agent -y
#修改配置文件
root@Mysql-master:~# vim /etc/zabbix/zabbix_agentd.conf
root@Mysql-master:~# cat /etc/zabbix/zabbix_agentd.conf|grep ^[a-Z]
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.20.32.103,172.20.32.101 #指向proxy以及server用于探测是否存活
ListenPort=10050
ListenIP=0.0.0.0
StartAgents=5
ServerActive=127.0.0.1
Hostname=172.20.32.104
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#启动
root@Mysql-master:~# systemctl restart zabbix-agent
root@Mysql-master:~# systemctl enable zabbix-agent
Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
等几分钟,就可以看到变绿了:
这里可以通过自带的测试命名测试是否能够获取到数据:
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.104 -p10050 -k "system.cpu.load[all,avg1]"
0.020000
配置并使用主动模式(Active Proxy Mode)的 zabbix proxy 收集 zabbix agent 监控数据
zabbix server : 172.20.32.101
zabbix proxy active : 172.20.32.102
web server : 172.20.32.105
root@Zabbix-proxy-active:~# /etc/zabbix/zabbix_proxy.conf
root@Zabbix-proxy-active:~# grep "^[a-Z]" /etc/zabbix/zabbix_proxy.conf
ProxyMode=0
Server=172.20.32.101
ServerPort=10051
Hostname=duanxin-zabbix-proxy-active
ListenPort=10051
LogFile=/tmp/zabbix_proxy.log
LogFileSize=0
EnableRemoteCommands=1
PidFile=/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=172.20.32.104
DBName=zabbix_proxy_active
DBUser=proxy
DBPassword=123456
DBPort=3306
ProxyLocalBuffer=720
ProxyOfflineBuffer=720
HeartbeatFrequency=30
ConfigFrequency=5
StartPollers=10
JavaGateway=172.20.32.102
JavaGatewayPort=10052
StartJavaPollers=10
CacheSize=16M
HistoryCacheSize=128M
HistoryIndexCacheSize=16M
Timeout=30
LogSlowQueries=3000
在机器172.20.32.103中测试是否能够正常连接数据库
root@Zabbix-proxy-active:~# mysql -uproxy -p123456 -h172.20.32.104
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 113
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
这里的数据库的路径以及对应的schema.sql文件和编译安装的都不一致,但是可以通过zcat和管道符的方法读到数据库中
root@Zabbix-proxy-active:~# cd /usr/share/doc/zabbix-proxy-mysql/
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# ll
total 48
drwxr-xr-x 2 root root 4096 Apr 30 23:58 ./
drwxr-xr-x 546 root root 20480 Apr 30 23:58 ../
-rw-r--r-- 1 root root 2460 Apr 27 15:00 changelog.Debian.gz
-rw-r--r-- 1 root root 980 Nov 21 20:16 copyright
-rw-r--r-- 1 root root 12946 Apr 27 15:00 schema.sql.gz
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# zcat schema.sql.gz | mysql -uproxy -p123456 -h172.20.32.104 zabbix_proxy_active
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# mysql -uproxy -p123456 -h172.20.32.104 zabbix_proxy_active
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 122
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [zabbix_proxy_active]>
MySQL [zabbix_proxy_active]> show tables;
+-------------------------------+
| Tables_in_zabbix_proxy_active |
+-------------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
......
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+-------------------------------+
144 rows in set (0.00 sec)
MySQL [zabbix_proxy_active]>
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# cd
root@Zabbix-proxy-active:~# systemctl restart zabbix-proxy
root@Zabbix-proxy-active:~# systemctl enable zabbix-proxy
Synchronizing state of zabbix-proxy.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-proxy
root@Zabbix-proxy-active:~# tail -f /tmp/zabbix_proxy.log #查看日志看是否报错
这里为了效果明显,复用数据库从库的172.20.32.105的slave数据库服务器添加一个agent代理服务器
在172.20.32.105机器
#从172.20.32.102拷贝deb包到172.20.32.105
root@Zabbix-proxy-active:~# scp zabbix-release_4.0-3+bionic_all.deb 172.20.32.105:/root
The authenticity of host '172.20.32.105 (172.20.32.105)' can't be established.
ECDSA key fingerprint is SHA256:0ze4VLdSnOsoO+pl/Hj+Ln8kc5lPyF1En6W6MEV22jM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.32.105' (ECDSA) to the list of known hosts.
[email protected]'s password:
zabbix-release_4.0-3+bionic_all.deb
#安装
root@Mysql-slave:~# dpkg -i zabbix-release_4.0-3+bionic_all.deb
root@Mysql-slave:~# apt update
root@Mysql-slave:~# apt install zabbix-agent -y
#修改配置文件
root@Mysql-slave:~# vim /etc/zabbix/zabbix_agentd.conf
root@Mysql-slave:~# cat /etc/zabbix/zabbix_agentd.conf|grep ^[a-Z]
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.20.32.102,172.20.32.101 #指向proxy以及server用于探测是否存活
ListenPort=10050
ListenIP=0.0.0.0
StartAgents=5
ServerActive=172.20.32.102 #配置主动模式代理服务器
Hostname=172.20.32.105
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#重新启动
root@Mysql-slave:~# systemctl restart zabbix-agent
root@Mysql-slave:~# systemctl enable zabbix-agent
Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "system.cpu.load[all,avg1]"
0.000000
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.104 -p10050 -k "agent.ping"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "agent.ping"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.106 -p10050 -k "agent.ping"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.107 -p10050 -k "agent.ping"
1
主机duanxin-zabbix-proxy-active: 172.20.32.105-mysql-slave 主动模式下配置java-getewat代理
先要要web主机 172.20.32.105部署Java环境,这里就直接apt安装jdk
root@Mysql-slave:/apps# apt install openjdk-8-jdk -y
#部署tomcat,这里上传到/usr/local/src
# tar xf apache-tomcat-8.5.54.tar.gz
# ln -sv /usr/local/src/apache-tomcat-8.5.54 /apps/tomcat
root@Mysql-slave:/apps# cd /apps/
root@Mysql-slave:/apps# mkdir tomcat/webapps/myapp -p
root@Mysql-slave:/apps# vim tomcat/webapps/myapp/index.html
root@Mysql-slave:/apps# cat tomcat/webapps/myapp/index.html
mysql slave jsp for tomcat test
root@Mysql-slave:/apps# vim tomcat/bin/catalina.sh
......
117
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=172.20.32.105"
......
#重启tomcat
root@Mysql-slave:/apps# tomcat/bin/catalina.sh stop
root@Mysql-slave:/apps# tomcat/bin/catalina.sh start
root@Mysql-slave:/apps# ss -ntl|grep 12345
LISTEN 0 50 *:12345 *:*
root@Zabbix-proxy-active:~# vim /etc/zabbix/zabbix_proxy.conf
......
317
### Option: JavaGateway
# IP address (or hostname) of Zabbix Java gateway.
# Only required if Java pollers are started.
#
# Mandatory: no
# Default:
JavaGateway=172.20.32.102
### Option: JavaGatewayPort
# Port that Zabbix Java gateway listens on.
#
# Mandatory: no
# Range: 1024-32767
# Default:
JavaGatewayPort=10052
### Option: StartJavaPollers
# Number of pre-forked instances of Java pollers.
#
# Mandatory: no
# Range: 0-1000
# Default:
StartJavaPollers=10
......
root@Zabbix-proxy-active:~# systemctl restart zabbix-proxy
root@Zabbix-proxy-active:~# ss -ntl|grep 10052
LISTEN 0 50 *:10052 *:*
root@Zabbix-proxy-active:~# netstat -tanlp|grep 172.20.32.105
tcp 0 0 172.20.32.102:10051 172.20.32.105:37169 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37185 TIME_WAIT -
tcp 0 0 172.20.32.102:16913 172.20.32.105:10050 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37177 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37163 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37165 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37183 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37187 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37167 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37175 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37181 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37171 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37179 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37173 TIME_WAIT -
tcp6 0 0 172.20.32.102:39953 172.20.32.105:12345 ESTABLISHED 828/java
tcp6 0 0 172.20.32.102:48279 172.20.32.105:17694 ESTABLISHED 828/java
tcp6 0 0 172.20.32.102:48163 172.20.32.105:17694 TIME_WAIT -
tcp6 0 0 172.20.32.102:39715 172.20.32.105:12345 TIME_WAIT -
tcp6 0 0 172.20.32.102:48041 172.20.32.105:17694 TIME_WAIT -
tcp6 0 0 172.20.32.102:48165 172.20.32.105:17694 TIME_WAIT -
tcp6 0 0 172.20.32.102:39837 172.20.32.105:12345 TIME_WAIT -
root@Mysql-slave:~# netstat -tanlp|grep 172.20.32.102
tcp 0 0 172.20.32.105:10050 172.20.32.102:17839 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17871 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17903 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17887 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17855 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17741 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17783 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17891 TIME_WAIT -
tcp6 0 0 172.20.32.105:12345 172.20.32.102:40773 ESTABLISHED 12370/java
# 172.20.32.105:12345 端口连接
tcp6 0 0 172.20.32.105:17694 172.20.32.102:49099 ESTABLISHED 12370/java
......