部署PMM

部署PMM

1.在主机上运行PMM Server,用于访问收集的数据,查看基于时间的图表,并执行性能分析。

可以通过三种方式运行PMM Server:

这里只介绍通过Docker方式运行PMM Server

Running PMM Server Using Docker

PMM服务器的Docker映像公开托管在https://hub.docker.com/r/percona/pmm-server/。 如果要从Docker映像运行PMM Server,则主机必须能够运行Docker 1.12.6或更高版本,并具有网络访问权限。

1
2
3
4
5
6
7
8
安装docker
首先安装epel源
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
yum clean all
yum makecache
yum -y install docker-io
yum upgrade device-mapper-libs -y
service docker start

修改docker容器存储路径,默认存储在/var/lib/docker下.这里使用软连接方式修改

1
2
3
4
5
6
service stop docker
cd /var/lib/docker
cp -r * /data/docker/
mv /var/lib/docker /var/lib/docker.bak
ln -s /var/lib/docker /data/docker
service start docker

禁用防火墙

1
2
停止: systemctl disable firewalld
禁用: systemctl stop firewalld

关闭或者设置 IPTABLES
1
2
3
#PMM
$IPTABLES -A INPUT -p tcp --dport 42002 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 42000 -j ACCEPT

这两个端口号是哪来的的呢? 是在pmm-admin check-network看到的(官方文档也有描述)
1
2
3
4
5
6
* Connection: Client <-- Server
-------------- ---------- --------------------- ------- ---------- ---------
SERVICE TYPE NAME REMOTE ENDPOINT STATUS HTTPS/TLS PASSWORD
-------------- ---------- --------------------- ------- ---------- ---------
linux:metrics pt_slave1 120.27.136.247:42000 OK YES -
mysql:metrics pt_slave1 120.27.136.247:42002 OK YES -

安装Percona-toolkit (Query Analytics需要)
1
2
yum install percona-xtrabackup-24.x86_64 percona-xtrabackup-24-debuginfo.x86_64 percona-xtrabackup-test-24.x86_64 percona-toolkit.x86_64 percona-toolkit-debuginfo.x86_64 percona-toolkit.x86_64 -y
yum install qpress* -y

创建专用用户赋予权限
1
2
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@' localhost' IDENTIFIED BY 'pass' WITH MAX_USER_CONNECTIONS 10;
GRANT SELECT, UPDATE, DELETE, DROP ON performance_schema.* TO 'pmm'@' localhost';

