- A+
前文我们了解了zabbix 使用snmp和jmx信道采集数据的相关使用配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/14029864.html;今天我们来说zabbix proxy;
1、zabbix proxy是什么?为什么要使用zabbix proxy?
简单讲zabbix proxy就是zabbix server的代理服务,它能帮助zabbix server采集数据,然后再统一的发送给zabbix server ;它的功能和zabbix server 很类似,zabbix server 能做到它几乎都能做;主要作用就是代理zabbix server ;我们知道监控一个主机或者服务,通常监控项有很多,每个监控项的数据采集工作都会消耗zabbix server 一个socket;这样一来监控一个主机少则十几个socket连接,多则几十个上百个;我们试想一个场景,我们要监控一个集群,这个集群有100台物理主机,每个物理主机都要监控cpu,内存,磁盘等等,一台服务器平均监控项为20个,那么100台服务器就要2000个socket连接;这意味着zabbix server要有2000个socket连接需要维持;这样一来无疑对zabbix server性能有很大的影响;为了降低zabbix server连接socket数量过大而带来的性能消耗,此时zabbix server就应该委托其他主机来代理收集数据;这个代理就是zabbix proxy;除了以上场景,比如跨机房的场景我们也需要用zabbix proxy,每个zabbix proxy只负责采集本地同一机房里的主机的数据,然后统一发送给zabbix server;这样一来可以减少zabbix server的socket连接数量,从而降低zabbix server的压力;
2、zabbix proxy内部组件
zabbix proxy主要由zabbix proxy和数据库组成;它这个数据库不是永久存储采集数据的,它可以将采集的数据临时存放在数据库中,当它把对应的数据发送给zabbix server以后,本地临时存储的数据就会清除;除了缓存采集的数据意外,它还可以用来存储在zabbix server上拉取的监控配置信息;
3、zabbix proxy 部署
准备yum仓库文件
[root@node03 ~]# scp /etc/yum.repos.d/zabbix.repo node06:/etc/yum.repos.d/ zabbix.repo 100% 242 164.4KB/s 00:00 [root@node03 ~]# scp /etc/yum.repos.d/mariadb.repo node06:/etc/yum.repos.d/ mariadb.repo 100% 129 116.6KB/s 00:00 [root@node03 ~]#
安装MariaDB-server
[root@node06 ~]# yum install -y MariaDB-server
配置数据库
[root@node06 ~]# cat /etc/my.cnf.d/zabbix_proxy.cnf [mysqld] bind-address = 0.0.0.0 default-storage-engine = innodb innodb_file_per_table = on max_connections = 4096 collation-server = utf8_general_ci character-set-server = utf8 skip_name_resolve [root@node06 ~]#
启动mariadb
[root@node06 ~]# /etc/init.d/mysql start Starting MariaDB.201125 22:12:03 mysqld_safe Logging to '/var/lib/mysql/node06.test.org.err'. 201125 22:12:03 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql SUCCESS! [root@node06 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* [root@node06 ~]#
设置root密码
[root@node06 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! [root
创建数据库和用户授权
[root@node06 ~]# mysql -uroot -padmin123.com Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 11 Server version: 10.0.38-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 character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on zabbix.* to zabbix_proxy@'192.168.%.%' identified by 'admin123.com'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]>
安装zabbix proxy
[root@node06 ~]# yum install -y zabbix-proxy-mysql
查看zabbix proxy 安装的文件
[root@node06 ~]# 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-4.0.26 /usr/share/doc/zabbix-proxy-mysql-4.0.26/AUTHORS /usr/share/doc/zabbix-proxy-mysql-4.0.26/COPYING /usr/share/doc/zabbix-proxy-mysql-4.0.26/ChangeLog /usr/share/doc/zabbix-proxy-mysql-4.0.26/NEWS /usr/share/doc/zabbix-proxy-mysql-4.0.26/README /usr/share/doc/zabbix-proxy-mysql-4.0.26/schema.sql.gz /usr/share/man/man8/zabbix_proxy.8.gz /var/log/zabbix /var/run/zabbix [root@node06 ~]#
导入表
[root@node06 ~]# zcat /usr/share/doc/zabbix-proxy-mysql-4.0.26/schema.sql.gz |mysql -uzabbix_proxy -padmin123.com -h192.168.0.46 zabbix [root@node06 ~]#
验证:查看对应数据库是否有表生成?
[root@node06 ~]# mysql -uzabbix_proxy -padmin123.com -h192.168.0.46 zabbix -e 'show tables;' |wc -l 145 [root@node06 ~]#
提示:能够统计到对应表的数量,说明我们导入表的操作没有问题;
配置zabbix proxy
[root@node06 ~]# grep -Ei "^[a-z]" /etc/zabbix/zabbix_proxy.conf ProxyMode=0 Server=192.168.0.43 ServerPort=10051 HostnameItem=system.hostname ListenPort=10051 LogFile=/var/log/zabbix/zabbix_proxy.log LogFileSize=0 DebugLevel=3 PidFile=/var/run/zabbix/zabbix_proxy.pid SocketDir=/var/run/zabbix DBHost=192.168.0.46 DBName=zabbix DBUser=zabbix_proxy DBPassword=admin123.com HeartbeatFrequency=60 ConfigFrequency=60 DataSenderFrequency=1 StartPollers=5 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log Timeout=4 ExternalScripts=/usr/lib/zabbix/externalscripts LogSlowQueries=3000 [root@node06 ~]#
提示:主要配置zabbix server的地址以及zabbix proxy的hostname和数据库相关的几个选项以及后面的心跳频率和配置文件更新频率以及数据发送频率;其他保持默认即可;这里需要提醒下,默认情况zabbix proxy 工作为主动模式,所谓主动模式是指zabbix proxy主动到zabbix server上获取监控配置和推送采集的数据;如果需要配置为被动,这需要将ProxyMode更改为1即可;Server是配置zabbix server的地址,意思是告诉proxy到到哪里获取配置以及将采集的数据推送到哪里;后面的HeartbeatFrequency是用来指定多长时间发送一次心跳信息给zabbix server,默认是60秒;ConfigFrequency是用来指定更新监控配置信息的频率,意思是多久去zabbix server 上同步一下监控配置;默认是3600;这个可以根据实际情况更改;DataSenderFrequency是用于指定多长时间发一次数据给zabbix server,默认为1秒;
启动zabbix proxy
[root@node06 ~]# systemctl start zabbix-proxy.service [root@node06 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:10051 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::10051 :::* [root@node06 ~]#
提示:zabbix proxy 默认监听在10051,启动后请确保该端口正常监听;
安装zabbix agent用于监控zabbix proxy自身
[root@node06 ~]# yum install -y zabbix-agent
配置zabbix agent
[root@node06 ~]# grep -Ei "^[a-z]" /etc/zabbix/zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=192.168.0.46 ListenPort=10050 ListenIP=0.0.0.0 ServerActive=192.168.0.46 HostnameItem=system.hostname Include=/etc/zabbix/zabbix_agentd.d/*.conf [root@node06 ~]#
提示:这里的配置和我们前边配置zabbix agent几乎一样,不同的是我们需要将Server指向zabbix proxy的地址和端口;如果其他agent需要用到proxy来代理,需要配置运行proxy来采集数据;这个Server的值可以是多个,分别用逗号隔开即可;同样ServerActive也应该指向zabbix proxy的地址;
启动zabbix agent
[root@node06 ~]# systemctl start zabbix-agent.service [root@node06 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:10050 *:* LISTEN 0 128 *:10051 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::10051 :::* [root@node06 ~]#
在zabbix web界面配置添加zabbix proxy
提示:在administration--->proxIes---->create proxy点击进入新建proxy的页面;
提示:这里的proxy name必须和本地运行zabbix proxy服务主机名称相同;填写好proxy name以后点击添加即可;
添加主机,使用我们刚才添加到proxy来代理采集数据
提示:添加主机一定要选择对应要使用的zabbix proxy;
链接模板
提示:选择好模板以后,最后点击add将主机添加到主机列表;
提示:可以看到现在添加到主机,前边都有对应proxy的名称;过一会我们就可以看到proxy将模板上的监控数据采集后,发送给zabbix server,此时就可以看到对应的主机上的监控数据;
验证:查看对应主机是否有监控数据?
提示:可以看到node06链接的模板监控项也陆续有数据,说明proxy采集到数据已经发送给zabbix server ;
查看zabbix proxy状态
提示:可以看到现在node06.test.org这个proxy有一个host,34个item,vps为0.39;如果其他主机需要用该proxy代理采集数据,我们需要将对应的agent配置允许该proxy来采集数据;
到此,zabbix proxy的安装,测试就完成了;