# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm # yum clean all
# yum install zabbix-agent -y
# systemctl start zabbix-agent # systemctl enable zabbix-agent
创建zabbix_proxy 库并设置字符集
mysql>create database zabbix_proxy character set utf8 collate utf8_bin;
创建用户zabbix和密码并设置登录范围(这里我们默认所有人可登录)
create user 'zabbix'@'%' identified by 'Aa@123456';
给zabbix用户授权
grant all privileges on zabbix_proxy.* to 'zabbix'@'%';
打开全局变量
set global log_bin_trust_function_creators = 1;
刷新
flush privileges;
vim /etc/zabbix/zabbix_agentd.conf
加入server端地址和proxy端地址
Server=10.12.153.235,10.12.153.188
ServerActive=10.12.153.235,10.12.153.188
systemctl restart zabbix-agent
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm # yum clean all
yum install zabbix-proxy-mysql -y
zcat /usr/share/doc/zabbix-proxy-mysql*/schema.sql.gz | mysql -uzabbix -pAa@123456 -h10.12.153.73 zabbix_proxy
登录数据库关闭数据库全局变量
mysql>set global log_bin_trust_function_creators = 0;
vim /etc/zabbix/zabbix_proxy.conf
需要找到并修改的配置如下
ProxyMode=1 # 0为主动 1为被动
Server=服务端ip地址
SourceIP=发送采样信息的ip地址
Hostname= #主机名
ListenPort=10051 #proxy自己的监听端口
EnableRemoteCommands=1 #允许远程命令
LogRemoteCommands=1 #记录远程命令的日志
数据的配置
DBHost=数据库地址
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=Aa@123456
ConfigFrequency=30 #多长时间,去服务端拖一次有自己监控的操作配置;为了实验更快的生效,这里设置30秒,默认3600s
DataSenderFrequency=1 #每一秒向server 端发一次数据,发送频度
修改完成后保存退出
systemctl start zabbix-proxy
systemctl enable zabbix-proxy
vim mycat-status.sh
#!/bin/bash
SQL=$(mysql -uroot -p'Aa@123456' -e 'show slave status\G' 2>/dev/null |grep "Slave_SQL_Running"|awk 'NR==1{print $2}')
IO=$(mysql -uroot -p'Aa@123456' -e 'show slave status\G' 2>/dev/null |grep "Slave_IO_Running"|awk 'NR==1{print $2}')
if [ "$SQL" = "Yes" -a "$IO" = "Yes" ];then
echo 1
else echo 0
fi
vim /etc/zabbix/zabbix_agentd.d/mycat-status.conf
赋值名mycat-status加上脚本路径
UserParameter=mycat-status,sh /opt/mycat-status.sh
保存退出
systemctl restart zabbix-agent
测试成功后添加