安装和使用PMM(Percona Monitoring and Management)
前言:PMM作为MySQL的监控系统,主要是用promethues和grafana两个工具进行定制的监控。
PMM分两个版本:PMM1和PMM2,PMM1控制力度比较好一些,PMM2界面比较丰富友好一些。该工具分PMM Server和PMM Client。
PMM2的安装
安装PMM Server with Docker
1.拉取镜像
sudo docker pull percona/pmm-server:2
2.创建一个永久数据容器
sudo docker create --volume /srv \ --name pmm-data percona/pmm-server:2 /bin/true
3.运行镜像,启动PMM Server
sudo docker run --detach --restart always \ --publish 443:443 --publish 80:80 \ --volumes-from pmm-data --name pmm-server \ percona/pmm-server:2
4.web浏览器中,访问服务器http://xx.xx.xx.xx:80,访问默认用户密码:admin / admin,第一次进去要修改下密码。
安装PMM Client
1.用yum安装,配置仓库
sudo yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
2.安装PMM Client 包
sudo yum install -y pmm2-client
或直接用rpm包安装
1.下载rpm包 wget https://downloads.percona.com/downloads/pmm2/2.16.0/binary/redhat/7/x86_64/pmm2-client-2.16.0-6.el7.x86_64.rpm 2.安装rpm包 rpm -ivh pmm2-client-2.16.0-6.el7.x86_64.rpm
配置
1.注册节点到PMM服务
pmm-admin config --server-insecure-tls --server-url=https://admin:admin@X.X.X.X:443
1)x.x.x.x is the address of your PMM Server.
2)443是默认端口
3)admin/admin是登录PMM Server页面的用户名密码
2.配置和加服务,首先创建用户
CREATE USER \'pmm\'@\'localhost\' IDENTIFIED BY \'pass\' WITH MAX_USER_CONNECTIONS 10; GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO \'pmm\'@\'localhost\';
3.选择和配置一个数据源
.慢查询数据源,需配置的配置文件参数(预备工作)
slow_query_log=ON log_output=FILE long_query_time=1 log_slow_admin_statements=ON log_slow_slave_statements=ON
#动态设置
SET GLOBAL slow_query_log = 1;
SET GLOBAL log_output = \'FILE\';
SET GLOBAL long_query_time = 1;
SET GLOBAL log_slow_admin_statements = 1;
SET GLOBAL log_slow_slave_statements = 1;
.Performance Schema数据源,需配置的配置文件参数(预备工作)
performance_schema=ON performance-schema-instrument=\'statement/%=ON\' performance-schema-consumer-statements-digest=ON innodb_monitor_enable=all #动态设置,performance_schema cannot be set in a session and must be set at server start-up UPDATE performance_schema.setup_consumers SET ENABLED = \'YES\' WHERE NAME LIKE \'%statements%\'; SET GLOBAL innodb_monitor_enable = all;
4.添加MySQL Service
pmm-admin add mysql --query-source=slowlog --size-slow-logs=1GB --username=pmm --password=pass MYSQL_NODE 192.168.1.123:3306
pmm-admin add mysql --query-source=perfschema --username=pmm --password=pass --service-name=MYSQL_NODE 192.168.1.123:3306
#服务名(MYSQL_NODE
) and 被监控的服务地址/端口 (191.168.1.123:3306
).
5.检查服务
pmm-admin inventory list services
6.从监控删除服务
pmm-admin remove <service-type> <service-name>
维护工作
删除PMM Server
1.停止pmm-server容器
docker stop pmm-server 2.删除容器 docker rm pmm-server pmm-data 3.删除镜像 docker rmi $(docker images | grep "percona/pmm-server" | awk {\'print $3\'})
维护的命令和界面维护简介
https://www.percona.com/doc/percona-monitoring-and-management/2.x/using/interface.html