zabbix 部署porxy
环境准备3台
①zabbix-server
②zabbix-proxy
③zabbix-agent
关闭防火墙,关闭zabbix的自动注册,自动发现
配置zabbix-proxy
安装zabbix的yum源
[root@localhost ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@localhost ~]# yum install zabbix-proxy-mysql zabbix-get -y
安装mariadb
[root@localhost ~]# yum install mariadb-server mariadb -y
已安装:
mariadb.x86_64 1:5.5.68-1.el7 mariadb-server.x86_64 1:5.5.68-1.el7
作为依赖被安装:
perl-DBD-MySQL.x86_64 0:4.023-6.el7
完毕!
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# netstat -tunlp
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:3306 0.0.0.0:* LISTEN 3442/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 722/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1476/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1088/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1092/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1328/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2571/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 722/rpcbind
tcp6 0 0 :::22 :::* LISTEN 1088/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1092/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1328/master
tcp6 0 0 ::1:6010 :::* LISTEN 2571/sshd: root@pts
udp 0 0 0.0.0.0:893 0.0.0.0:* 722/rpcbind
udp 0 0 192.168.122.1:53 0.0.0.0:* 1476/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1476/dnsmasq
udp 0 0 0.0.0.0:39524 0.0.0.0:* 800/avahi-daemon: r
udp 0 0 0.0.0.0:111 0.0.0.0:* 722/rpcbind
udp 0 0 0.0.0.0:5353 0.0.0.0:* 800/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 727/chronyd
udp6 0 0 :::893 :::* 722/rpcbind
udp6 0 0 :::111 :::* 722/rpcbind
udp6 0 0 ::1:323 :::* 727/chronyd
[root@localhost ~]#
数据库sql设置
[root@localhost ~]# mysql
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)]> create database zabbix_proxy character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix_proxy.* to zabbix@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges
-> ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@localhost ~]#
导入zabbix-proxy数据库信息
默认提供好了一个sql数据
[root@localhost ~]# rpm -ql zabbix-proxy-mysql
/etc/logrotate.d/zabbix-proxy
/etc/zabbix/zabbix_proxy.conf
/usr/lib/systemd/system/zabbix-proxy.service
/usr/lib/tmpfiles.d/zabbix-proxy.conf
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_proxy_mysql
/usr/share/doc/zabbix-proxy-mysql-5.0.19
/usr/share/doc/zabbix-proxy-mysql-5.0.19/AUTHORS
/usr/share/doc/zabbix-proxy-mysql-5.0.19/COPYING
/usr/share/doc/zabbix-proxy-mysql-5.0.19/ChangeLog
/usr/share/doc/zabbix-proxy-mysql-5.0.19/NEWS
/usr/share/doc/zabbix-proxy-mysql-5.0.19/README
/usr/share/doc/zabbix-proxy-mysql-5.0.19/schema.sql.gz
/usr/share/man/man8/zabbix_proxy.8.gz
/var/log/zabbix
/var/run/zabbix
[root@localhost ~]# ^C
#将压缩包导入zabbix_proxy里
[root@localhost ~]# zcat /usr/share/doc/zabbix-proxy-mysql-5.0.19/schema.sql.gz |mysql -uzabbix -pzabbix zabbix_proxy
#进入数据库
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix_proxy |
+--------------------+
5 rows in set (0.05 sec)
MariaDB [(none)]> use zabbix_proxy;
ERROR 1049 (42000): Unknown database 'zabbix_proxy;'
MariaDB [(none)]> use zabbix_proxy;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix_proxy]> show tables;
+----------------------------+
| Tables_in_zabbix_proxy |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| config_autoreg_tls |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| interface_snmp |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| item_rtdata |
| items |
| items_applications |
| lld_macro_path |
| lld_override |
| lld_override_condition |
| lld_override_opdiscover |
| lld_override_operation |
| lld_override_ophistory |
| lld_override_opinventory |
| lld_override_opperiod |
| lld_override_opseverity |
| lld_override_opstatus |
| lld_override_optag |
| lld_override_optemplate |
| lld_override_optrends |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| media_type_message |
| media_type_param |
| module |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_data |
| task_remote_command |
| task_remote_command_result |
| task_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
166 rows in set (0.00 sec)
MariaDB [zabbix_proxy]>
MariaDB [zabbix_proxy]> exit
Bye
修改zabbix_proxy配置文件,连接数据库的信息
[root@localhost ~]# sed -i.ori '162a DBPassword=zabbix' /etc/zabbix/zabbix_proxy.conf
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# sed -i 's#Server=127.0.0.1#Server=192.168.1.130#' /etc/zabbix/zabbix_proxy.conf
[root@localhost ~]#
[root@localhost ~]# sed -i 's#Hostname=Zabbix proxy#Hostname=zabbix pox-agent#' /etc/zabbix/zabbix_proxy.conf
[root@localhost ~]#
[root@localhost ~]# grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf
Server=192.168.1.130
Hostname=zabbix pox-agent
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBPassword=zabbix
DBName=zabbix_proxy
DBUser=zabbix
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
[root@localhost ~]#
启动代理服务
[root@localhost ~]# systemctl restart zabbix-proxy.service
[root@localhost ~]# 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 一 2022-01-10 15:40:20 CST; 15s ago
Process: 4051 ExecStart=/usr/sbin/zabbix_proxy -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 4053 (zabbix_proxy)
Tasks: 29
CGroup: /system.slice/zabbix-proxy.service
├─4053 /usr/sbin/zabbix_proxy -c /etc/zabbix/zabbix_proxy.conf
├─4066 /usr/sbin/zabbix_proxy: configuration syncer [synced config 0 bytes in 0.051088 sec, idle 3600 sec]
├─4068 /usr/sbin/zabbix_proxy: trapper #1 [processed data in 0.000000 sec, waiting for connection]
├─4069 /usr/sbin/zabbix_proxy: trapper #2 [processed data in 0.000000 sec, waiting for connection]
├─4070 /usr/sbin/zabbix_proxy: trapper #3 [processed data in 0.000000 sec, waiting for connection]
├─4071 /usr/sbin/zabbix_proxy: trapper #4 [processed data in 0.000000 sec, waiting for connection]
├─4073 /usr/sbin/zabbix_proxy: trapper #5 [processed data in 0.000000 sec, waiting for connection]
├─4078 /usr/sbin/zabbix_proxy: preprocessing manager #1 [queued 0, processed 0 values, idle 5.008972 sec during 5.009095 sec]
├─4079 /usr/sbin/zabbix_proxy: preprocessing worker #1 started
├─4080 /usr/sbin/zabbix_proxy: preprocessing worker #2 started
├─4081 /usr/sbin/zabbix_proxy: preprocessing worker #3 started
├─4082 /usr/sbin/zabbix_proxy: heartbeat sender [sending heartbeat message failed in 0.064828 sec, idle 60 sec]
├─4083 /usr/sbin/zabbix_proxy: data sender [sent 0 values in 0.004168 sec, idle 1 sec]
├─4084 /usr/sbin/zabbix_proxy: housekeeper [startup idle for 30 minutes]
├─4086 /usr/sbin/zabbix_proxy: http poller #1 [got 0 values in 0.001090 sec, idle 5 sec]
├─4088 /usr/sbin/zabbix_proxy: discoverer #1 [processed 0 rules in 0.124087 sec, idle 60 sec]
├─4090 /usr/sbin/zabbix_proxy: history syncer #1 [processed 0 values in 0.000066 sec, idle 1 sec]
├─4092 /usr/sbin/zabbix_proxy: history syncer #2 [processed 0 values in 0.000065 sec, idle 1 sec]
├─4093 /usr/sbin/zabbix_proxy: history syncer #3 [processed 0 values in 0.000174 sec, idle 1 sec]
├─4096 /usr/sbin/zabbix_proxy: history syncer #4 [processed 0 values in 0.000048 sec, idle 1 sec]
├─4098 /usr/sbin/zabbix_proxy: self-monitoring [processed data in 0.000045 sec, idle 1 sec]
├─4099 /usr/sbin/zabbix_proxy: task manager [processed 0 task(s) in 0.000601 sec, idle 5 sec]
├─4100 /usr/sbin/zabbix_proxy: poller #1 [got 0 values in 0.000064 sec, idle 5 sec]
├─4102 /usr/sbin/zabbix_proxy: poller #2 [got 0 values in 0.000065 sec, idle 5 sec]
├─4103 /usr/sbin/zabbix_proxy: poller #3 [got 0 values in 0.000024 sec, idle 5 sec]
├─4105 /usr/sbin/zabbix_proxy: poller #4 [got 0 values in 0.000032 sec, idle 5 sec]
├─4107 /usr/sbin/zabbix_proxy: poller #5 [got 0 values in 0.000039 sec, idle 5 sec]
├─4109 /usr/sbin/zabbix_proxy: unreachable poller #1 [got 0 values in 0.000035 sec, idle 5 sec]
└─4112 /usr/sbin/zabbix_proxy: icmp pinger #1 [got 0 values in 0.000015 sec, idle 5 sec]
1月 10 15:40:18 localhost.localdomain systemd[1]: Starting Zabbix Proxy...
1月 10 15:40:20 localhost.localdomain systemd[1]: zabbix-proxy.service: Supervising process 4053 which is not our child. We'll most likely not notice when it exits.
1月 10 15:40:20 localhost.localdomain systemd[1]: Started Zabbix Proxy.
[root@localhost ~]#
web页面添加代理
zabbix 服务端
追踪日志的报错
[root@localhost ~]# tail -f /var/log/zabbix/zabbix_server.log
24441:20220110:155841.001 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24441:20220110:155842.005 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24440:20220110:155843.009 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24438:20220110:155844.012 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24440:20220110:155845.016 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24441:20220110:155846.019 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24441:20220110:155847.023 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24438:20220110:155847.496 cannot parse heartbeat from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24440:20220110:155848.027 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24438:20220110:155849.031 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24438:20220110:155850.036 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24438:20220110:155851.042 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24439:20220110:155852.045 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
24438:20220110:155853.049 cannot parse proxy data from active proxy at "192.168.1.138": proxy "zabbix porxy-agent" not found
^C
[root@localhost ~]#
agent 使用 proxy
[root@localhost ~]# grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=127.0.0.1,192.168.1.138
ServerActive=127.0.0.1,192.168.1.138
Hostname=Zabbix pox-agent
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
[root@localhost ~]#