zabbix监控mysql数据库(推荐这种方式:zabbix通过mpm监控mysql的环境搭建)

来源:互联网 发布:mac的launchpad 编辑:程序博客网 时间:2024/05/21 19:38

推荐这种方式:zabbix通过mpm监控mysql的环境搭建: http://blog.csdn.net/huoyuanshen/article/details/72828069

1,参考url:

http://blog.csdn.net/mchdba/article/details/51288767 (推荐,已实测)

http://www.ttlsa.com/zabbix/zabbix-monitor-mysql/


2,注意事项:

a,agentd安装要支持mysql监控,./configure --enable-agent --with-mysql   (根据教程安装即可)

b,  

b1:  vim /etc/zabbix/zabbix_agentd.conf 中添加自定义参数时

UserParameter=mysql.ping,mysqladmin -uzabbix -pys_ipowerlong0418 -P3306 -h127.0.0.1  ping | grep -c alive

要改成

UserParameter=mysql.ping,netstat -ntpl |grep 3306 |grep mysql |wc |awk '{print $1}'     (否则无法正常监控mysql关闭状态)

b2:   然后用root账户执行: chmod +s /bin/netstat   (让zabbix用户执行netstat时具有root权限)

b3:新创建的zabbix用户,不需要super权限,可去掉。'127.0.0.1'已要改成'localhost'

 GRANT PROCESS,REPLICATION CLIENT ON *.* TO zabbix@'localhost' IDENTIFIED BY 'ys_ipowerlong0418';

c ,

c1:   修改mysql配置文件(不需要重启)

vim /etc/my.cnf 添加如下信息(注意:如果配置的是root的账户,一定注意权限泄露问题)

[mysqladmin]

user=zabbix

password=ys_ipowerlong0418

c2:   然后修改/usr/local/zabbix/chk_mysql.sh 按如下配置(主要是去除了账户和密码字段,同事修复mysqladmin命令路径。)

#!/bin/sh
# -------------------------------------------------------------------------------
# FileName:    check_mysql.sh
# Revision:    1.0
# Date:        2016/04/22
# Author:      tim
# Email:       mchdba@sohu.com
MYSQL_SOCK="/usr/local/mysql/mysql.sock"
MYSQL_HOST='127.0.0.1'
MYSQL_PORT='3306'
ARGS=1
if [ $# -ne "$ARGS" ];then
    echo "Please input one arguement:"
fi
case $1 in
    Uptime)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK status|cut -f2 -d":"|cut -f1 -d"T"`
            echo $result
            ;;
        Com_update)
            result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_update"|cut -d"|" -f3`
            echo $result
            ;;
        Slow_queries)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK status |cut -f5 -d":"|cut -f1 -d"O"`
                echo $result
                ;;
    Com_select)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_select"|cut -d"|" -f3`
                echo $result
                ;;
    Com_rollback)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
                echo $result
                ;;
    Questions)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK status|cut -f4 -d":"|cut -f1 -d"S"`
                echo $result
                ;;
    Com_insert)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_insert"|cut -d"|" -f3`
                echo $result
                ;;
    Com_delete)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_delete"|cut -d"|" -f3`
                echo $result
                ;;
    Com_commit)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_commit"|cut -d"|" -f3`
                echo $result
                ;;
    Bytes_sent)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`
                echo $result
                ;;
    Bytes_received)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
                echo $result
                ;;
    Com_begin)
        result=`mysqladmin  -h$MYSQL_HOST  -S $MYSQL_SOCK extended-status |grep -w "Com_begin"|cut -d"|" -f3`
                echo $result
                ;;
                       
        *)
        echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions)"
        ;;
esac



0 0
原创粉丝点击