###### 服務器信息
### 生產環境
IP 10.0.5.179
### 開發環境
IP 10.0.2.76
###### PMM構構圖
PMM監控工具自帶監控LINUX,MySQL,MongoDB
pmm重要組件 grafana,prometheus
https://grafana.com/ //grafana作為數據展示
https://prometheus.io/ //數據采集數據庫
###### mysql數據庫服務配置
https://www.percona.com/doc/percona-monitoring-and-management/conf-mysql.html
innodb_monitor_enable = all
docker run -d -p 80:80 --volumes-from pmm-data --name pmm-server -e SERVER_USER=pmm -e SERVER_PASSWORD=123456 -e METRICS_MEMORY=786432 --restart always --init percona/pmm-server:1.2.0
PMM 1.2.0需要加 METRICS_MEMORY=786432
###### PMM監控工具安裝
參考:https://www.percona.com/doc/percona-monitoring-and-management/deploy/index.html
https://docs.docker.com/engine/installation/linux/centos
### 第一步:安裝docker
1.yum remove docker docker-common container-selinux docker-selinux docker-engine
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum list docker-ce.x86_64 --showduplicates |sort -r
yum install docker-ce.x86_64
### 修改默認存儲路徑
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -g /apps/docker/pmm (線上環境179的配置)
1. mkdir /home/docker(你想要docker存放image的目錄)
2. systemctl stop docker
3. vi /usr/lib/systemd/system/docker.service
4. 添加 -g /home/docker (本地開發環境10.0.2.76的配置)
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket
[Service]
Type=notify
ExecStart=/usr/bin/docker daemon -g /home/docker -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
### 啟動
systemctl start docker
### 第二步:安裝PMM服務端安裝
# 配置加速鏡像
1.curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://396e823a.m.daocloud.io //開啟鏡像加速,由於docker鏡像被牆
[root@pgxl-71 ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://396e823a.m.daocloud.io
docker version >= 1.12
{"registry-mirrors": ["http://396e823a.m.daocloud.io"]}
Success.
You need to restart docker to take effect: sudo systemctl restart docker
systemctl restart docker // docker重啟
# 添加pmm-server鏡像
docker pull percona/pmm-server:latest
# 添加數據容器
2.Create a PMM Data Container //數據目錄
$ 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.3 /bin/true
# 啟動pmm-server容器
3.Create and Run the PMM Server Container //創建PMM Server
$ docker run -d \
-p 80:80 \
--volumes-from pmm-data \
--name pmm-server \
-e SERVER_USER=admin \
-e SERVER_PASSWORD=password \
--restart always \
--init \
percona/pmm-server:1.1.3
### 第三步:安裝PMM客戶端安裝
參考:https://www.percona.com/doc/percona-monitoring-and-management/deploy/client/yum.html#install-client-yum
1.yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
yum install pmm-client
[root@pgxl-71 ~]# pmm-admin --help
Usage:
pmm-admin [flags]
pmm-admin [command]
Available Commands:
config Configure PMM Client.
add Add service to monitoring.
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.
Flags:
-c, --config-file string PMM config file (default "/usr/local/percona/pmm-client/pmm.yml")
-v, --version show version
Use "pmm-admin [command] --help" for more information about a command.
2.添加MongoDB監控服務,自動會添加Linux相關監控
##### 客戶端配置
pmm-admin config --server 10.0.0.148 --server-user admin --server-password password --client-name hostname //
##### mongo服務器配置
pmm-admin add mongodb --cluster cluster1 --uri mongodb://root:123456@localhost:27017/admin
//cluster1 為自定義集群名
//--uri mongodb://root:123456@localhost:27017/admin 為monogo鏈地址
3.添加MySQL監控服務,自動會添加Linux相關監控
pmm-admin config --server 10.0.0.148 --server-user admin --server-password password --client-name hostname
以上3,4操作都會寫入配置文件 /usr/local/percona/pmm-client/pmm.yml
pmm-admin 已經封裝對prometheus修改
pmm-admin add mysql --user root --socket /apps/dbdat/mysql-5.7.17/mysql.sock --password 123456 mysql143
4.添加redis監控服務(生產線已不使用該方式)
wget https://github.com/oliver006/redis_exporter/releases/download/v0.11/redis_exporter-v0.11.linux-amd64.tar.gz
tar -zxvf redis_exporter-v0.11.linux-amd64.tar.gz
[root@pgxl-76 tmp]# ./redis_exporter --help
Usage of ./redis_exporter:
-check-keys string
Comma separated list of keys to export value and length/size
-debug
Output verbose debug information
-log-format string
Log format, valid options are txt and json (default "txt")
-namespace string
Namespace for metrics (default "redis")
-redis.addr string
Address of one or more redis nodes, separated by separator (default "redis://localhost:6379")
-redis.alias string
Redis instance alias for one or more redis nodes, separated by separator
-redis.password string
Password for one or more redis nodes, separated by separator
-separator string
separator used to split redis.addr, redis.password and redis.alias into several elements. (default ",")
-version
Show version information and exit
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9121")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
啟動客戶端 ./redis_exporter -redis.addr redis://localhost:6379
redis_exporter 由於沒有集成到PMM服務,所以需要修改prometheus,登入PMM服務端
[root@pgxl-76 tmp]# docker exec -it pmm-server /bin/bash
[root@a5914a0f9617 opt]# vim /etc/prometheus.yml //添加以下
- job_name: redis_exporter
static_configs:
- targets: ['10.0.2.76:9121']
5添加linux監控
pmm-admin config --server 10.0.5.179 --server-user pmm --server-password XXXXXXX --client-name PGXL182
pmm-admin add linux:metrics
###郵箱報警添加
進入docker
docker exec -it pmm-server /bin/bash
編緝grafana.ini
vim /etc/grafana/grafana.ini
[smtp]
enabled = true
host = smtp.healthmall.cn:25
user = liuqian@healthmall.cn
password = 123456
from_address = liuqian@healthmall.cn
from_name = Grafana
重啟pmm-server容器
docker restart pmm-server
### 釘釘報警配置
http://docs.grafana.org/alerting/notifications/
在釘釘上創作一個內部群,並添加webhook機器人。
DingDing/DingTalk
In DingTalk PC Client:
-
Click “more” icon on left bottom of the panel.
-
Click “Robot Manage” item in the pop menu, there will be a new panel call “Robot Manage”.
-
In the “Robot Manage” panel, select “customised: customised robot with Webhook”.
-
In the next new panel named “robot detail”, click “Add” button.
-
In “Add Robot” panel, input a nickname for the robot and select a “message group” which the robot will join in. click “next”.
-
There will be a Webhook URL in the panel, looks like this: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx. Copy this URL to the grafana Dingtalk setting page and then click “finish”.
Dingtalk supports the following “message type”: text
, link
and markdown
. Only the text
message type is supported.
升級
docker pull percona/pmm-server:latest
docker stop pmm-server && docker rm pmm-server
docker run -d -p 80:80 -p 9090:9090 --volumes-from pmm-data --name pmm-server -e SERVER_USER=pmm -e SERVER_PASSWORD=ngiISI0Q4g9gfqWz89folKJSi --restart always --init percona/pmm-server:latest