Zabbix Server 自带模板监控更加灵活MySQL数据库

              Zabbix Server 自带模板监控更加灵活MySQL数据库

                                           作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。 

 

 

 

一.zabbix-agent端配置

1>.修改zabbix的item配置文件

[root@node102 ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf  | egrep -v '^#|^$'
UserParameter=mysql.status[*],echo "show global status where Variable_name='$3';" | HOME=/var/lib/zabbix mysql -u$1 -p$2 -N | awk '{print $$2}'          #注意这里修改了3处
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix mysql -N'
UserParameter=mysql.ping[*],HOME=/var/lib/zabbix mysqladmin ping -u$1 -p$2 | grep -c alive                                          #这里也修改了3处
UserParameter=mysql.version,mysql -V
[root@node102 ~]# 
[root@node102 ~]# systemctl restart zabbix-agent
[root@node102 ~]#

2>.使用zabbix-Server测试

[root@node101 ~]# zabbix_get -s node102.yinzhengjie.org.cn -k mysql.status[root,yinzhengjie,Uptime]          #很显然,我们是可以取到值的!
3128
[root@node101 ~]# 
[root@node101 ~]# zabbix_get -s node102.yinzhengjie.org.cn -k mysql.status[root,yinzhengjie,Uptime]
3129
[root@node101 ~]# 
[root@node101 ~]# zabbix_get -s node102.yinzhengjie.org.cn -k mysql.status[root,yinzhengjie,Uptime]
3130
[root@node101 ~]# 
[root@node101 ~]# 

3>.创建MySQL测试用户

[root@node102 ~]# mysql -uroot -pyinzhengjie
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 728
Server version: 5.5.60-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)]> 
MariaDB [(none)]> GRANT ALL ON *.* TO  monitor@'localhost' IDENTIFIED BY 'yinzhengjie2019';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> quit
Bye
[root@node102 ~]# 

 

二.zabbix-Server端配置

1>.找到zabbix-server的数据库模板

2>.添加zabbix的变量

3>.更新模板

4>.重复下图操作,将默认的13个监控项的key都添加2个变量

5>.数据库模板配置完成

6>.配置被监控的数据库的用户名和密码

7>.配置完成

8>.在zabbix-server端让配置立即生效

[root@node101 ~]# zabbix_server -R config_cache_reload        #重新加载配置信息
zabbix_server [4009]: command sent successfully
[root@node101 ~]# 
[root@node101 ~]# 

9>.查看监控图像

 

posted @ 2019-02-20 00:40  尹正杰  阅读(846)  评论(0编辑  收藏  举报