千家信息网

zabbix监控MySQL详解

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,注意事项:实验环境CentOS Linux release 7.0.1406 (Core)[root@localhost scripts]# mysql -vWelcome to the MariaD
千家信息网最后更新 2024年09月22日zabbix监控MySQL详解

注意事项:

实验环境

CentOS Linux release 7.0.1406 (Core)

[root@localhost scripts]# mysql -v

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

Your MariaDB connection id is 10683

Server version: 5.5.52-MariaDB MariaDB Server

因为我是在一台服务器上做的,需要如下:

zabbix_agentd httpd mysqld zabbix_server


1、使用percona监控插件监控MySQL

[root@localhost alertscripts]# yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

2、percona组成部分

  • PHP脚本

  • shell脚本去调用PHP脚本

  • zabbix配置文件

  • zabbix模板文件

3、安装percona-zabbix模板 PHP PHP-MySQL

[root@localhost alertscripts]# yum install percona-zabbix-templates php php-mysql

4、查看具体安装了什么软件

[root@localhost alertscripts]# rpm -qa php

[root@localhost scripts]# rpm -ql percona-zabbix-templates

/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.7.xml

[root@localhost scripts]#


5、导入模板

/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml



6、拷贝配置文件

[root@localhost alertscripts]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/

7、脚本存放位置

[root@localhost scripts]# pwd

/var/lib/zabbix/percona/scripts

8、重启服务

[root@localhost scripts]# systemctl restart zabbix-agent

9、创建一个配置文件,内容,用户名,密码。

<注意:生产环境中,需要创建一个监控用户>

[root@localhost scripts]# vim ss_get_mysql_stats.php.cnf

[root@localhost scripts]# cat ss_get_mysql_stats.php.cnf

$mysql_user = 'root';

$mysql_pass = 's3cret';(我这里root密码为空,因为没有设置)

9、打开配置文件查看监控的内容,根据需要获取相应的参数



10、执行下脚本

[root@localhost scripts]# ./get_mysql_stats_wrapper.sh

获得的指标

[root@localhost scripts]# ./get_mysql_stats_wrapper.sh

7

4

4

4

2746

273953

1

20

0

0

8191

6663

1507

26

0

1507


11、脚本中有点小BUG

11、配置主机添加模板,用惯了英文换会英文界面

然后查看图形连接数

0