前言:MySQL监控也用过好多产品,包括zabbix、Lepus、PMM,想比较而言,PMM监控更加全面,安装配置也更加简单。

一、Server端安装

server端安装非常简单,我们采用docker的方式来部署。
1.拉取镜像

  1. docker pull percona/pmm-server:latest

2.创建PMM数据容器

  1. docker create \
  2. -v /opt/prometheus/data \
  3. -v /opt/consul-data \
  4. -v /var/lib/mysql \
  5. -v /var/lib/grafana \
  6. --name pmm-data \
  7. percona/pmm-server:latest /bin/true

3.创建PMM服务器容器

  1. docker run -d -p 80:80 \
  2. --volumes-from pmm-data \
  3. --name pmm-server \
  4. -e SERVER_USER=test \
  5. -e SERVER_PASSWORD=test \
  6. -e ORCHESTRATOR_ENABLED=true \
  7. --restart always \
  8. percona/pmm-server:latest

4.查看服务启动

  1. [root@db-monitor-01 tmp]# ps -ef|grep docker
  2. root 8531 1 0 10:38 ? 00:00:05 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --seccomp-profile=/etc/docker/seccomp.json --selinux-enabled --log-driver=journald --signature-verification=false --storage-driver overlay2
  3. root 8538 8531 0 10:38 ? 00:00:03 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc --runtime-args --systemd-cgroup=true
  4. root 9095 8531 0 10:56 ? 00:00:00 /usr/libexec/docker/docker-proxy-current -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.17.0.2 -container-port 80
  5. root 9100 8538 0 10:56 ? 00:00:00 /usr/bin/docker-containerd-shim-current 7c5656534fed82420cba57ec9ab3f929b242802dae2dcf3fbb400859d2517b6d /var/run/docker/libcontainerd/7c5656534fed82420cba57ec9ab3f929b242802dae2dcf3fbb400859d2517b6d /usr/libexec/docker/docker-runc-current
  6. root 9660 2640 0 11:25 pts/1 00:00:00 grep --color=auto docker

二、Client安装

1.安装rpm包

  1. rpm -ivh pmm-client-1.9.1-1.el7.x86_64.rpm

2.连接server

  1. pmm-admin config --server server_ip --bind-address=client_ip --client-address=client_ip --server-user=admin --server-password=xxx --client-name=xxx

3.收集数据

  1. pmm-admin add mysql --user=pmm --password=xxxx --port=3306

三、常用操作命令

PMM Client相关

  1. [root@Mariadb-04 tmp]# pmm-admin --help
  2. Usage:
  3. pmm-admin [flags]
  4. pmm-admin [command]
  5. Available Commands:
  6. config Configure PMM Client. 配置PMM客户端
  7. add Add service to monitoring. 增加监控
  8. remove Remove service from monitoring. 删除监控服务
  9. list List monitoring services for this system. 列出监控服务
  10. info Display PMM Client information (works offline). 打印PMM客户端信息
  11. check-network Check network connectivity between client and server. 检查网络
  12. ping Check if PMM server is alive. ping server
  13. start Start monitoring service.开启服务
  14. stop Stop monitoring service.停止服务
  15. restart Restart monitoring service.重启服务
  16. show-passwords Show PMM Client password information (works offline).显示客户端密码
  17. purge Purge metrics data on PMM server.删除PMM server端监控信息
  18. repair Repair installation.重新安装
  19. uninstall Removes all monitoring services with the best effort.删除所有服务
  20. help Help about any command
  21. Flags:
  22. -c, --config-file string PMM config file (default "/usr/local/percona/pmm-client/pmm.yml")
  23. -h, --help help for pmm-admin
  24. --verbose verbose output
  25. -v, --version show version
  26. Use "pmm-admin [command] --help" for more information about a command.

Docker相关

  1. [root@db-monitor-01 tmp]# docker --help
  2. Usage: docker COMMAND
  3. A self-sufficient runtime for containers
  4. Options:
  5. --config string Location of client config files (default "/root/.docker")
  6. -D, --debug Enable debug mode
  7. --help Print usage
  8. -H, --host list Daemon socket(s) to connect to (default [])
  9. -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
  10. --tls Use TLS; implied by --tlsverify
  11. --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
  12. --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
  13. --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
  14. --tlsverify Use TLS and verify the remote
  15. -v, --version Print version information and quit
  16. Management Commands:
  17. container Manage containers
  18. image Manage images
  19. network Manage networks
  20. node Manage Swarm nodes
  21. plugin Manage plugins
  22. secret Manage Docker secrets
  23. service Manage services
  24. stack Manage Docker stacks
  25. swarm Manage Swarm
  26. system Manage Docker
  27. volume Manage volumes
  28. Commands:
  29. attach Attach to a running container
  30. build Build an image from a Dockerfile
  31. commit Create a new image from a container's changes
  32. cp Copy files/folders between a container and the local filesystem
  33. create Create a new container
  34. diff Inspect changes on a container's filesystem
  35. events Get real time events from the server
  36. exec Run a command in a running container
  37. export Export a container's filesystem as a tar archive
  38. history Show the history of an image
  39. images List images
  40. import Import the contents from a tarball to create a filesystem image
  41. info Display system-wide information
  42. inspect Return low-level information on Docker objects
  43. kill Kill one or more running containers
  44. load Load an image from a tar archive or STDIN
  45. login Log in to a Docker registry
  46. logout Log out from a Docker registry
  47. logs Fetch the logs of a container
  48. pause Pause all processes within one or more containers
  49. port List port mappings or a specific mapping for the container
  50. ps List containers
  51. pull Pull an image or a repository from a registry
  52. push Push an image or a repository to a registry
  53. rename Rename a container
  54. restart Restart one or more containers
  55. rm Remove one or more containers
  56. rmi Remove one or more images
  57. run Run a command in a new container
  58. save Save one or more images to a tar archive (streamed to STDOUT by default)
  59. search Search the Docker Hub for images
  60. start Start one or more stopped containers
  61. stats Display a live stream of container(s) resource usage statistics
  62. stop Stop one or more running containers
  63. tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  64. top Display the running processes of a container
  65. unpause Unpause all processes within one or more containers
  66. update Update configuration of one or more containers
  67. version Show the Docker version information
  68. wait Block until one or more containers stop, then print their exit codes
  69. Run 'docker COMMAND --help' for more information on a command.

四、监控界面

【MySQL】MySQL监控利器PMM - 图1

【MySQL】MySQL监控利器PMM - 图2

【MySQL】MySQL监控利器PMM - 图3

【MySQL】MySQL监控利器PMM - 图4

【MySQL】MySQL监控利器PMM - 图5

五、排错

  1. Aug 17 21:07:24 localhost dockerd: time="2016-08-17T21:07:24.864612251+08:00" level=error msg="Attempting next endpoint for push after error: Get https://192.168.41.80:5001/v2/: dial tcp 192.168.41.80:5001: getsockopt: connection refused"
  2. Aug 17 21:07:24 localhost dockerd: time="2016-08-17T21:07:24.864884008+08:00" level=error msg="Attempting next endpoint for push after error: Get https://192.168.41.80:5001/v1/_ping: dial tcp 192.168.41.80:5001: getsockopt: connection refused"

类似于如上错误解决方法:

  1. vim /etc/docker/daemon.json
  2. { "insecure-registries":["myregistry.example.com:5000"] }
  3. Restart docker daemon
  4. systemctl restart docker.service