zabbix 3.0 监控mysql_zabbix 3.0.2监控mysql

内网有一台mysql服务器,版本是5.7.14

关于这个版本安装,有兴趣可以参考

http://xiao987334176.blog.51cto.com/2202382/1783509

zabbix自带有一个模板Template App MySQL,用来监控mysql的

但是不能直接使用,否则会因为没有Key,导致获取不到数据。

下面介绍详细步骤。

首先在mysql服务器安装zabbix-agent,请参考

http://xiao987334176.blog.51cto.com/2202382/1768281

最下面一部分。

###################################################################################

讲解一个比较重要的问题。

在shell里面,直接运行mysql相关命令,指定密码时,就会有一个提示

比如: mysql -u zabbix -p123456 运行之后

Warning: Using a password on the command line interface can be insecure.

这个提示在mysql 5.5之后会出现。

而且,这个提示,会被zabbix-servre捕捉到,在zabbix-server.log日志中会出现

24123:20160826:101433.609 error reason for "110:mysql.status[Bytes_sent]" changed: Received value [mysqladmin: [Warning] Using a password on the command line interface can be insecure.8991074] is not suitable for value type [Numeric (float)]

提示参数不符合

在zabbix-server服务器上面,使用zabbix-get命令时

[root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.110 -p10050 -k mysql.status[Uptime]

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

57577

###################################################################################

那么为了解决这个问题,必须无密码登录才可以,为了安全起见,限定只能在localhost登录

先创建一个zabbix用户(创建用户,密码不能为空,否则报错)

grant all PRIVILEGES on *.* to zabbix@'localhost' identified by '123456';

设置密码为root

update mysql.user set authentication_string=password('root') where user='zabbix' and Host = 'localhost';

刷新权限

flush privileges;

退出

exit;

测试无密码登录

[root@localhost opt]# mysql -u zabbix

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

Your MySQL connection id is 930

Server version: 5.7.14 Source distribution

Copyright (c) 2000, 2016, 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> exit

Bye

发现一个很奇怪的现象,把密码设置和root一样,就可以无密码登录了

mysql> select Host,User,authentication_string from mysql.user;

+-----------+-----------+-------------------------------------------+

| Host      | User      | authentication_string                     |

+-----------+-----------+-------------------------------------------+

| localhost | root      | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |

| localhost | zabbix    | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

+-----------+-----------+-------------------------------------------+

3 rows in set (0.00 sec)

进入Mysql服务器的zabbix-agent目录

cd /usr/local/zabbix-agent/

mkdir alertscripts

编辑脚本

vim checkmysql.sh

内容如下:

#!/bin/sh

#MYSQL_SOCK="/data/3306/mysqld.sock"

#MYSQL_PWD=`cat /usr/local/zabbix-agent/alertscripts/.mysqlpassword`

ARGS=1

if [ $# -ne "$ARGS" ];then

echo "Please input one arguement:"

fi

case $1 in

Uptime)

result=`mysqladmin -uzabbix status|cut -f2 -d":"|cut -f1 -d"T"`

echo $result

;;

Com_update)

result=`mysqladmin -uzabbix extended-status |grep -w "Com_update"|cut -d"|" -f3`

echo $result

;;

Slow_queries)

result=`mysqladmin -uzabbix status |cut -f5 -d":"|cut -f1 -d"O"`

echo $result

;;

Com_select)

result=`mysqladmin -uzabbix extended-status |grep -w "Com_select"|cut -d"|" -f3`

echo $result

;;

Com_rollback)

result=`mysqladmin -uzabbix extended-status |grep -w "Com_rollback"|cut -d"|" -f3`

echo $result

;;

Questions)

result=`mysqladmin -uzabbix status|cut -f4 -d":"|cut -f1 -d"S"`

echo $result

;;

Com_insert)

result=`mysqladmin -uzabbix extended-status |grep -w "Com_insert"|cut -d"|" -f3`

echo $result

;;

Com_delete)

result=`mysqladmin -uzabbix extended-status |grep -w "Com_delete"|cut -d"|" -f3`

echo $result

;;

Com_commit)

result=`mysqladmin -uzabbix extended-status |grep -w "Com_commit"|cut -d"|" -f3`

echo $result

;;

Bytes_sent)

result=`mysqladmin -uzabbix extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`

echo $result

;;

Bytes_received)

result=`mysqladmin -uzabbix extended-status |grep -w "Bytes_received" |cut -d"|" -f3`

echo $result

;;

Com_begin)

result=`mysqladmin -uzabbix 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

设置权限

chmod 755 checkmysql.sh

chown zabbix:zabbix -R /usr/local/zabbix-agent/

编辑配置文件

vim /usr/local/zabbix-agent/etc/zabbix_agentd.conf

增加紫色部分,内容如下:

LogFile=/usr/local/zabbix-agent/logs/zabbix_agentd.log

###zabbix 服务端地址

Server=192.168.1.109

##agent服务监听地址,也就是本机地址

#ListenIP=192.168.1.105

###ServerActive=192.168.1.110

##zabbix-server端主机地址(zabbix server)

Hostname=zabbix server

UserParameter=mysql.version,mysql -V

UserParameter=mysql.status[*],/usr/local/zabbix-agent/alertscripts/checkmysql.sh $1

UserParameter=mysql.ping,mysqladmin -uzabbix ping | grep -c alive

重启zabbix_agentd

/etc/init.d/zabbix_agentd restart

在zabbix-server服务器上面检查mysql

[root@localhost alertscripts]# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.110 -p10050 -k mysql.status[Uptime]

9479

[root@localhost alertscripts]#

如果能直接返回数字,没有多余的字符,就说明成功了。

在zabbix-server添加一台主机

966ddaadb753f33ed66d44d56ce354c4.png

添加模板的时候,选择Template App MySQL和Template OS Linux

d0526e025700baa13b88bb4ecc4c7658.png

等待10分钟,图像就会出来了。

7dabdca6fd3173a91c6807e537cf195a.png

fcde93c493a62d65e62ca7c3db98ec92.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值