zoukankan      html  css  js  c++  java
  • Ubuntu下Zabbix结合percona监控mysql数据

    按道理来说zabbix就自带的MySQL插件来监控mysql数据库,但是你会发现,自带的mysql监控项是很少的,根本满足不了公司的需求。
    由于它本身自带的模板太过简单了,所以需要做更详细的监控,而percona就提供了这个详细监控的模版以及脚本,解决了监控不全面的问题。
    percona插件是安装在zabbix-agent端的

    1、percona插件安装:

    首先需要下载php依赖:

    ubuntu@ubuntu:~$ apt-get install php
    

    1、官网下载percona包

    https://www.percona.com/downloads/percona-monitoring-plugins/
    2019-03-25 14-02-49屏幕截图.pngVersion: percona的版本
    Software:linux server的版本
    Download All Packages Together: 一起下载所有包
    Download Packages Separately: 单独下载某个包
    这里我们选择下载最后一个包-percona-zabbix-templates-1.1.7-1.xenial_all.ded

    2、命令下载

    ubuntu@ubuntu:~$ wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.7/binary/debian/xenial/x86_64/percona-zabbix-templates_1.1.7-1.xenial_all.deb
    

    3、安装percona包

    ubuntu@ubuntu:~$ sudo dpkg -i percona-zabbix-templates_1.1.7-1.xenial_all.deb 
    ubuntu@ubuntu:~$ cd /var/lib/zabbix/percona/templates && ll
    total 292
    drwxr-xr-x 2 root root   4096 Mar 25 14:19 ./
    drwxr-xr-x 4 root root   4096 Mar 15 11:39 ../
    -rw-r--r-- 1 root root  18866 Dec  8  2016 userparameter_percona_mysql.conf
    -rw-r--r-- 1 root root 269258 Dec  8  2016 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
    

    2、编辑配置文件

    1、添加模板文件路径

    ubuntu@ubuntu:~$ sudo mv /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix_agentd.conf.d/
    

    2、修改MySQL的执行命令文件,更改mysql的用户与密码:

     ubuntu@ubuntu:~$ sudo vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
    


    RES=`HOME=~ /usr/bin/mysql -uroot -pzabbix  -e 'SHOW SLAVE STATUSG' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr ' ' ','`

    mysql -u用户名 -p密码,这里根据自己实际情况修改

    3、修改 ss_get_mysql_stats.php文件

    ubuntu@ubuntu:~$ sudo vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
    


    $mysql_user = 'root';
    $mysql_pass = 'zabbix';


    4、重启zabbix客户端

    [root@node2 templates]# /etc/init.d/zabbix_agentd restart
    

    5、导入mysql的监控模板

    模板需要先导入桌面

    ubuntu@ubuntu:~$ sudo sz /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml 
    


                                                                       图1

    6、导入出错

    出现“标签无效 "/zabbix_export/date": "YYYY-MM-DDThh:mm:ssZ" 预计”,如图2所示:
     
                                                                       图2
    解决方法:百度了一下说将zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml导入zabbix2.4版本中再导出。之后将新的导出xml导入到3.2中问题解决。


    7、关联模板Template Percona MySQL Server

    2019-03-25 14-35-28屏幕截图.png
    可以发现自带的监控项就一百多了,图形四十多个。

                                                                     图3

    8、查看监控图像,出数据如图4、图5所示:


                                                                     图4
     

    9、碰到问题:

    55392:20170914:014811.374 item "SLAVE1:MySQL.State-none" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
    
    21" of type "string" is not suitable for value type "Numeric (float)"
    
    55392:20170914:014813.403 item "SLAVE1:MySQL.State-other" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
    
    0" of type "string" is not suitable for value type "Numeric (float)"
    

    执行测试发现发现是文件权限不对:

    [root@slave1 zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k  "MySQL.Threads-connected"
    rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
    
    [root@slave1 zabbix]# ls -alt /tmp/192.168.174.133-mysql_cacti_stats.txt
    -rw-r--r--. 1 root root 1422 Sep 14 01:41 /tmp/192.168.174.133-mysql_cacti_stats.txt
    

    修改权限后测试正常:

    [root@slave1 zabbix]# chown zabbix:zabbix /tmp/192.168.174.133-mysql_cacti_stats.txt
    [root@slave1 zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k  "MySQL.Threads-connected"
    22
    
    [root@slave1 zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k  "MySQL.Key-read-requests"
    152
    

    查看日志也正常:

    [root@slave1 zabbix]# tail -f zabbix_server.log
    
    55393:20170914:015126.082 item "SLAVE1:MySQL.innodb-transactions" became not supported: cannot convert value to numeric type
    
    55394:20170914:015127.098 item "SLAVE1:MySQL.Key-buf-bytes-unflushed" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
    
    0" of type "string" is not suitable for value type "Numeric (float)"
    
    55392:20170914:015128.100 item "SLAVE1:MySQL.Key-buf-bytes-used" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
    
    1530880" of type "string" is not suitable for value type "Numeric (float)"
    
    55392:20170914:015129.120 item "SLAVE1:MySQL.key-buffer-size" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
    
    8388608" of type "string" is not suitable for value type "Numeric (float)"
    
    55395:20170914:015130.166 item "SLAVE1:MySQL.Key-read-requests" became not supported: cannot convert value to numeric type
    
    55393:20170914:015131.169 item "SLAVE1:MySQL.Key-reads" became not supported: cannot convert value to numeric type
    
    55393:20170914:015132.182 item "SLAVE1:MySQL.Key-write-requests" became not supported: cannot convert value to numeric type
    
    55392:20170914:015252.792 item "SLAVE1:MySQL.slave-lag" became supported
    
    55393:20170914:015253.795 item "SLAVE1:MySQL.Slave-open-temp-tables" became supported
    
    55393:20170914:015255.830 item "SLAVE1:MySQL.slave-running" became supported
    
    55395:20170914:015256.873 item "SLAVE1:MySQL.slave-stopped" became supported
    
    55393:20170914:015304.906 item "SLAVE1:MySQL.State-closing-tables" became supported
    
    55392:20170914:015305.913 item "SLAVE1:MySQL.State-copying-to-tmp-table" became supported
    
    55395:20170914:015306.925 item "SLAVE1:MySQL.State-end" became supported
    
    55392:20170914:015307.934 item "SLAVE1:MySQL.State-freeing-items" became supported
    
    
    
  • 相关阅读:
    python主流框架简介和Django框架的使用
    如何确定计算上已安装的.NET framework版本
    访问另一台主机时报错0x80004005
    sql server自动备份数据库
    sql server创建维护计划报错“不是有效的win32”
    sql server agent代理备份数据库报错‘用户 'sa' 登录失败’
    sql server日志查错
    windows10安装64位Orcale 19c
    触发器基本知识
    MediaElement 的两种模式
  • 原文地址:https://www.cnblogs.com/zeq912/p/10593647.html
Copyright © 2011-2022 走看看