首页 > 数据库 >7.2 zabbix实现Mysql的监控

7.2 zabbix实现Mysql的监控

时间:2022-09-02 02:22:07浏览次数:62  
标签:00 Mysql server 7.2 zabbix master mysql root

7.2 zabbix实现Mysql的监控

监控MySQL连接数、主从同步、同步延迟等。

:实现MySQL主从

1.1MySQL Master

mysql-server-5.7.xx:

vim /etc/mysql/mysql.conf.d/mysqld.cnf

[mysqld]

bind-address = 0.0.0.0

server-id = 10

log-bin = /var/lib/mysql/master-log

 

 

 

1.2MySQL Slave

mysql-server-5.7.xx:

vim /etc/mysql/mysql.conf.d/mysqld.cnf 

[mysqld]

bind-address = 0.0.0.0

server-id = 105

relay-log = /var/lib/mysql/relay-log

 

 

1.3MySQL Master授权账户

在mysql master服务器授权账户并导出数据,然后rsync到mysql backup服务器。

MySQL Master授权账户:

[root@mysql-master ~]#mysql

......

mysql> grant replication slave,replication client on *.* to magedu@'172.31.0.%' identified by "Mmagedu0!";

mysql> quit;

 

[root@mysql-master ~]#mysqldump --all-databases --single_transaction --flush-logs --master-data=2 --lock-tables > /opt/backup.sql

 

[root@mysql-master ~]#rsync /opt/backup.sql 172.31.0.105:/opt/

 

 

 

 

 

1.4MySQL slave导入数据:

在MySQL Slave服务器导入数据开始同步数据,Position位置在sql文件

[root@mysql-slave ~]#mysql

.......

mysql> change master to

    -> MASTER_HOST="172.31.0.104",

    -> MASTER_USER="magedu",

    -> MASTER_PASSWORD="Mmagedu0!",

    -> MASTER_LOG_FILE="master-log.000003",

    -> MASTER_LOG_POS=154;

Query OK, 0 rows affected, 2 warnings (0.08 sec)

 

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show slave status\G;

*************************** 1. row ***************************

               Slave_IO_State: Connecting to master

                  Master_Host: 172.31.0.104

                  Master_User: magedu

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: master-log.000003

          Read_Master_Log_Pos: 154

               Relay_Log_File: relay-log.000001

                Relay_Log_Pos: 4

        Relay_Master_Log_File: master-log.000003

             Slave_IO_Running: Connecting

            Slave_SQL_Running: Yes

 

 

 

 

zabbix-server、zabbbix-agent、Percona、mysql-master

官方文档及下载地址:

https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html #插件地 址

https://www.percona.com/downloads/ #安装包下载地址

https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html

#installation-instructions #安装教程

 

 

 

 

 

 

2.1安装配置zabbix-agent

[root@mysql-master ~]#apt install zabbix-agent -y

 

[root@mysql-master ~]#grep "^[a-Z]" /etc/zabbix/zabbix_agentd.conf

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix-agent/zabbix_agentd.log

LogFileSize=0

Server=172.31.0.101

ListenPort=10050

ServerActive=172.31.0.101

Hostname=172.31.0.104 

Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf

 

[root@mysql-master ~]#systemctl restart zabbix-agent

[root@mysql-master ~]#systemctl enable zabbix-agent

 

 

2.2安装配置Percona

[root@mysql-master ~]#

wget https://www.percona.com/downloads/percona-zabbix-templates_1.1.8-1.artful_all.deb

 

[root@mysql-master ~]#ls

percona-zabbix-templates_1.1.8-1.artful_all.deb

 

[root@mysql-master ~]#dpkg -i percona-zabbix-templates_1.1.8-1.artful_all.deb

dpkg-deb: error: 'percona-zabbix-templates_1.1.8-1.artful_all.deb' is not a Debian format archive

dpkg: error processing archive percona-zabbix-templates_1.1.8-1.artful_all.deb (--install):

 dpkg-deb --control subprocess returned error exit status 2

Errors were encountered while processing:

这是由于下载的包不完整造成,重新下载。

 

[root@mysql-master ~]#dpkg -i percona-zabbix-templates_1.1.8-1.artful_all.deb

Selecting previously unselected package percona-zabbix-templates.

(Reading database ... 72774 files and directories currently installed.)

Preparing to unpack percona-zabbix-templates_1.1.8-1.artful_all.deb ...

Unpacking percona-zabbix-templates (1.1.8-1.artful) ...

Setting up percona-zabbix-templates (1.1.8-1.artful) ...

 

[root@mysql-master ~]#dpkg -l | grep percona

ii  percona-zabbix-templates               1.1.8-1.artful                                  all          Percona Monitoring Plugins for Zabbix

 

