一,准备工作
1:#建立mysqladmin命令
ln -s / usr / local / mysql / bin / mysqladmin / usr / bin
2:建立监控用户(所有数据库上建立)
#建立zabbix监控用户(只有查询权限)
授予选择*。*至zabbix@'127.0.0.1'由'密码'标识;
将*。*选择授予'密码'标识的zabbix @'localhost';
##建立监控MySQL的用户的
授予复制客户端* *到'ZABBIX' @ '本地主机'由'密码'标识;
。授予复制客户端* *至'zabbix'@'127.0.0.1'由'密码'识别; 冲洗特权;
3:建立监控
脚本:mkdir -p /etc/zabbix/zabbix_agentd.d/mysql/
cat /etc/zabbix/zabbix_agentd.d/mysql/mysql.sh
脚本内容如下(一般用于监控主数据库):
#!/斌/庆典
#用户名
MYSQL_USER ='zabbix'
#密码
MYSQL_PWD ='密码'
#主机地址/ IP
MYSQL_HOST ='127.0.0.1'
#端口
MYSQL_PORT ='3306'
#数据连接
MYSQL_CONN =“/ usr / bin / mysqladmin -u $ { MYSQL_USER} -p $ {MYSQL_PWD} -h $ {MYSQL_HOST} -P $ {MYSQL_PORT}“
#参数是否正确
如果[$# - ne”1“];然后
回显”arg error!“
fi
##### ####################################获取数据###### ###### ########################################
Uptime运行的时间
#Com_update每秒的更新操作
#Slow_queries慢速查询
#Com_select每秒的查询操作
#Com_rollback每秒的回滚操作
#Questions每秒的的mysql_query函数查询
#Com_insert每秒的写入操作
#Com_delete每秒的删除操作
#Com_commit每秒的提交操作
#Bytes_sent每秒发送的字节
#Bytes_received每秒接受的字节
#Com_begin每秒的所有操作
case uptime中的$ 1
)
result =`$ {MYSQL_CONN} status 2> / dev / null | cut -f2 -d“:”| cut -f1 -d“T”`
echo $ result
;;
Com_update)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_update”| cut -d“|” -f3`
echo $ result
;;
Slow_queries)
result =`$ {MYSQL_CONN} status 2> / dev / null | cut -f5 -d“:”| cut -f1 -d“O”`
echo $ result
;;
Com_select)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_select”| cut -d“|” -f3`
echo $ result
;;
Com_rollback)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_rollback”| cut -d“|” -f3`
echo $ result
;;
问题)
result =`$ {MYSQL_CONN} status 2> / dev / null | cut -f4 -d“:”| cut -f1 -d“S”`
echo $ result
;;
Com_insert)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_insert”| cut -d“|” -f3`
echo $ result
;;
Com_delete)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_delete”| cut -d“|” -f3`
echo $ result
;;
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_commit”| cut -d“|” -f3`
echo $ result
;;
Bytes_sent)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Bytes_sent”| cut -d“|” -f3`
echo $ result
;;
Bytes_received)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Bytes_received”| cut -d“|” -f3`
echo $ result
;;
Com_begin)
result =`$ {MYSQL_CONN} extended-status 2> / dev / null | grep -w“Com_begin”| cut -d“|”
*)
echo“用法:$ 0(正常运行时间| Com_update | Slow_queries | Com_select | Com_rollback | 问题| Com_insert | Com_delete | Com_commit | Bytes_sent | Bytes_received | Com_begin)“
;;
ESAC
二,自定义监控项:
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
#mysql性能监控:
UserParameter = mysql.status [*],/ etc / zabbix / zabbix_agentd.d / mysql / mysql.sh $ 1
三,重启ZABBIX代理
再在|网页端的创建³³模板