线上MySQL监控平台PMM部署

作者:陈太闯 于 2020年05月20日 发布在分类/ 运维

MYSQL监控平台PMM部署

PMM简介

Percona Monitoring and Management (PMM) 是一款开源的用于管理和监控MySQLMongoDB性能的开源平台,通过PMM客户端收集到的DB监控数据用第三方软件Grafana画图展示出来。在这个产品之前,Percona提供了ZabbixCacti的图形模板,也许是考虑到了用户部署起来繁琐等问题,Percona发布了PMM Docker镜像,用户只需要下载镜像运行就全部搞定,开箱即用相当easy


PMM官方文档资源获取

https://learn.percona.com/hubfs/Manuals/Percona_Monitoring_And_Management_PMM/PMM%201.17/Percona-Monitoring-And-Management-1.17.0.pdf

PMM Server端安装部署

·         我们的部署是基于docker容器的方式实现,简单高效

1.    注意,需要开启linux内核的ip_forward转发功能

#把文件的内容由0修改为1。禁用IP转发则把1改为0。

echo 1 > /proc/sys/net/ipv4/ip_forward ##

sysctl -p /etc/sysctl.conf ##


一、首先安装pmm server

我们这边使用docker安装pmm server 方便快捷

使用Docker运行PMM服务器

PMM服务器的Docker映像位于percona / pmm-server公共存储库中。如果您打算从Docker镜像运行PMM Server,则主机必须能够运行Docker 1.12.6或更高版本,并具有网络访问权限。

注意:确保主机的防火墙和路由规则不限制Docker容器


监控服务器安装docker

yum install -y docker systemctl start docker


## 若以上 sh get-pmm.sh 安装方式不能安装 dcoker 镜像,可以使用如下方式安装。####

设置阿里云镜像库加速docker下载

mkdir -p /etc/docker cat >/etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://kli7phym.mirror.aliyuncs.com"] } EOF systemctl daemon-reload systemctl restart docker


1步。拉取PMM服务器映像

docker pull percona/pmm-server: latest


#迁移docker目录

systemctl stop docker

mkdir -p /data

cp -arf /var/lib/docker /data/docker

mv /var/lib/docker /var/lib/docker.bak

ln -s /data/docker /var/lib/docker

systemctl start docker


2步。创建一个PMM数据容器

docker create \ -v /opt/prometheus/data \ -v /opt/consul-data \ -v /var/lib/mysql \ -v /var/lib/grafana \ --name pmm-data \ percona/pmm-server: latest / bin/true


3步。创建和运行 PMM Server Container

方式一: 

docker run -d \ -p 80:80 \ --volumes-from pmm-data \ --name pmm-server \ --restart always \ percona/pmm-server:latest


方式二:

docker run -d -p 80:80 --volumes-from pmm-data --name pmm-server --restart always percona/pmm-server:1.17.0


至此 pmm 构建完毕


验证PMM Server端部署是否正常

# docker ps -a

# docker images


打开浏览器http://yourip即可

Component

URL

PMM 首页

http://yourip

Query Analytics ( 慢日志分析)

http://yourip/qan/

Metrics Monitor (Grafana)

http://yourip/graph/

user name: admin

password: admin

Orchestrator

http://yourip/orchestrator


二、被监控MySQL服务端安装pmm-client

(pmm-client与percona-toolkit请自行到percona官方下载)

在要被监控的MySQL服务器上安装!

1、获取PMM Client客户端软件包,并安装!

## --nogpgcheck 忽略gap key错误

yum install pmm-client --nogpgcheck


安装pmm-client

# rpm -ivh https://www.percona.com/downloads/pmm/1.0.7/binary/redhat/7/x86_64/pmm-client-1.0.7-1.x86_64.rpm

#wget https://www.percona.com/downloads/pmm/1.17.0/binary/redhat/7/x86_64/pmm-client-1.17.0-1.el7.x86_64.rpm #yum localinstall pmm-client-1.17.0-1.el7.x86_64.rpm


安装percona工具

#wget -c https://www.percona.com/downloads/percona-toolkit/3.0.13/binary/redhat/7/x86_64/percona-toolkit-3.0.13-1.el7.x86_64.rpm

#yum localinstall percona-toolkit-3.0.13-1.el7.x86_64.rpm


2、连接PMM ClientPMM Server

#pmm-admin config --server $PMM-SERVER-IP:PORT --server-user abc --server-password password

[root@mysql opt]#

pmm-admin config --server 10.252.216.3

OK, PMM server is alive.


PMM Server | 10.252.216.3

Client Name | csx-dev-basic-data-master

Client Address | 10.252.193.21


# cat /usr/local/percona/pmm-client/pmm.yml

server_address: 10.252.216.3

client_address: 10.252.193.21

bind_address: 10.252.193.21

client_name: csx-dev-basic-data-master_10.252.193.21


3、增加pmm-client监控账号

mysql -u root -p

mysql> GRANT SELECT, RELOAD, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO ' pmm '@'localhost' IDENTIFIED BY ' Yh2018b2b%@ ';

mysql> GRANT SELECT, UPDATE, DELETE, DROP ON `performance_schema`.* TO ' pmm '@' localhost ';


4、增加pmm客户端监控mysqlpmm服务器

Verify that MySQL user exists and has the correct privileges.

Use additional flags --user, --password, --host, --port, --socket if needed.


pmm-admin add mysql --user pmm --password PM2018%@

[linux:metrics] OK, already monitoring this system.

[mysql:metrics] OK, now monitoring MySQL metrics using DSN pmm:***@unix(/data/mysql/mysql.sock)

[mysql:queries] OK, now monitoring MySQL queries from slowlog using DSN pmm:***@unix(/data/mysql/mysql.sock)


5、查看结果

# pmm-admin list

pmm-admin 1.17.0


PMM Server | 10.252.216.3

Client Name | csx-dev-basic-data-master_10.252.193.21

Client Address | 10.252.193.21

Service Manager | linux-systemd

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

SERVICE TYPE NAME LOCAL PORT RUNNING DATA SOURCE OPTIONS

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

mysql:queries csx-dev-basic-data-master_10.252.193.21 - YES pmm:***@unix(/data/mysql/mysql.sock) query_source=slowlog, query_examples=true, slow_log_rotation=true, retain_slow_logs=1

linux:metrics csx-dev-basic-data-master_10.252.193.21 42000 YES -

mysql:metrics csx-dev-basic-data-master_10.252.193.21 42002 YES pmm:***@unix(/data/mysql/mysql.sock)


四、Email报警

报警是通过Grafana发出的,内置有EmailWebhookslackpagerduty,可惜没有微信,老外应该没听过这个玩意,所以这里我介绍一下Email报警是如何配置的。

 

1 、首先进入docker shell里,见下面截图:

# docker ps

# docker exec -it 75d3be875849 /bin/bash

 

2 、修改/etc/grafana/grafana.ini配置文件:

####################################   SMTP / Emailing ##########################

[smtp]

enabled = true

host =   smtp.126.com:25

user =   chunyang_he@126.com

password =   123456

;cert_file =

;key_file =

;skip_verify =   false

from_address =   chunyang_he@126.com

 

3 、重启Docker生效

# docker stop 75d3be875849

# docker start 75d3be875849

 

4 、页面配置

这一步步骤繁琐,具体请参考视频演示:http://pan.baidu.com/s/1i4OyGo1


分享到朋友圈 分享到微信
发表评论
验证码