mysql:metrics 需要REPLICATION CLIENT权限
mysql:queries 需要SUPER权限
具体参考 [What privileges are required to monitor a MySQL instance?(https://www.percona.com/doc/percona-monitoring-and-management/faq.html#id11)

Step 1.创建PMM Data Container

1
2
3
4
5
6
7
$ 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

Note

如果再本地找不到,Docker会从Dockerhub拉取image

确保你在使用最新版本的Docker

This container does not run, it simply exists to make sure you retain all PMM data when you upgrade to a newer pmm-server image. Do not remove or re-create this container, unless you intend to wipe out all PMM data and start over.

上述命令执行以下工作:

  • docker create命令指示Docker守护程序从映像创建一个容器.
  • -v选项初始化容器的数据卷.
  • --name选项为可用于引用Docker网络中的容器的容器分配一个自定义名称。 在次数为:pmm-data.
  • percona/pmm-server:1.5.2是导出容器的映像的名称和版本标签.
  • /bin/true是容器运行命令

Step 2.Create and Run the PMM Server Container

1
2
3
4
5
6
7
8
9
10
11
12
docker run -d \
-p 80:80 \
--volumes-from pmm-data \
--name pmm-server \
-e SERVER_USER=hehe \
-e SERVER_PASSWORD=ninainaide \
-e METRICS_RETENTION=4320h \
-e METRICS_MEMORY=35651584 \
-e METRICS_RESOLUTION=3s \
-e DISABLE_TELEMETRY=true \
--restart always \
percona/pmm-server:1.5.2

上述命令执行以下工作:

  • docker run命令指示docker守护程序从映像运行容器。
  • -d选项以分离模式(即后台)启动容器。
  • -p选项映射用于访问PMM服务器Web UI的端口。 例如,如果端口80不可用,则可以使用-p 8080:80将着陆页映射到端口8080。
  • --volumes-from选项从pmm-data容器中装载卷(请参阅步骤1.创建一个PMM数据容器)。
  • —name选项为可用于引用Docker网络中的容器的容器分配一个自定义名称。 在这种情况下:pmm-server。
  • —restart选项定义容器的重新启动策略。 设置它始终确保Docker守护程序在启动时启动容器,并在容器退出时重新启动它。
  • percona / pmm-server:1.5.2是导出容器的映像的名称和版本标签。
  • -e SERVER_USER SERVER_PASSWORD是为了安全,设置访问PMM web页面所需的用户名和密码(否则任何有你pmm地址的人都可以访问) Security Features in Percona Monitoring and Management
  • -e METRICS_MEMORY 默认prometheus使用768M内存存储最近的data chunks 使用此参数设置 具体参考How to control memory consumption for PMM?
  • -e METRICS_RESOLUTION pmm-server 和 client 网络不太好的话把这个值设大一点 1~5s 超过5s promethes无法启动 具体参考What resolution is used for metrics?

2.在所有需要监控的服务器安装PMM Client

1
2
3
安装percona源
rpm -ivh https://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
sudo yum install pmm-client

3.Connect PMM Client to PMM Server

在安装完PMM Client后,它并不会自动连接PMM Server.

要将客户端连接到PMM服务器,请使用pmm-admin config –server命令指定IP地址。 例如,如果PMM服务器在192.168.100.1上运行,并且在IP 192.168.200.1的计算机上安装了PMM Client:

1
2
3
4
5
6
$ sudo pmm-admin config --server 192.168.100.1 --server-user jsmith --server-password pass1234
OK, PMM server is alive.

PMM Server | 192.168.100.1
Client Name | ubuntu-amd64
Client Address | 192.168.200.1

Note

If you changed the default port 80 when running PMM Server, specify it after the server’s IP address. For example:

1
$ sudo pmm-admin config --server 192.168.100.1:8080 --server-user jsmith --server-password pass1234

可以添加–client-name参数指定客户端名称,否则为主机名,但是像ECS那样的默认主机名iZbp1igpeohje7z5ugkdr9Z肯定不是我们想要的

4.Start data collection

After you connect the client to PMM Server, enable data collection from the database instance by adding a monitoring service.

To enable general system metrics, MySQL metrics, and MySQL query analytics, run:

1
sudo pmm-admin add mysql --user mysql --password mysql --socket /data/mysqldata/3306/mysql.sock

To enable general system metrics, MongoDB metrics, and MongoDB query analytics, run:

1
sudo pmm-admin --dev-enable add mongodb

Note

MongoDB查询分析是实验性的,在添加时需要–dev-enable选项。 没有此选项,则只会添加一般系统指标和MongoDB指标.

To enable ProxySQL performance metrics, run:

1
sudo pmm-admin add proxysql:metrics

要查看正在监控的内容,请运行:

1
$ sudo pmm-admin list

举例你开启了系统和MongoDB指标监控,会产生类似下面的输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo pmm-admin list
pmm-admin 1.1.3

PMM Server | 192.168.100.1
Client Name | ubuntu-amd64
Client Address | 192.168.200.1
Service manager | linux-systemd

---------------- ----------- ----------- -------- ---------------- --------
SERVICE TYPE NAME LOCAL PORT RUNNING DATA SOURCE OPTIONS
---------------- ----------- ----------- -------- ---------------- --------
linux:metrics mongo-main 42000 YES -
mongodb:metrics mongo-main 42003 YES localhost:27017

有关添加实例的更多信息,请运行pmm-admin add —help.

装完一定要用pmm-admin check-network检查,下面的是正常的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@iZbp1igpeohje7z5ugkdr9Z log]# pmm-admin check-network
PMM Network Status

Server Address | xx.xx.xx.xx
Client Address | xx.xx.xx.xx

* System Time
NTP Server (0.pool.ntp.org) | 2017-09-28 15:44:39 +0800 CST
PMM Server | 2017-09-28 07:44:38 +0000 GMT
PMM Client | 2017-09-28 15:44:39 +0800 CST
PMM Server Time Drift | OK
PMM Client Time Drift | OK
PMM Client to PMM Server Time Drift | OK

* Connection: Client --> Server
-------------------- -------
SERVER SERVICE STATUS
-------------------- -------
Consul API OK
Prometheus API OK
Query Analytics API OK

Connection duration | 31.032856ms
Request duration | 31.557981ms
Full round trip | 62.590837ms


* Connection: Client <-- Server
-------------- ---------- -------------------- ------- ---------- ---------
SERVICE TYPE NAME REMOTE ENDPOINT STATUS HTTPS/TLS PASSWORD
-------------- ---------- -------------------- ------- ---------- ---------
linux:metrics pt_slave5 101.37.14.213:42000 OK YES -
mysql:metrics pt_slave5 101.37.14.213:42002 OK YES -

修改容器时区(你试试不改时区grafana邮件告警的时候时间对吗 :) )
1
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

重启

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@test2 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
69195dca404b percona/pmm-server:1.5.2 "/opt/entrypoint.sh" 28 hours ago Exited (128) 6 minutes ago 0.0.0.0:80->80/tcp, 443/tcp pmm-server
094c63bd911b percona/pmm-server:1.5.2 "/bin/true" 28 hours ago pmm-data
[root@test2 ~]# docker start 69195dca404b
Error response from daemon: Cannot start container 69195dca404b: Error getting container 69195dca404bc607fa12a9cd6436a9786a71dcf226a0e4c1d6bf0b9879a14f03 from driver devicemapper: Error mounting '/dev/mapper/docker-253:0-6947028-69195dca404bc607fa12a9cd6436a9786a71dcf226a0e4c1d6bf0b9879a14f03' on '/var/lib/docker/devicemapper/mnt/69195dca404bc607fa12a9cd6436a9786a71dcf226a0e4c1d6bf0b9879a14f03': device or resource busy
Error: failed to start containers: [69195dca404b]

umount /var/lib/docker/devicemapper/mnt/69195dca404bc607fa12a9cd6436a9786a71dcf226a0e4c1d6bf0b9879a14f03
[root@test2 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
69195dca404b percona/pmm-server:1.5.2 "/opt/entrypoint.sh" 28 hours ago Exited (128) 8 minutes ago 0.0.0.0:80->80/tcp, 443/tcp pmm-server
094c63bd911b percona/pmm-server:1.5.2 "/bin/true" 28 hours ago pmm-data
[root@test2 ~]# docker start 69195dca404b
69195dca404b
[root@test2 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
69195dca404b percona/pmm-server:1.5.2 "/opt/entrypoint.sh" 28 hours ago Up 5 seconds 0.0.0.0:80->80/tcp, 443/tcp pmm-server
094c63bd911b percona/pmm-server:1.5.2 "/bin/true" 28 hours ago pmm-data

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2022 Fan() All Rights Reserved.

访客数 : | 访问量 :