zabbix监控mysql各项指标

zabbix监控mysql各项指标准备两台虚拟机zabbix-server(服务端ip:192.168.176.138)zabbix-agent(客户端ip:192.168.176.139)两台分别上传zabbix.repo到/etc/yum.repos.d下面安装前工作//关闭防火墙systemctlstopfirewalldsetenforce0//时间同步yum-yinstallntpdatentpdatepool.ntp.org服务端[root@localhost~]#yum-y

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

准备两台虚拟机

zabbix-server(服务端 ip:192.168.176.138)

zabbix-agent(客户端 ip:192.168.176.139)

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

安装前工作

// 关闭防火墙
systemctl stop firewalld
setenforce 0
// 时间同步
yum -y install ntpdate
ntpdate pool.ntp.org

服务端

[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 访问

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

客户端

[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
//服务端安装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.net/132440.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Spark调研笔记第4篇 – PySpark Internals

    Spark调研笔记第4篇 – PySpark Internals

    2022年2月5日
    46
  • scratch编程小游戏——黄金矿工

    黄金矿工的玩法就是操控一个不断摆来摆去的钩子去挖出黄金,现在我们就来用scratch编一个黄金矿工首先新建好变量:矿车要画出许多的造型:代码:钩爪的绳索是这个游戏最为复制的一点,方法是移动后画出一条线,返回时用背景一样的颜色来覆盖,我们首先来画出造型:红色的是中心位置代码如下:(此代码需要用到一部分自定义,不懂的见文章末尾链接)自定义部分是这个代码的核心:接下来是黄金,造型的话要画出三个:大、中、小各一个代码如下:黄金代码是程序中非常重要的一环,一定不要有差错现

    2022年4月4日
    2.3K
  • 分部类(Partial Classes)

    分部类(Partial Classes)

    2021年7月27日
    70
  • 排序二叉树及其遍历「建议收藏」

    排序二叉树及其遍历「建议收藏」  所谓建立排序二叉树就是,就是将各结点数据元素顺序插到一棵二叉树中,在插入的过程中,始终保持二叉树中每个结点的值都大于其左子树上每个结点的值,而小于或等于其右子树上每个结点的值,每个结点信息包括结点数据(结点值)、左子树指针、右子树指针。程序执行的过程中,bt指针始终指向根结点,p指针指向当前已找到的结点,q指针不断向下寻找新的结点。  为实现二叉树的非递归算法,需要设置一个栈来保存指向结点

    2022年7月25日
    4
  • java菜鸟教程+视频笔记

    java菜鸟教程+视频笔记1、java中局部变量是在栈上分配的;2、数组是储存在堆上的对象,可以保存多个同类型变量;3、在Java语言中,所有的变量在使用前必须声明。4、局部变量没有默认值,所以局部变量被声明后,必须经过初始化,才可以使用。5、内置类型有默认值,引用对象的默认值是null;6、非静态实例变量、非静态方法是通过对象实例进行调用的,不能直接从静态方法中调用;比如java源文件中main方法中不可以直接调用非静态…

    2022年6月14日
    26
  • goland最新激活码[在线序列号]

    goland最新激活码[在线序列号],https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    60

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号