2

Zabbix Proxy搭建实现分布式部署

 2 years ago
source link: https://www.opsit.cn/7915.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

0x01 环境介绍

众所周知,proxy 可以代替 zabbix server 收集性能和可用性数据,然后把数据汇报给 zabbix server,并且在一定程度上分担了zabbix server 的压力。此外,当所有agents和proxies报告给一个Zabbix server并且所有数据都集中收集时,使用proxy是实现集中式和分布式监控的最简单方法。

本实验采用Zabbix 5.0.6 环境进行搭建,拓扑如下

885693c05528ac5_1_post.png

Server [CentOS 7.6 Zabbix:5.06]

ip:172.16.252.100

hostname:zabbix

Proxy [CentOS 7.6 Zabbix:5.06]

ip:172.16.252.119

hostname:lab-node1

Agent [CentOS 7.6]

ip:172.16.252.201

hostname:lab-client-node2

0x02 Server 安装

参照此篇文章,此处不再复述安装步骤

0x03 Proxy 安装配置

1. 安装zabbix官方源余epel源,注意操作前将SElinux与防火墙永久关闭(实验环境,实际生产环境请配置相关端口策略

  1. yum -y install epel-release.noarch
  2. rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

2. 安装配置Zabbix-proxy相关组件

  1. yum install -y zabbix-proxy zabbix-proxy-mysql mariadb mariadb-server zabbix-agent

3. 数据库操作优化

  1. vim /etc/my.cnf
  2. [mysqld]
  3. datadir=/var/lib/mysql
  4. socket=/var/lib/mysql/mysql.sock
  5. symbolic-links=0
  6. character-set-server=utf8 #设置字符集为utf8
  7. innodb_file_per_table=1 #设置innodb的每个表文件单独存储
  8. [mysqld_safe]
  9. log-error=/var/log/mariadb/mariadb.log
  10. pid-file=/var/run/mariadb/mariadb.pid
  11. # 开启数据库服务,设为开机启动
  12. systemctl start mariadb #设为开机启动
  13. systemctl enable mariadb #开启MariaDB数据

4. 数据库配置

  1. MariaDB [(none)]> create database zabbixproxydb character set utf8 collate utf8_bin;
  2. #创建数据库且字符集为utf8,使web界面显示中文不出现乱码
  3. MariaDB [(none)]> grant all privileges on zabbixproxydb.* to root@'localhost' identified by 'passwd1!';
  4. #创建zabbixproxydb数据库,且赋予root用户拥有此数据库全部权限。
  5. MariaDB [(none)]> flush privileges;

5. 导入相关表到数据库

  1. zcat /usr/share/doc/zabbix-proxy-mysql-*/schema.sql.gz | mysql -uroot -p zabbixproxydb
  2. #将模板数据恢复至zabbixproxydb数据
  3. mysql -uroot -ppasswd1! zabbixproxydb -e "show tables" #查看数据是否导入

6. 修改zabbix_proxy.conf配置

  1. vim /etc/zabbix/zabbix_proxy.conf
  2. ProxyMode=0 # 默认即为0,代表 Proxy 处于主动模式,即 Proxy 主动去请求 Zabbix Server 获取监控项;1 代表被动模式
  3. Server=172.16.252.100 #改成service端ip需要向service发送数据
  4. ServerPort=10051 # 默认即为10051,Zabbix Server 监听端口,同上只在 Proxy 为主动模式时生效
  5. Hostname=lab-node1 # Server端添加proxy的时候需要一致,建议采用主机名
  6. LogFile=/var/log/zabbix/zabbix_proxy.log # Proxy 日志文件位置
  7. LogFileSize=0
  8. PidFile=/var/run/zabbix/zabbix_proxy.pid
  9. DBHost=localhost # 连接数据库的主机
  10. DBName=zabbixproxydb # 数据库名
  11. DBUser=root # 连接用户
  12. DBPassword=passwd1! # 用户密码
  13. ConfigFrequency=60 # proxy主动从server端检索配置更新的频率,单位秒,主动proxy 参数, 被动 proxies忽略此项
  14. DataSenderFrequency=60 # Proxy 向 Zabbix Server 发送监控数据间隔,单位为秒
  15. Timeout=4

7. Proxy agent配置

  1. #修改配置zabbix_agentd.conf配置文件
  2. vim /etc/zabbix/zabbix_agentd.conf
  3. PidFile=/var/run/zabbix/zabbix_agentd.pid
  4. LogFile=/var/log/zabbix/zabbix_agentd.log
  5. LogFileSize=0
  6. Server=172.16.252.119 #若为纯主动模式需要注释此行
  7. ServerActive=172.16.252.119 #主动模式,数据通过proxy代理向Server传送数据
  8. Hostname=lab-node1 #zabbix server web上添加自身需要用到
  9. #将proxy与agent启动并加入开机启动
  10. systemctl start zabbix-agent.service #启动agent服务
  11. systemctl enable zabbix-agent.service #agent添加到开机启动
  12. systemctl start zabbix-proxy.service #启动proxy服务
  13. systemctl enable zabbix-proxy.service #proxy添加到开机启动

0x04 前台web配置

进入前台web页面,点击管理 –agent代理程序 —创建代理

88e5a0668859f60_1_post.png

输入代理程序名,此处对应zabbix_proxy.conf配置文件中的hostname,与ip地址,选择主动模式

88455d5b23e8690_1_post.png

0x05 Client 安装配置

1. 安装agent服务

  1. yum -y install zabbix-agent

2. agent修改配置

  1. vim /etc/zabbix/zabbix_agentd.conf
  2. PidFile=/var/run/zabbix/zabbix_agentd.pid
  3. LogFile=/var/log/zabbix/zabbix_agentd.log
  4. LogFileSize=0
  5. Server=172.16.252.119 #若为纯主动模式需要注释此行
  6. ServerActive=172.16.252.119 #主动模式,数据通过proxy代理向Server传送数据
  7. Hostname=lab-node1 #zabbix server web上添加自身需要用到
  8. #启动并添加到自启动
  9. systemctl start zabbix-agent
  10. systemctl enable zabbix-agent

3. 主机加入监控

web页面点击–配置–主机–创建主机

886c5a5f926e509_1_post.png

并链接到对应的系统模板中,此处需要对模板进行修改,点击模板中监控项,全选,批量更新为Zabbix客户端 主动模式

88465ca01d29525_1_post.png

889a8e054969750_1_post.png

稍等几分钟后即可在配置–主机中看到可用性 状态变绿

8859d95dad60500_1_post.png


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK