centos7中安装zabbix监控mysql主从状态

安装环境:两台虚拟主机
安装步骤:
首先
做mysql主从(详解下面链接)
https://blog.csdn.net/RoninLJH/article/details/106753020

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# ntpdate pool.ntp.org

配置yum源

[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=0

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0

安装zabbix、httpd

[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql  httpd 

登录mysql、创建zabbix数据库,并授权

[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;

导入数据库数据

[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.4.10/create.sql.gz | mysql -uzabbix -pzabbix zabbix

修改zabbix配置文件

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf

DBPassword=zabbix

修改时间戳

[root@localhost ~]# vim /etc/php.ini

date.timezone =Asia/Shanghai

启动httpd、zabbix

[root@localhost ~]# systemctl enable httpd zabbix-server 
[root@localhost ~]# systemctl start httpd zabbix-server 
[root@localhost ~]# netstat -anpt |egrep "80|10051"

centos7中安装zabbix监控mysql主从状态_第1张图片
centos7中安装zabbix监控mysql主从状态_第2张图片
centos7中安装zabbix监控mysql主从状态_第3张图片
centos7中安装zabbix监控mysql主从状态_第4张图片

**

汉化

**

centos7中安装zabbix监控mysql主从状态_第5张图片
上传语言包

[root@localhost ~]# cd /usr/share/zabbix/assets/fonts/
[root@localhost fonts]# rm -rf graphfont.ttf 
[root@localhost fonts]# mv simkai.ttf graphfont.ttf

centos7中安装zabbix监控mysql主从状态_第6张图片

监控mysql

安装zabbix监控端(注意:需要配置yum源,同server端一样)

[root@localhost ~]# yum -y install zabbix-agent

修改配置文件

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.33.137
ServerActive=192.168.33.173

开启zabbix

[root@localhost ~]# systemctl enable zabbix-agent
[root@localhost ~]# systemctl start zabbix-agent

设置k(需要在从库里授权一个用户)

MariaDB [(none)]> grant all on *.* to ljh@'localhost' identified by 'ljh';
[root@localhost ~]# mkdir /etc/zabbix/scripts
[root@localhost ~]# vim /etc/zabbix/scripts/check_mysql.sh
----------------------------------
#!/bin/bash
case $1 in
#mysql主从是否正常
		slave_yes)
                mysql -uljh -pljh-e "show slave status \G;" | grep "Yes" |wc -l
                ;;
#mysql是否存活
        slave_status)
                netstat -anpt |grep mysqld |wc -l
                ;;
#mysql吞吐量 发送
        Bytes_sent)
                mysqladmin -uljh -pljh  extended-status |grep Bytes_sent |awk '{print $4}'
                ;;
#mysql吞吐量 接收
        Bytes_received)
                mysqladmin -uljh -pljh  extended-status |grep Bytes_received |awk '{print $4}'
                ;;
#表大小
        tb_size)
                mysql -uljh -pljh -e "select data_length from information_schema.tables where table_schema='mysql' and table_name='db';" | sed -n '2p'
                ;;
#库大小
        db_size)
                mysql -uljh -pljh -e "select sum(data_length) as xx from information_schema.tables where table_schema='mysql'" |sed '1d'
                ;;
#每秒请求数
        qps)
                mysqladmin status | awk '{print $6/$2}'
                ;;
#事务数
        tps)
                commit=`mysqladmin extended-status |grep Com_commit |awk '{print $4}'`
                rollback=`mysqladmin extended-status |grep -w Com_rollback |awk '{print $4}'`
                uptime=`mysqladmin status | awk '{print $2}'`
                t=`expr $commit + $rollback`
                echo `expr $t / $uptime`
                ;;
esac

-----------------------------------

[root@localhost ~]# chmod +x /etc/zabbix/scripts/check_mysql.sh

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.d/mysql.conf
-----------------------------
UserParameter=mysql_status[*],/etc/zabbix/scripts/check_mysql.sh $1
------------------------------
[root@localhost ~]# systemctl restart zabbix-agent
[root@localhost ~]# chmod +s /bin/netstat

注意:监控的主机ip为节点ip
centos7中安装zabbix监控mysql主从状态_第7张图片
在这里插入图片描述
在这里插入图片描述
centos7中安装zabbix监控mysql主从状态_第8张图片
centos7中安装zabbix监控mysql主从状态_第9张图片
查看
centos7中安装zabbix监控mysql主从状态_第10张图片
添加触发器
centos7中安装zabbix监控mysql主从状态_第11张图片
centos7中安装zabbix监控mysql主从状态_第12张图片
centos7中安装zabbix监控mysql主从状态_第13张图片
测试触发器报警

[root@localhost ~]# systemctl stop mariadb

centos7中安装zabbix监控mysql主从状态_第14张图片

[root@localhost ~]# systemctl start mariadb

centos7中安装zabbix监控mysql主从状态_第15张图片
**

其他监控项同理(注意qps值是浮点数添加监控项的时候要手动更改)

**
centos7中安装zabbix监控mysql主从状态_第16张图片

你可能感兴趣的:(监控,Zabbix,监控)