[root@mysql-master ~]#

cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.conf.d/

 

[root@mysql-master ~]# systemctl restart zabbix-agent

 

安装php环境: 目前Perconaubuntu 自带的php 7.2不兼容,需要安装php 5.6版本

[root@mysql-master ~]# add-apt-repository ppa:ondrej/php

[root@mysql-master ~]#apt-get -y update

[root@mysql-master ~]#apt install -y php5.6 php5.6-mysql

 

 

创建mysql认证文件:

# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf

<?php

$mysql_user = 'root';

$mysql_pass = '';

?>

 

测试脚本能否获取数据:

[root@mysql-master /var/lib/zabbix/percona/scripts/]#./get_mysql_stats_wrapper.sh gg

18

 

[root@mysql-master /var/lib/zabbix/percona/scripts]#ps -ef | grep zabbix_agent

zabbix    12665      1  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd --foreground

zabbix    12678  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]

zabbix    12679  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]

zabbix    12680  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]

zabbix    12681  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]

zabbix    12682  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #4 [waiting for connection]

zabbix    12683  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #5 [waiting for connection]

zabbix    12684  12665  0 09:37 ?        00:00:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

root      12697   1526  0 09:39 pts/0    00:00:00 grep --color=auto zabbix_agent

 

 

 

2.3  配置mysql实现用户授权

mysql 进入数据库创建账户并授权

[root@mysql-master ~]# mysql

 

mysql> create database zabbix_server character set utf8 collate utf8_bin;

 

mysql> grant all privileges on zabbix_server.* to magedu@'172.31.%.%' identified by 'Mmagedu0!';

 

mysql> flush privileges;

 

mysql> quit

 

 

 

 

2.4  Zabbix-server配置

(1) 修改Zabbix-server配置文件

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

DBHost=172.31.0.104

DBName=172.31.0.104

DBUser=magedu

DBPassword=Mmagedu0!

DBPort=3306

 

(2) 初始化zabbix_server数据库,使之成为zabbix数据库。

[root@zabbix-server ~]#zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -umagedu -pMmagedu0! -h172.31.0.104 zabbix_server

mysql: [Warning] Using a password on the command line interface can be insecure.

登录不上mysql有很大可能是在mysql配置文件的的bind-address=127.0.0.1

 

 

(3) 确认授权用户相关信息

[root@zabbix-server /var/log]#find / -name zabbix.conf.php

[root@zabbix-server /var/log]#vim /etc/zabbix/web/zabbix.conf.php

<?php

// Zabbix GUI configuration file.

global $DB;

$DB['TYPE']     = 'MYSQL';

$DB['SERVER']   = '172.31.0.104';

$DB['PORT']     = '3306';

$DB['DATABASE'] = 'zabbix_server';

$DB['USER']     = 'magedu';

$DB['PASSWORD'] = 'Mmagedu0!';

// Schema name. Used for IBM DB2 and PostgreSQL.

$DB['SCHEMA'] = '';

 

$ZBX_SERVER      = '172.31.0.101';

$ZBX_SERVER_PORT = '10051';

$ZBX_SERVER_NAME = '172.31.0.101';

 

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

 

 

查看日志很重要,日志目录一般在配置文件中有说明。

 

 

(4) 检查在zabbix-server上能否登录

[root@zabbix-server ~]#mysql -umagedu -pMmagedu0! -h172.31.0.104

mysql: [Warning] Using a password on the command line interface can be insecure.

.......

 

 

2.5 各个主机之间开启时间同步,同步到网络时间,重启服务

 

timedatectl set-timezone AsiaShanghai

systemctl restart systemd-timesyncd.service

 

[root@zabbix-server ~]#systemctl restart apache2 zabbix-server

[root@mysql-master ~]#systemctl restart zabbix-agent mysql

[root@mysql-slave ~]#systemctl restart mysql

 

三 、web网页端配置

3.1zabbix web登录

http://172.31.0.101/zabbix/

 

 

 

 

查看日志

[root@zabbix-server /var/log]#tail -f syslog

[root@zabbix-server /var/log]#tail /var/log/zabbix/zabbix_server.log

 

 

修改Zabbix-server配置

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

DBHost=172.31.0.104

DBName=172.31.0.104

DBUser=magedu

DBPassword=Mmagedu0!

DBPort=3306

 

初始化zabbix_server数据库,使之成为zabbix数据库。

[root@zabbix-server ~]#zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -umagedu -pMmagedu0! -h172.31.0.104 zabbix_server

mysql: [Warning] Using a password on the command line interface can be insecure.

 

确认授权用户相关信息

[root@zabbix-server /var/log]#find / -name zabbix.conf.php

[root@zabbix-server /var/log]#vim /etc/zabbix/web/zabbix.conf.php

