zabbix_proxy离线安装超详细
zabbix_proxy使用
背景
阿里云的网络有俩种网络架构,经典网络和专有网络(vpc)我们的监控机zabbix是在VPC内网的,如果对经典网络(公网)进行监控呢?
可能方法有很多,但是我使用了zabbix的proxy主动模式,这种场景正符合分布式监控:)
拓扑图
关于proxy的使用场景
zabbix的proxy主动模式proxy 可以用在 Proxy 没有公网 IP ,但可以访问公网的情况下Zabbix Server <- Zabbix Proxy -> Zabbix Agent
Proxy 去请求 Zabbix Server,由于 Zabbix Agent 用的是被动模式,所以也是由 Zabbix Proxy 去请求 Zabbix Agent
• 监控远程区域设备
• 监控本地网络不稳定区域
• 当 zabbix 监控上千设备时,使用它来减轻 server 的压力
• 简化分布式监控的维护
zabbix proxy 仅仅需要一条 tcp 连接到 zabbix server
zabbix proxy 是一个数据收集器,它不计算触发器、不处理事件、不发送报警
官网参考
系统环境:
CentOS Linux release 7.6.1810 (Core)
ip:192.168.21.10 zabbix-proxy地址
192.168.21.11 zabbix-agent地址
192.168.2.15 zabbix-server地址
proxy安装
wget https://repo.zabbix.com/zabbix/5.2/rhel/7/x86_64/zabbix-proxy-mysql-5.2.6-1.el7.x86_64.rpm
2. 安装proxy
[root@localhost tools]# pwd /home/tools [root@localhost tools]# ls zabbix-proxy-mysql-5.2.6-1.el7.x86_64.rpm [root@localhost ~]# rpm -Uvh zabbix-proxy-mysql-5.2.6-1.el7.x86_64.rpm --nodeps warning: zabbix-proxy-mysql-5.2.6-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Preparing... ################################# [100%] Updating / installing... 1:zabbix-proxy-mysql-5.2.6-1.el7 ################################# [100%]
离线下载地址:
链接:https://pan.baidu.com/s/1VSV-T78EVeYNSO3QdK93fw
提取码:klma
需要上传到服务器
[root@localhost tools]# rpm -Uvh mariadb-server/*.rpm --nodeps warning: mariadb-server/mariadb-5.5.68-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:perl-Data-Dumper-2.145-3.el7 ################################# [ 10%] 2:perl-Net-Daemon-0.48-5.el7 ################################# [ 20%] 3:perl-Compress-Raw-Zlib-1:2.061-4.################################# [ 30%] 4:perl-Compress-Raw-Bzip2-2.061-3.e################################# [ 40%] 5:perl-IO-Compress-2.061-2.el7 ################################# [ 50%] 6:perl-PlRPC-0.2020-14.el7 ################################# [ 60%] 7:perl-DBI-1.627-4.el7 ################################# [ 70%] 8:perl-DBD-MySQL-4.023-6.el7 ################################# [ 80%] 9:mariadb-1:5.5.68-1.el7 ################################# [ 90%] 10:mariadb-server-1:5.5.68-1.el7 ################################# [100%]
[root@localhost tools]# systemctl start mariadb [root@localhost tools]# systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2022-09-01 11:43:47 CST; 4s ago Process: 31107 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 31022 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 31106 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─31106 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─31270 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin... Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: MySQL manual for m... Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: Please report any ... Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: The latest informa... Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: You can find addit... Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: http://dev.mysql.com Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: Consider joining M... Sep 01 11:43:45 localhost.localdomain mariadb-prepare-db-dir[31022]: https://mariadb.or... Sep 01 11:43:45 localhost.localdomain mysqld_safe[31106]: 220901 11:43:45 mysqld_safe .... Sep 01 11:43:45 localhost.localdomain mysqld_safe[31106]: 220901 11:43:45 mysqld_safe ...l Sep 01 11:43:47 localhost.localdomain systemd[1]: Started MariaDB database server. Hint: Some lines were ellipsized, use -l to show in full. [root@localhost tools]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.68-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> create database zabbix_proxy character set utf8; # 创建数据库 Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on zabbix_proxy.* to zabbix@'%' identified by 'Zabbix@123'; # 创建用户 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> grant all on zabbix_proxy.* to zabbix@'localhost' identified by 'Zabbix@123'; # 创建用户 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> set password=password('Zabbix@123'); # 设置root密码 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; # 刷新 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit # 退出 Bye
6.导入刷库,无报错代表成功
[root@localhost tools]# zcat /usr/share/doc/zabbix-proxy-mysql-5.2.6/schema.sql.gz | mysql -u zabbix -p'Zabbix@123' zabbix_proxy [root@localhost tools]#
proxy配置
[root@localhost tools]# vi /etc/zabbix/zabbix_proxy.conf 主要修改以下配置 Server=192.168.2.15 #server的通信IP ServerPort=10051 #server的端口 Hostname=proxy_fangshan #proxy代理标识 DBPassword=Zabbix@123 #数据库密码 ConfigFrequency=60 #多久从zabbix-server接受配置 DataSenderFrequency=60 #多久向zabbix-server发送收集数据
Timeout=10 #等待agent回应超时时间,默认4s
ProxyMode=0 //默认主动模式0,被动模式1
DBHost=127.0.0.1 //数据库地址
DBName=zabbix_proxy #数据库名称
DBUser=zabbix #数据库用户
DBPort=3306 #数据库端口
DBSocket=/var/lib/mysql/mysql.sock #数据库sock
LogFileSize=0 //不切割日志,默认1M
[root@localhost tools]# setenforce 0 注:启动失败,没有日志的话参考下面操作 [root@localhost tools]# /usr/sbin/zabbix_proxy #报错没有libodbc.so.2 ./zabbix_proxy: error while loading shared libraries: libodbc.so.2: cannot open shared object file: No such file or directory [root@localhost tools]# echo /usr/lib64 > /etc/ld.so.conf.d/usr-libs.conf
#将libodbc下的链接库上传到/usr/lib64目录下
动态库下载地址:链接:https://pan.baidu.com/s/1ORi9BtmY7WsE_grFcZySZg
提取码:klzc
[root@localhost tools]# ll libodbc/ total 2744
-rw-r--r-- 1 yunwei root 297792 Sep 16 11:22 libevent-2.0.so.5
-rw-r--r-- 1 yunwei root 41272 Sep 16 11:22 libltdl.so.7
-rw-r--r-- 1 yunwei root 845760 Sep 16 11:22 libnetsnmp.so.31
-rw-r--r-- 1 yunwei root 429728 Sep 16 11:22 libodbc.so.2
-rw-r--r-- 1 yunwei root 32936 Sep 16 11:22 libOpenIPMIposix.so.0
-rw-r--r-- 1 yunwei root 1102048 Sep 16 11:22 libOpenIPMI.so.0
-rw-r--r-- 1 yunwei root 41000 Sep 16 11:22 libOpenIPMIutils.so.0
[root@localhost tools]# cp libodbc/* /usr/lib64/ #链接库放到指定位置
[root@localhost tools]# ldconfig #刷新 [root@localhost tools]# systemctl restart zabbix-proxy.service [root@localhost tools]# systemctl status zabbix-proxy.service ● zabbix-proxy.service - Zabbix Proxy Loaded: loaded (/usr/lib/systemd/system/zabbix-proxy.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2022-09-01 14:12:12 CST; 8s ago Process: 40286 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=0/SUCCESS) Process: 40290 ExecStart=/usr/sbin/zabbix_proxy -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 40292 (zabbix_proxy) CGroup: /system.slice/zabbix-proxy.service └─40292 /usr/sbin/zabbix_proxy -c /etc/zabbix/zabbix_proxy.conf Sep 01 14:12:12 localhost.localdomain systemd[1]: Starting Zabbix Proxy... Sep 01 14:12:12 localhost.localdomain systemd[1]: zabbix-proxy.service: Supervising pr.... Sep 01 14:12:12 localhost.localdomain systemd[1]: Started Zabbix Proxy. Hint: Some lines were ellipsized, use -l to show in full. [root@localhost tools]# systemctl enable zabbix-proxy.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-proxy.service to /usr/lib/systemd/system/zabbix-proxy.service.
新建代理
在我们的zabbix界面上点击管理--agent代理程序--创建代理agent代理程序名称 为 zabbix_proxy的主机名 (建议一致 )
更新完成
agent安装配置
下载地址:链接:https://pan.baidu.com/s/18uBFGEy4zK-StdMCepyvNA
提取码:agen
vi /etc/zabbix_agentd.conf 配置文件用以下内容即可 StartAgents=0 #开启主动模式 ServerActive=192.168.21.10 #指定proxy通信地址 Hostname=fangshan192.168.21.11 #agent标识 Timeout=30 #数据超时时间 [root@localhost ~]# systemctl restart zabbix-agent [root@localhost ~]# systemctl status zabbix-agent ● zabbix-agent.service - Zabbix Monitor Agent Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2022-09-01 14:33:16 CST; 5s ago Main PID: 55308 (zabbix_agentd) CGroup: /system.slice/zabbix-agent.service ├─55308 /usr/sbin/zabbix_agentd -f ├─55309 /usr/sbin/zabbix_agentd: collector [idle 1 sec] └─55310 /usr/sbin/zabbix_agentd: active checks #1 [getting list of active ch... Sep 01 14:33:16 localhost.localdomain systemd[1]: Started Zabbix Monitor Agent. Sep 01 14:33:16 localhost.localdomain zabbix_agentd[55308]: Starting Zabbix Agent [fang... Sep 01 14:33:16 localhost.localdomain zabbix_agentd[55308]: Press Ctrl+C to exit. Hint: Some lines were ellipsized, use -l to show in full. [root@localhost ~]# systemctl enable zabbix-agent
添加主机
只需要填写以下
• 主机名称 为 agent的hostname
• 在...群组里
• IP地址 为 agent的内网IP
• 由agent代理程序监测 下拉 选择我们刚创建的代理名称 (敲黑板)
• 模板 添加你需要的模板
再次查看agent代理程序
查看当前被监控机数据