ubuntu pmm安装配置监控MySQL
1. PMM 的 SERVER端需要有DOCKER支持,安装DOCKER:
root@ubuntu:~# apt-get install docker.io root@ubuntu:~# service docker status docker start/running, process 2746
2. 创建数据容器:
root@ubuntu:~# docker create -v /opt/prometheus/data -v /opt/consul-data -v /var/lib/mysql -v /var/lib/grafana --name pmm-data percona/pmm-server:1.1.2 /bin/true Unable to find image 'percona/pmm-server:1.1.2' locally 1.0.7: Pulling from percona/pmm-server 7e671841de32: Pull complete 67282acf791c: Pull complete 7b74716dd91c: Pull complete c43b458dbeb1: Pull complete 9ba8cf8f5164: Pull complete 2a4fcb055224: Pull complete eb3887a931e5: Pull complete e9d1a8cff0ad: Pull complete 451f471aafac: Pull complete 015ab4ad0316: Pull complete 8fd288f53199: Pull complete 02f3bb9387ba: Pull complete 3aa1a10c3417: Pull complete 7c167ae7a6a7: Pull complete 7c167ae7a6a7: Pulling fs layer bb04ed60c038: Already exists 0812a82a4eba: Already exists f6662ef795ac: Already exists 39a955bdc1e1: Already exists 348ae5f2350a: Already exists d61c7e9067e9: Already exists 78a58c16256c: Already exists 4dd18e76374e: Already exists dba2d32d5bd1: Already exists 977d24c6a914: Already exists 642e729d446f: Already exists Digest: sha256:2c980ce9c1b5218592b61c4fc2ea8552798ce9cbb870be0faa42b430f715770b Status: Downloaded newer image for percona/pmm-server:1.1.2 e3fb255bb95b2a89f7f935f53d4f94cf218324a8d8ad836bd5788929ba540970
这里的下载可谓是一波三折, 下载了两天才下载下来,不停的失败,不停的重启下载, 那么我们换一个环境去安装是否是又要下载一次? 答案是否定的, docker为用户提供了镜像导出导入功能:
2.1 将下载的镜像保存为文件:
root@ubuntu:~# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE percona/pmm-server 1.1.2 6a00bad79251 4 weeks ago 1.12 GB root@ubuntu:~# docker save -o pmm1.1.2.tar percona/pmm-server root@ubuntu:~# ls -ltrh total 1.1G -rw-r--r-- 1 root root 1.1G May 4 11:54 pmm1.1.2.tar
2.2 导入文件:
root@ubuntu:~# docker load < pmm1.1.2.tar root@ubuntu:~# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE percona/pmm-server 1.1.2 6a00bad79251 4 weeks ago 1.12 GB
2.3 创建数据容器:
root@ubuntu:/var/lib/docker# docker create -v /opt/prometheus/data -v /opt/consul-data -v /var/lib/mysql -v /var/lib/grafana --name pmm-data percona/pmm-server:1.1.2 /bin/true 75843b84aafe561fdf7fa8934c11f2b8998bdd719cb38e753a695e950e3bc470
2.4 运行数据容器,在启动时注意名字, 不要重复:
root@ubuntu:/var/lib/docker# docker run -d -p 80:80 --volumes-from pmm-data --name pmm-server_t --restart always percona/pmm-server:1.1.2 66060b025cdd8c0d299ba320a281a9ae73613095f1e8300069168fef0bb4c243 root@ubuntu:/var/lib/docker# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 66060b025cdd percona/pmm-server:1.1.2 "/opt/entrypoint.sh" 22 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp, 443/tcp pmm-server_t
3. 运行PMM SERVER:
root@ubuntu:~# docker run -d \ > -p 80:80 \ > --volumes-from pmm-data \ > --name pmm-server \ > --restart always \ > percona/pmm-server:1.1.2 59a3dbd69635a0b3ca21a20c5cbdd7894816fe5d5db8c2163fe93496520737c9
4. 查看DOCKER运行状态:
root@ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 59a3dbd69635 percona/pmm-server:1.1.2 "/opt/entrypoint.sh" 27 seconds ago Up 25 seconds 0.0.0.0:80->80/tcp, 443/tcp pmm-server
访问页面测试:
5. 客户端安装PMM-CLIENT:
https://www.percona.com/downloads/pmm-client/pmm-client-1.1.2/binary/debian/trusty/x86_64/pmm-client_1.1.2-1.trusty_amd64.deb dpkg -i pmm-client_1.1.2-1.trusty_amd64.deb
数据库授权:
mysql> grant process,super,select on *.* to monitor@'192.168.137.%' identified by 'monitor_2017'; Query OK, 0 rows affected (1.50 sec) mysql> flush privileges; Query OK, 0 rows affected (0.03 sec)
6. 在PMM SERVER端添加MYSQL主机:
pmm-admin add mysql --user monitor --password monitor_2017 --host 192.168.137.9 --port 3306 [linux:metrics] OK, already monitoring this system. [mysql:metrics] OK, now monitoring MySQL metrics using DSN monitor:***@tcp(192.168.137.9:3306) [mysql:queries] OK, now monitoring MySQL queries from slowlog using DSN monitor:***@tcp(192.168.137.9:3306)
root@ubuntu:~# pmm-admin list pmm-admin 1.1.2 PMM Server | 192.168.137.9 Client Name | ubuntu Client Address | 192.168.137.9 Service Manager | linux-upstart -------------- ------- ----------- -------- ------------------------------------ ------------------------------------------ SERVICE TYPE NAME LOCAL PORT RUNNING DATA SOURCE OPTIONS -------------- ------- ----------- -------- ------------------------------------ ------------------------------------------ mysql:queries ubuntu - YES monitor:***@tcp(192.168.137.9:3306) query_source=slowlog, query_examples=true linux:metrics ubuntu 42000 YES - mysql:metrics ubuntu 42002 YES monitor:***@tcp(192.168.137.9:3306)
完成安装配置, 可以去检查监控项了。