<?php

// Zabbix GUI configuration file.

global $DB;

$DB['TYPE']     = 'MYSQL';

$DB['SERVER']   = '172.31.0.104';

$DB['PORT']     = '3306';

$DB['DATABASE'] = 'zabbix_server';

$DB['USER']     = 'magedu';

$DB['PASSWORD'] = 'Mmagedu0!';

// Schema name. Used for IBM DB2 and PostgreSQL.

$DB['SCHEMA'] = '';

 

$ZBX_SERVER      = '172.31.0.101';

$ZBX_SERVER_PORT = '10051';

$ZBX_SERVER_NAME = '172.31.0.101';

 

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

 

 

查看日志很重要,日志目录一般在配置文件中有说明。

 

 

检查在zabbix-server上能否登录

[root@zabbix-server ~]#mysql -umagedu -pMmagedu0! -h172.31.0.104

mysql: [Warning] Using a password on the command line interface can be insecure.

.......

 

3.2zabbix web导入Percona模板

 

 

 

 

 

 

 

 

 

 

3.3创建groups

 

 

 

 

 

3.4zabbbix web添加主机

 

 

 

 

3.5zabbix web对主机关联模板

 

 

 

 

 

3.6:验证MySQL监控数据:

Percona模板中的监控项默认是五分钟收集一次监控项数据,会结合脚本检查agent上报错数据的文件的时间戳是否超过五分钟,安装percona脚本自动生成,脚本位置:/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh。

 

zabbix-server测试

[root@zabbix-server ~]#apt install zabbix-get

[root@zabbix-server ~]#zabbix_get -s 172.31.0.104 -p 10050 -k "MySQL.Key-read-requests"

6

图形没有获取到数据

 

 

更改一下监控模式,每页全钩上。

 

 

翻下来点击批量更新

 

 

弹出下面的窗口:类型钩上,然后选择主动模式。

 

 

 

 

等几分钟,结果如下 :

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:00,Mysql,server,7.2,zabbix,master,mysql,root
From: https://www.cnblogs.com/biaoming534/p/16648412.html

相关文章

  • 7.1 zabbix实现Nginx的监控
    7.实现Nginx、Mysql的监控7.1zabbix实现Nginx的监控脚本:nginx_status.sh模板:nginx-template-magedu-jiege.xml对nginx的活动连接和当前状态等运行状态进行监控配置示......
  • 6. 部署Zabbix监控
    6. 部署Zabbix监控 6.1 安装mysql[root@ubuntu~]#hostnamectlset-hostnamemysql-master;exit[root@mysql-master ~]#aptinstall-ymysql-server #配置my......
  • zabbix
    目录zabbix部署zabbix部署lamp已构建完成解压mysql8.0[root@localhostlocal]#tarxfmysql-8.0.28-linux-glibc2.12-x86_64.tar.xz修改所属主和组[root@localho......
  • zabbix_server优化
    造成zabbix性能下降的因素如表所示zabbix性能低下的表现1.   zabbix队列有太多被延迟的item,可以通过administration-queue查看2.   zabbix绘图中经常出现断图,一些i......
  • zabbix4.0.5自动安装脚本
    拿包请在下方留言拿包请在下方留言环境:centos7服务器可以上外网即可 #自动化部署zabbix脚本#!/bin/bash#版本详情#1.zabbix-4.0.5.tar.gz#2.nginx-1.16.1.tar......
  • Grafana安装配置和简单图标实现(使用MySQL数据源)
    grafana介绍Grafana是一个开源的度量分析与可视化套件,纯JavaScript开发的前端工具,通过访问库(如InfluxDB),展示自定义报表、显示图表等。它的UI十分灵活,有丰富的插件和模板,功......
  • 记一次因网络变更导致zabbix连接es报400和404
    背景zabbix历史数据存储到es集群,正常工作中的时候,因网络变更导致zabbixserver连接不上es,zabbix日志首先报400错误,之后一直404,es那边报查询相关的错误。现象如下图:......
  • MySQL保留字
    {"action","add","aggregate","all","alter","after","and","as","asc","avg","avg_row_length","auto_increment","between",......
  • Mysql主从复制
    遇到的问题:#查看slave状态showslavestatus\G显示IO线程为连接:Slave_IO_Running:NO解决思路:1、检查changemasterto里用户名、密码、日志位置等信息;如果不行就......
  • 安装Zabbix客户端zabbix-agent2
    Ubuntu系统:下载链接:http://mirrors.aliyun.com/zabbix/zabbix/6.0/ubuntu/pool/main/z/zabbix/?spm=a2c6h.25603864.0.0.5e804167HzHeoe以ubuntu20.04的64位系统为例:Inde......