zabbix 自动发现主机并关联模板
一.自动发现添加主机
1.利用agent自动发现主机
Configuration - Discovery -Create discovery rule
2.将自动发现的主机关联模板
Configuration - Action -Event source:Discovery - Create action
3.查看发现主机结果
Monitoring - Discovery
参考:https://blog.csdn.net/reblue520/article/details/52209755
二.添加标准msyql监控模板
1.拷贝模板配置文件
cp /root/zabbix-3.4.7/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d
2.修改配置文件
原文件userparameter_mysql.conf 中的HOME目录是/var/lib/zabbix,也就是指向.my.cnf的目录,统一修改成自定义目录:/usr/local/zabbix/etc/
3.创建数据库连接账号
grant all on *.* to "mysqlcheck"@"localhost" identified by "mysqlcheck"; 添加.my.cnf文件 [mysql] host=localhost user=mysqlcheck password=mysqlcheck socket=/usr/local/mysql/mysql.sock [mysqladmin] host=localhost user=mysqlcheck password=mysqlcheck socket=/usr/local/mysql/mysql.sock 修改zabbix_agentd.conf,启用用户参数目录 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
4.重启agent
5..在server中将主机加入模板:Template DB MySQL
三.导入percona的mysql模板
1.安装配置percona监控
1)YUM安装
wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm
2)查看解压目录
[root@slave01 ~]# rpm -qpl percona-zabbix-templates-1.1.8-1.noarch.rpm warning: percona-zabbix-templates-1.1.8-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY /var/lib/zabbix/percona /var/lib/zabbix/percona/scripts /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php /var/lib/zabbix/percona/templates /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
2)将percona目录拷贝到zabbix目录
cp -rp /var/lib/zabbix/percona /usr/local/zabbix/etc/
3)zabbix_agentd.conf include上面的目录
4.重启agent
2.客户端agent主机配置
1)修改mysql连接信息
vim /usr/local/zabbix/etc/percona/scripts/ss_get_mysql_stats.php $mysql_user = 'mysqlcheck'; $mysql_pass = 'mysqlcheck';
2)安装php
https://blog.csdn.net/zhezhebie/article/details/73325663 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum install php70w-cli php70w-mysql -y
3)测试脚本
[root@master scripts]# ./get_mysql_stats_wrapper.sh gg
14
4)在etc目录下配置.my.cnf
[client] user = msyqlcheck password = mysqlcheck
5)syql slave
[root@master etc]# sudo -u zabbix -H /usr/local/zabbix/etc/percona/scripts/get_mysql_stats_wrapper.sh running-slave 0
3.zabbix server配置
1)将templates的xml文件导入server
2)在agent或者server端都可以通过get来获取值
/usr/local/zabbix/bin/zabbix_get -s 192.168.3.20 -k "MySQL.max-connections"
3)来源IP限制
28094:20180422:030055.200 failed to accept an incoming connection: connection from "127.0.0.1" rejected, allowed hosts: "192.168.3.2 Server=192.168.3.21,192.168.3.20,127.0.0.1