前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >zabbix监控mysql各项指标

zabbix监控mysql各项指标

作者头像
全栈程序员站长
发布2022-06-29 09:32:22
1K0
发布2022-06-29 09:32:22
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

准备两台虚拟机

zabbix-server(服务端 ip:192.168.176.138)

zabbix-agent(客户端 ip:192.168.176.139)

两台分别上传zabbix.repo到/etc/yum.repos.d下面

安装前工作

代码语言:javascript
复制
// 关闭防火墙
systemctl stop firewalld
setenforce 0
// 时间同步
yum -y install ntpdate
ntpdate pool.ntp.org

服务端

代码语言:javascript
复制
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb mariadb-server
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> Ctrl-C -- exit!
[root@localhost ~]# zcat  /usr/share/doc/zabbix-server-mysql-4.4.10/create.sql.gz |mysql -uzabbix -pzabbix zabbix
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
[root@localhost ~]# cat  /etc/zabbix/zabbix_server.conf |grep -v "^#"|sed '/^$/d'|grep DB
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
[root@localhost ~]# systemctl start httpd zabbix-server zabbix-agent
[root@localhost ~]# netstat  -lptnu|egrep "80|10050|10051"
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      2710/zabbix_agentd  
tcp6       0      0 :::10050                :::*                    LISTEN      2710/zabbix_agentd  
tcp6       0      0 :::80                   :::*                    LISTEN      2704/httpd 
[root@localhost ~]# vim /etc/php.ini
date.timezone =Asia/Shanghai //修改时区,tips:前面的分号去掉
[root@localhost ~]# systemctl restart httpd //修改完时区一定重启httpd

http;//192.168.176.137/zabbix 访问

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

客户端

代码语言:javascript
复制
[root@localhost ~]# yum -y install zabbix-agent mariadb mariadb-server httpd bc
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
[root@localhost ~]# cat /etc/zabbix/zabbix_agentd.conf |grep -v "^#"|sed '/^$/d'
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.176.138 //改为服务端ip
ServerActive=192.168.176.138 //改为服务端ip
Hostname=Zabbix server
[root@localhost ~]# systemctl start zabbix-agent mariadb httpd
[root@localhost ~]# mkdir -p /etc/zabbix/scripts
[root@localhost ~]# cd /etc/zabbix/scripts/
[root@localhost scripts]# vim mysql_byte.sh
[root@localhost scripts]# cat mysql_byte.sh 
#!/bin/bash
case $1 in
byte_sent)
	mysqladmin  extended-status|grep -w "Bytes_sent"|awk  '{print $4}'
	;;
byte_recv)
	mysqladmin  extended-status|grep -w "Bytes_received"|awk  '{print $4}'
	;;
esac
[root@localhost scripts]# vim mysql_in_r.sh
[root@localhost scripts]# cat mysql_in_r.sh 
#!/bin/bash

mysql -e "show global status like 'innodb%read%';" | grep Innodb_buffer_pool_read_requests | awk '{print $2}'
[root@localhost scripts]# vim pv_uv.sh
[root@localhost scripts]# cat pv_uv.sh 
#!/bin/bash
case $1 in
	uv|UV)
		cat /var/log/httpd/access_log |awk '{print $1}'|sort|uniq|wc -l
	;;
	pv|PV)
		cat /var/log/httpd/access_log |awk '{print $1}' |wc -l
	;;
esac
[root@localhost scripts]# vim mysql_qps.sh
[root@localhost scripts]# cat mysql_qps.sh 
#!/bin/bash
q1=`mysql -s -e 'show global status like "Question%";'|awk '{print $NF}'`
t1=`uptime |awk '{print $5}'|sed "s/,//g"|awk -F ":" '{print $1*3600+$2*60}'`

n=`echo "scale=4;$q1/$t1"|bc`
echo $n
[root@localhost scripts]# vim mysql_tps.sh
[root@localhost scripts]# cat mysql_tps.sh 
#!/bin/bash
c1=`mysql -s -e "show global status like 'Com_commit';"|awk '{print $NF}'`
r1=`mysql -s -e "show global status like 'Com_rollback';"|awk '{print $NF}'`
t1=`uptime |awk '{print $5}'|sed "s/,//g"|awk -F ":" '{print $1*3600+$2*60}'`

n1=$(($c1+$r1))
n=`echo "scale=4;$n1/$t1"|bc`

echo $n
[root@localhost scripts]# vim /etc/zabbix/zabbix_agentd.d/mysql.conf 
[root@localhost scripts]# cat /etc/zabbix/zabbix_agentd.d/mysql.conf 
UserParameter=mysql.byte[*],/bin/bash /etc/zabbix/scripts/mysql_byte.sh $1
UserParameter=mysql.in.r,/bin/bash /etc/zabbix/scripts/mysql_in_r.sh  $1
UserParameter=pv_uv[*],/bin/bash /etc/zabbix/scripts/pv_uv.sh $1
UserParameter=qps,/bin/bash /etc/zabbix/scripts/mysql_qps.sh $1
UserParameter=tps,/bin/bash /etc/zabbix/scripts/mysql_tps.sh $1
代码语言:javascript
复制
//服务端安装zabbix-get
[root@localhost ~]# yum -y install zabbix-get
[root@localhost ~]# zabbix_get -s 192.168.176.139 -k mysql.byte[byte_sent]
ZBX_NOTSUPPORTED: Unsupported item key. //出错
//出错解决 客户端上操作
[root@localhost scripts]# chmod -R 777 /etc/zabbix/scripts/
[root@localhost scripts]# systemctl restart zabbix-agent
//服务端
[root@localhost ~]# zabbix_get -s 192.168.176.139 -k mysql.byte[byte_sent]
40258

zabbix网页监控数据

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/132440.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年6月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 准备两台虚拟机
    • zabbix-server(服务端 ip:192.168.176.138)
      • zabbix-agent(客户端 ip:192.168.176.139)
        • 安装前工作
        • 服务端
        • 客户端
        • zabbix网页监控数据
    相关产品与服务
    云数据库 MariaDB
    腾讯云数据库 MariaDB(TencentDB for MariaDB) 让您轻松在云端部署、使用 MariaDB 数据库。MariaDB 是在 MySQL 版权被 Oracle 收购后,由 MySQL 创始人 Monty 创立,其版权授予了“MariaDB基金会(非营利性组织)”以保证 MariaDB 永远开源,良好的开源策略,是企业级应用的最优选择,主流开源社区系统/软件的数据库系统,均已默认配置 MariaDB。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档