1. 程式人生 > >pmm 部署監控mysql資料庫

pmm 部署監控mysql資料庫

詳細的部署資訊請參考官方文件:

https://www.percona.com/doc/percona-monitoring-and-management/deploy/server/docker.setting-up.html#pmm-server-docker-image-pulling

一、server端部署:
1.監控機器安裝docker:
ip:192.168.56.101
作業系統版本:
[[email protected] ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
安裝:
yum install -y docker

啟動:
systemctl start docker
systemctl enable docker


2.拉取PMM伺服器映像:
docker pull percona/pmm-server:latest

[[email protected] ~]# docker pull percona/pmm-server:latest
Trying to pull repository docker.io/percona/pmm-server ...
latest: Pulling from docker.io/percona/pmm-server
aeb7866da422: Pull complete
904d1ed4e1e3: Pull complete
Digest: sha256:5eb0fe89d2e93198e7070e92f22cdd95fcef5db257f70a3e05071685f2503a56
Status: Downloaded newer image for docker.io/percona/pmm-server:latest


3.建立一個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

[[email protected] ~]# 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
8448b22b99f7d667f6bfa9dcc78a4e662aed57a4d36473061d2533afa6c3e515

  
4.建立和執行 PMM Server Container:
docker run -d -p 80:80 --volumes-from pmm-data --name pmm-server --restart always percona/pmm-server:latest

[[email protected] ~]# docker run -d -p 80:80 --volumes-from pmm-data --name pmm-server --restart always percona/pmm-server:latest
56372ece726b9e61f29d2f0dd1e72a5353237015997f2e7637a7164b05f38727


檢查docker狀態:
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE                       COMMAND                CREATED             STATUS              PORTS                         NAMES
56372ece726b        percona/pmm-server:latest   "/opt/entrypoint.sh"   28 seconds ago      Up 27 seconds       0.0.0.0:80->80/tcp, 443/tcp   pmm-server

5.登入:
http://192.168.56.101
預設登入資訊如下,可以自行修改:
username:admin   password:admin

image

登入介面:

image

二、客戶端部署:
6.客戶端部署軟體,在需要被監控MySQL服務端安裝pmm-client:
客戶端資訊(192.168.56.102)
新增yum源(或者下載安裝包):
rpm -ivh https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-6.noarch.rpm
安裝pmm-client:
yum install pmm-client –y

解除安裝軟體:
yum remove pmm-client -y

6.新增監控:
客戶端連線pmm server,配置監控伺服器:
pmm-admin config --server 192.168.56.101

新增作業系統監控:
[[email protected] ~]# pmm-admin add linux:metrics
OK, now monitoring this system.

在需要監控的資料庫上面建立使用者:
GRANT ALL PRIVILEGES ON  *.* TO 'pmm-monitor'@'%' IDENTIFIED BY 'pmm-monitor';
flush privileges;

新增mysql監控:
pmm-admin add mysql --user pmm-monitor --password pmm-monitor --host 192.168.56.102 --port 3306

[[email protected] ~]# pmm-admin add mysql --user pmm-monitor --password pmm-monitor --host 192.168.56.102 --port 3306
[linux:metrics] OK, already monitoring this system.
[mysql:metrics] OK, now monitoring MySQL metrics using DSN pmm-monitor:***@tcp(192.168.56.102:3306)
[mysql:queries] OK, now monitoring MySQL queries from slowlog using DSN pmm-monitor:***@tcp(192.168.56.102:3306)

web頁面檢視新增的mysql監控資訊:

image

客戶端檢視監控資訊:
[[email protected] ~]# pmm-admin list
pmm-admin 1.16.0

PMM Server      | 192.168.56.101
Client Name     | my2.ml.com
Client Address  | 192.168.56.102
Service Manager | linux-upstart

-------------- ----------- ----------- -------- ----------------------------------------- --------------------------------------------------------------------------------------
SERVICE TYPE   NAME        LOCAL PORT  RUNNING  DATA SOURCE                               OPTIONS                                                                              
-------------- ----------- ----------- -------- ----------------------------------------- --------------------------------------------------------------------------------------
mysql:queries  my2.ml.com  -           YES      pmm-monitor:***@tcp(192.168.56.102:3306)  query_source=slowlog, query_examples=true, slow_log_rotation=true, retain_slow_logs=1
linux:metrics  my2.ml.com  42000       YES      -                                                                                                                              
mysql:metrics  my2.ml.com  42002       YES      pmm-monitor:***@tcp(192.168.56.102:3306)


預設監控顯示是以主機名字顯示,如果機器上面部署多個mysql或者需要指定顯示的主機名:

pmm-admin config --server 192.168.56.101 --client-name xx指定監控顯示名稱xxx

刪除無用監控:
pmm-admin purge 會提示幫助資訊,示例如下:
pmm-admin purge linux:metrics my2.ml.com
pmm-admin purge mysql:metrics my2.ml.com

直接輸入pmm-admin會顯示所有的幫助資訊:

[[email protected] ~]# pmm-admin
Usage:
   pmm-admin [flags]
   pmm-admin [command]

Available Commands:
   config         Configure PMM Client.
   add            Add service to monitoring.
   annotate       Annotate application events.
   remove         Remove service from monitoring.
   list           List monitoring services for this system.
   info           Display PMM Client information (works offline).
   check-network  Check network connectivity between client and server.
   ping           Check if PMM server is alive.
   start          Start monitoring service.
   stop           Stop monitoring service.
   restart        Restart monitoring service.
   show-passwords Show PMM Client password information (works offline).
   purge          Purge metrics data on PMM server.
   repair         Repair installation.
   uninstall      Removes all monitoring services with the best effort.
   summary        Fetch system data for diagnostics.
   help           Help about any command

Flags:
   -c, --config-file string   PMM config file (default "/usr/local/percona/pmm-client/pmm.yml")
   -h, --help                 help for pmm-admin
       --skip-root            skip UID check (experimental)
       --timeout duration     timeout (default 5s)
       --verbose              verbose output
   -v, --version              show version

Use "pmm-admin [command] --help" for more information about a command.