使用zabbix-agent2对redis和mongodb进行监控
一、redis
zabbix-agent2.conf中添加
Plugins.Redis.Sessions.redis.Uri=tcp://192.168.11.16:6379 #redis_smartgate 为被监控的实例名,在zabbix服务器端会用到
Plugins.Redis.Sessions.redis.Password=xxxxxxxxxxxxxxxxx #redis_smartgate的密码
在主机配置中添加宏
{$REDIS.CONN.URI} = redis #redis_smartgate与zabbix-agent2.conf中的配对
二、mongodb
2.1 在mongo数据库中添加监控专用的帐号
use admin
db.auth("admin", "[email protected]")
db.createUser({ "user": "monitor", "pwd": "monitor@#2O22", "roles": [ { role: "readAnyDatabase", db: "admin" }, { role: "clusterMonitor", db: "admin" } ] })
2.2 在zabbix-agent2中添加配置
Plugins.Mongo.Sessions.mongo.Uri=tcp://127.0.0.1:27017
Plugins.Mongo.Sessions.mongo.User=monitor
Plugins.Mongo.Sessions.mongo.Password=monitor@#2O22
2.3 在主机配置中添加宏
{$MONGODB.CONNSTRING} = mongo #redis_smartgate与zabbix-agent2.conf中的配对
三、mysql
3.1、在被监控的数据库主机上,新建数据库用户,并赋予权限:
mysql> CREATE USER ‘monitor’@‘%’ IDENTIFIED BY ‘monitor@#2O22’;
mysql> GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON . TO ‘monitor’@‘%’;
mysql> flush privileges;
3.2 配置
Plugins.Mysql.CallTimeout=30
Plugins.Mysql.Sessions.mysql.Uri=unix:/data/mysql/mysql.sock
Plugins.Mysql.Sessions.mysql.User=monitor
Plugins.Mysql.Sessions.mysql.Password=monitor@#2O22
在主机配置中添加宏
{$MYSQL_DSN} = mysql #redis_smartgate与zabbix-agent2.conf中的配对
zabbix_agent2.conf
PidFile=/data/zabbix_agent2/zabbix_agent2.pid
LogFile=/data/zabbix_agent2/log/zabbix_agent2.log
LogFileSize=0
Server=192.168.11.100,127.0.0.1
ServerActive=192.168.11.100:10051,127.0.0.1:10051
Hostname=192.168.11.100
Include=/data/zabbix_agent2/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
TLSConnect=psk
TLSAccept=psk
TLSPSKIdentity=PSK 001
TLSPSKFile=/data/zabbix_agent2/zabbix_agent2.d/.zabbix.psk
#mongo
Plugins.Mongo.Sessions.mongo.Uri=tcp://127.0.0.1:27017
Plugins.Mongo.Sessions.mongo.User=monitor
Plugins.Mongo.Sessions.mongo.Password=Monitor#2O22
#redis
Plugins.Redis.Sessions.redis.Uri=tcp://127.0.0.1:6379
Plugins.Redis.Sessions.redis.Password=xxxxxxxxxxxxxxxxx
#mysql
Plugins.Mysql.CallTimeout=30
#Plugins.Mysql.Sessions.mysql.Uri=unix:/data/mysql/mysql.sock
Plugins.Mysql.Sessions.mysql.Uri=tcp://127.0.0.1:3306
Plugins.Mysql.Sessions.mysql.User=monitor
Plugins.Mysql.Sessions.mysql.Password=Monitor#2O22
mongodb zabbix-agent2插件
https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix-agent2-plugins/1/rhel/7/x86_64/