上一篇给大家分享了监控Nginx《项目实战:创建模板,监控Nginx状态、服务信息》,这里跟大家分享一下监控MySQL的记录,如果你没有安装MySQL可以参考我另一篇博文《ubuntu安装配置LNMP》,Let's go!

Zabbix监控MySQL数据库

一、客户端

Ubuntu普通用户登录

1、  登陆MySQL

$ mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 20000023

Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

项目实战:zabbix监控MySQL状态、服务信息_Linux系统运维 自动化运维 zabb

2、  创建zabbix用户用于发送数据

mysql>  GRANT USAGE ON*.*TO'zabbix'@'localhost'IDENTIFIED BY'You_passwd';

Query OK, 0 rows affected (0.00 sec)

 

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

 

mysql> \q

Bye

项目实战:zabbix监控MySQL状态、服务信息_Linux系统运维 自动化运维 zabb_02

3、  测试zabbix用户登陆

$ mysql -uzabbix -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 20000582

Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> \q

Bye

项目实战:zabbix监控MySQL状态、服务信息_Linux系统运维 自动化运维 zabb_03

4、  查找MySQL进程所在的位置

$ sudo find / -name *sock -print

[sudo] password for bdyun:

/run/mysqld/mysqld.sock        #MySQL进程所在的位置

/sys/kernel/debug/tracing/events/sock

/lib/modules/3.13.0-32-generic/kernel/net/vmw_vsock

/usr/src/linux-headers-3.13.0-32/net/vmw_vsock

5、  新建配置文件

$ sudo vi /etc/zabbix/.my.cnf

$ cat /etc/zabbix/.my.cnf

[mysql]

host=localhost

user=zabbix                                 #用来发送数据的用户

password=Bd_zabbix                #用来发送数据的用户密码

socket=/run/mysqld/mysqld.sock

[mysqladmin]

host=localhost

user=zabbix                                 #用来发送数据的用户

password=Bd_zabbix                         #用来发送数据的用户密码

socket=/run/mysqld/mysqld.sock   #MySQL进程所在的位置

项目实战:zabbix监控MySQL状态、服务信息_Linux系统运维 自动化运维 zabb_04

6、  修改文件userparameter_mysql.conf

查找文件所在位置

$ sudo find / -name userparameter_mysql.conf

/usr/share/doc/zabbix-agent/examples/userparameter_mysql.conf

复制文件到/etc/zabbix/zabbix_agentd.conf.d/userparameter_mysql.conf

$ sudo cp /usr/share/doc/zabbix-agent/examples/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.conf.d/userparameter_mysql.conf

$ ls /etc/zabbix/zabbix_agentd.conf.d/

nginx.conf  userparameter_mysql.conf

这个文件用于制定Zabbix Agent如何获取MySQL数据,我们需要将所有的/var/lib/zabbix修改为当前.my.cnf文件的路径/etc/zabbix。设置完 成之后保存并重启Zabbix Agent

$ sudo sed -i 's@/var/lib/zabbix@/etc/zabbix@g' /etc/zabbix/zabbix_agentd.conf.d/userparameter_mysql.conf

$ sudo service zabbix-agent restart

zabbix-agent stop/waiting

zabbix-agent start/running, process 32121

 

 

7、  重启服务

 

$ sudo service zabbix-agent restart

zabbix-agent stop/waiting

zabbix-agent start/running, process 32121

 

二、服务端

1、为监控主机选择、添加MySQL模板

ConfigurationèHostsèTemplates

项目实战:zabbix监控MySQL状态、服务信息_Linux系统运维 自动化运维 zabb_05

2、查看图组数据图形

项目实战:zabbix监控MySQL状态、服务信息_Linux系统运维 自动化运维 zabb_06