前情介紹
Percona Monitoring and Management是percona一款開源的用于管理和監(jiān)控MySQL 和MongoDB性能的開源平臺故爵,通過PMM客戶端收集到的DB監(jiān)控?cái)?shù)據(jù)用第三方軟件Grafana畫圖展示出來
框架結(jié)構(gòu)
PMM Client:(部署在每個(gè)監(jiān)控?cái)?shù)據(jù)庫主機(jī)。搜集主機(jī)骇钦,數(shù)據(jù)庫和查詢分析數(shù)據(jù))
組成部分:
ppm-admin:命令行的PMM Client管理工具辩撑,用來新增躯枢、移除監(jiān)控的資料Instance。
percona-qan-agent:是一種管理QAN代理的服務(wù)槐臀,收集查詢性能數(shù)據(jù)并將其發(fā)送到PMM服務(wù)器上的QAN API锄蹂。
node_exporter:Prometheus exporter用于搜集一般系統(tǒng)信息(https://github.com/prometheus/node_exporter)。
mysqld_exporter:Prometheus exporter用于搜集MySQL Server的信息(https://github.com/percona/mysqld_exporter)水慨。
mongodb_exporter:Prometheus exporter用于搜集MongoDB server的信息(https://github.com/percona/mongodb_exporter)得糜。
PMM Server:(匯集數(shù)據(jù)并展示。提供表晰洒,dashboards和graph的web界面)
組成部分:
QAN(Query Analytics):分析mysql數(shù)據(jù)庫的查詢性能朝抖,相對于qan agent,它包含:
—qan api:后端存儲和獲取由agent采集的查詢性能數(shù)據(jù)谍珊。
—qan web:提供數(shù)據(jù)展示治宣。
metrics monitor:提供mysql和mongodb的歷史性能數(shù)據(jù)查詢。
—prometheus:第三方的時(shí)序數(shù)據(jù)庫砌滞,連接到pmm client的exporter并匯集數(shù)據(jù)侮邀。consul給pmm client提供api用于遠(yuǎn)程list,添加贝润,刪除prometheus上的配置主機(jī)绊茧,并存儲監(jiān)控的元數(shù)據(jù)。
—grafana:第三方的圖形展示界面打掘。
Orchestrator:提供mysql復(fù)制的拓?fù)涔ぞ吆蛨D形界面华畏。
搭建步驟:
1.通過docker工具,創(chuàng)建PMM-Server容器
①.安裝docker微服務(wù)
==>sudo apt-get install docker.io
(等待安裝完成)
==>sudo service docker status
(查看docker運(yùn)行狀態(tài))
● docker.service - Docker Application Container Engine
???Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
???Active: active (running) since Thu?2018-11-22?11:13:58?CST; 18min ago
?????Docs: https://docs.docker.com
?Main PID:?27566?(dockerd)
???CGroup: /system.slice/docker.service
???????????├─27566?/usr/bin/dockerd -H fd://
???????????└─27597?docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --
②.獲取PMM-Server最新鏡像
==>?sudo docker pull percona/pmm-server:latest
latest: Pulling from percona/pmm-server
aeb7866da422: Pull complete
cc3feb415dc3: Pull complete
Digest: sha256:92092866dcfaabd6aac4d2754a4094967ea42864faf2434811232181a9f755dc
Status: Downloaded newer image?for?percona/pmm-server:latest
(返回上述字段尊蚁,則表明獲取成功)
③.創(chuàng)建持久化的pmm data鏡像
==>sudo docker create -v /pmm/prometheus/data/ -v /pmm/consul-data/ -v /var/lib/mysql -v /pmm/grafana/ --name pmm-data percona/pmm-server:latest /bin/true
(-v 初始化數(shù)據(jù)卷的容器亡笑,建議數(shù)據(jù)卷單獨(dú)掛載 )
④.創(chuàng)建并啟動pmm server鏡像
==>sudo docker run -d -p 8070:80-e ORCHESTRATOR_ENABLED=true-e DISABLE_TELEMETRY=true-e DISABLE_UPDATES=true?--volumes-from pmm-data --name pmm-server --restart always percona/pmm-server:latest
(端口根據(jù)實(shí)際需求進(jìn)行更改,-e横朋,表示啟用額外的功能仑乌,所以我們啟用Orchestrator復(fù)制拓?fù)洌P(guān)閉telemetry,避免pmm-server每24小時(shí)上報(bào)percona.com绝骚,同時(shí)關(guān)閉更新)
⑤.通過運(yùn)行容器的主機(jī)的IP地址訪問PMM Web界面,顯示如下界面則表示成功祠够。
2.安裝PMM-Client
(在指定目錄下載Percona安裝包)
==>sudo dpkg -i percona-release_0.1-6.xenial_all.deb
==>sudo apt update
==>sudo apt install pmm-client
(安裝Percona軟件包压汪,更新源,并安裝PMM-Clinent)
3.PMM Client連接到PMM Server
==>sudo pmm-admin config --server localhost(server IP)
OK, PMM server is alive.
PMM Server????? | localhost
Client Name???? | CI-CD1-Zeaho
Client Address? |?172.17.0.1
(注意古瓤,如果在運(yùn)行PMM Server時(shí)更改了默認(rèn)端口80 止剖,請?jiān)诜?wù)器的IP地址之后指定。)
4.添加監(jiān)測項(xiàng)目
①.創(chuàng)建一個(gè)監(jiān)控賬號'db_zhg'
==>mysql -uroot -p123456
==>GRANT select,process,super ON *.* TO 'db_zhg'@'localhost' IDENTIFIED BY 'hbbUabJz*8eBhD0n' WITH? MAX_USER_CONNECTIONS 10;
②.添加MySQL監(jiān)控和主機(jī)監(jiān)控(server端操作)
==>sudo pmm-admin add mysql db_zhg --password?hbbUabJz*8eBhD0n?--host172.16.158.189(client IP)?--port 4408
[linux:metrics] OK, now monitoring?this?system.
[mysql:metrics] OK, now monitoring MySQL metrics using DSN root:***@unix(/var/run/mysqld/mysqld.sock)
[mysql:queries] OK, now monitoring MySQL queries from slowlog using DSN root:***@unix(/var/run/mysqld/mysqld.sock)
(顯示ok落君,則表明添加成功)
參考鏈接: