PMM实现监控Mysql-MGR

一、docker安装PMM服务端

1、安装yum配置单元
 # 如果已安装,略过此步
 yum install -y yum-utils   #yum配置单元
2、配置docker阿里云yum源
#配置docker阿里云yum源
[root@rocky-18 yum.repos.d]# vim aliyun_docker.repo 
[root@rocky-18 yum.repos.d]# yum repolist

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

3、安装依赖包
[root@rocky-18 yum.repos.d]# yum install -y device-mapper-persistent-data lvm2    #驱动映射包,和lvm逻辑卷管理命令
4、启动docker
[root@rocky-18 yum.repos.d]# systemctl enable --now docker
5、拉取pmm-server镜像
[root@rocky-18 ~]# docker pull percona/pmm-server:latest
latest: Pulling from percona/pmm-server
2d473b07cdd5: Pull complete 
bf7875dc8ab7: Pull complete 
Digest: sha256:975ad1b212771360298c1f9e0bd67ec36d1fcfd89d58134960696750d73f4576
Status: Downloaded newer image for percona/pmm-server:latest
docker.io/percona/pmm-server:lates
[root@rocky-18 ~]# docker images
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
percona/pmm-server   latest    3d3c8937808d   4 weeks ago   1.94GB

image

6、运行pmm-server容器
[root@rocky-18 ~]# mkdir /opt/prometheus/data -p
[root@rocky-18 ~]# 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
203cd171607c2534fac061a3427a23b4ab2fc5a245e1abc031945e493cb427e0
[root@rocky-18 ~]# docker run --detach --restart always \
> --publish 443:443 \
> --volumes-from pmm-data \
> --name pmm-server \
> percona/pmm-server:latest
b89afbf00e8d877e591bc055d423e4f1db94f9c98cd70bccf5eaacd88db6d6b9
[root@rocky-18 ~]# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                CREATED          STATUS                    PORTS                                           NAMES
b89afbf00e8d   percona/pmm-server:latest   "/opt/entrypoint.sh"   39 seconds ago   Up 38 seconds (healthy)   80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   pmm-server
203cd171607c   percona/pmm-server:latest   "/bin/true"            6 minutes ago    Created                                                                   pmm-data

image

7、浏览器访问pmm-server grafana

默认用户名admin 密码admin 需要修改

image

二、在节点安装pmm-client

请确保MGR已经建立成功,并且认证方式是:mysql_native_password,建立MGR可参考https://blog.51cto.com/dayu/5656612

1、所有节点安装pmm-client
[root@mysql1 ~]# yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm                            #配置yumyuan
[root@mysql3 ~]# yum install -y pmm2-client

2、注册pmm-client客户端到pmm-server上(所有节点步骤相同)
[root@mysql1 ~]# pmm-admin config --server-insecure-tls --server-url=https://admin:admin@192.168.100.18:443
Checking local pmm-agent status...
pmm-agent is running.
Registering pmm-agent on PMM Server...
Registered.
Configuration file /usr/local/percona/pmm2/config/pmm-agent.yaml updated.
Reloading pmm-agent configuration...
Configuration reloaded.
Checking local pmm-agent status...
pmm-agent is running.

# 另外两个节点执行同样命令注册pmm-client客户端到pmm-server上

#说明:
a)、192.168.100.18是PMM服务器的地址。
b)、443是默认端口号。
c)、admin/admin是默认的PMM用户名和密码。这是您用于登录PMM用户界面的同一个帐户
d)、server-insecure-tls客户必须使用安全通道向PMM服务器注册。如果使用http作为服务器URL,PMM将尝试通过https在端口443上进行连接。如果无法建立TLS连接,则会出现错误,您必须使用https以及相应的安全端口。

image

image

image

3、创建并授权pmm账号密码连接数据库
[root@mysql1 ~]# mysql
mysql> SELECT * FROM performance_schema.replication_group_members;  #查看MGR连接是否正常
mysql> create user pmm@'192.168.100.%' identified by '123456';    #在MGR中创建用于数据采集的用户,接入到PMM中
mysql> grant select,process,replication client,reload,backup_admin on *.* to pmm@'192.168.100.%';      # 授权
mysql> UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME LIKE '%statements%';           # 开启MySQL的performance_schema的SQL语句监控指标采集项

mysql> select * from performance_schema.setup_consumers  WHERE NAME LIKE '%statements%';      

mysql> SET persist innodb_monitor_enable = all;     #启用MySQL的innodb启用计数器,其参数后面可跟计数对象如log,metadata_table_handles_opened,metadata_table_handles_closed等,如果设置为ALL代表统计所有选项,负面影响就是由于每个计数器都会增加一定程度的运行时开销,因此请在生产服务器上尽量保守使用计数器功能,根据实际需求,开启特定对象的监控,用来诊断分析定位问题或监控特定指标项。

4、添加MGR实例到监控中
方法一:通过web页面方式添加MGR实例到监控中

image

image

image

image

image

方法二:可通过命令行方式增加监控的数据库
# 在安装pmm-client客户端的主机上,添加监控的MySQL实例

pmm-admin add mysql --username=username --password=password --tls --tls-skip-verify --tls-ca=pathtoca.pem --tls-cert=pathtocert.pem --tls-key=pathtocertkey.pem --server-url=http://admin:admin@172.16.130.12 --query-source=perfschema name 172.16.130.53:3308

# 如果开启了MGR的慢日志,则可以通过下列命令添加慢日志监控

image

三、监控选项:

image

image

四、卸载

1、卸载PMM-CLIENT
#yum安装方式和二进制包方式
yum remove -y pmm2-client
yum remove -y percona-release
2、取消到pmm-server的注册
pmm-admin unregister --force

​ 取消监控的节点或者客户端:

pmm-admin remove <service-type> <service-name>
service-type:
mysql, mongodb, postgresql, proxysql, haproxy, external
3、docker方式卸载pmm-client 总结起来3个字,1停2删3清
docker stop pmm-client    #停止pmm-client 容器
docker rm pmm-client      #删除pmm-client 容器
docker rmi $(docker images | grep "percona/pmm-client" | awk {'print $3'}) --force   #删除pmm-client的docker镜像
docker volume rm pmm-client-data    清理卷组中的数据
posted @ 2022-09-18 20:34  大雨转暴雨  阅读(290)  评论(0编辑  收藏  举报