一嵌屎、Zabbix web頁面操作
1.1 為主機(jī)增加mysql template
1.2 查看主機(jī)監(jiān)控項狀態(tài)
點(diǎn)擊主機(jī) - 應(yīng)用集 - 監(jiān)控項
查看信息螃概,如果有報錯需要解決
如:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: NO)
1.3 查看是否獲取到數(shù)據(jù)
檢測中 - 最新數(shù)據(jù)
二寿谴、Zabbix agent配置
2.1 創(chuàng)建檢測腳本
打開zabbix agent配置目錄 /etc/zabbix
cd /etc/zabbix
chk_mysql.sh
vim chk_mysql.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# FileName: check_mysql.sh
# Revision: 1.0
# Date: 2016/09/29
# Author: lisiyu
# Email:
# Website:
# Description:
# Notes: ~
# -------------------------------------------------------------------------------
# Copyright: 2015 (c) DengYun
# License: GPL
# 用戶名
MYSQL_USER='zabbix'
# 密碼
MYSQL_PWD='zabbix'
# 主機(jī)地址/IP
MYSQL_HOST='127.0.0.1'
# 端口
MYSQL_PORT='3306'
# 數(shù)據(jù)連接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
# 參數(shù)是否正確
if [ $# -ne "1" ];then
echo "arg error!"
fi
# 獲取數(shù)據(jù)
case $1 in
Uptime)
result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"`
echo $result
;;
Com_update)
result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3`
echo $result
;;
Slow_queries)
result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Com_select)
result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3`
echo $result
;;
Com_rollback)
result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
echo $result
;;
Questions)
result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"`
echo $result
;;
Com_insert)
result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3`
echo $result
;;
Com_delete)
result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3`
echo $result
;;
Com_commit)
result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3`
echo $result
;;
Bytes_sent)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`
echo $result
;;
Bytes_received)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
echo $result
;;
Com_begin)
result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac
注意:腳本的zabbix用戶運(yùn)行權(quán)限
2.2 修改mysql檢測配置
將原先的注釋了,添加新的配置
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
#UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -N | awk '{print $$2}'
UserParameter=mysql.status[*],/etc/zabbix/chk_mysql.sh $1
#UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix mysql -N'
#UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.ping,mysqladmin -uzabbix -pzabbix -P3306 -h127.0.0.1 ping | grep -c alive
UserParameter=mysql.version,mysql -V
2.3 關(guān)閉SELinux和firewall
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
2.4 重啟agent
systemctl stop zabbix-agent
systemctl start zabbix-agent
2.5 如果還有問題衷恭,創(chuàng)建mysql連接文件
vim /etc/zabbix/zabbix_agentd.d/.my.cnf
[client]
user = zabbix
password = zabbix
三腾夯、zabbix測試mysql
注意,要在zabbix server上運(yùn)行zabbix_get价脾,在agent上會報錯:
zabbix_get [24860]: Check access restrictions in Zabbix agent configuration
因為zabbix server是編譯安裝牧抵,所以我這里目錄在/usr/local/zabbix
cd /usr/local/zabbix/bin
./zabbix_get -s 192.168.16.214 -p10050 -k "system.cpu.load[all,avg15]";
./zabbix_get -s 192.168.16.214 -p10050 -k mysql.status[Uptime];
參考
zabbix監(jiān)控mysql性能(106)
Zabbix_get小工具的使用
Zabbix官網(wǎng) Recipes for monitoring
zabbix3.0 監(jiān)控mysql服務(wù)免用戶名密碼登錄的問題故障處理詳細(xì)過程