PMM 容器环境搭建
启动 PMM 容器以及 MongoDB容器
- 创建一个 docker-compose 项目,并进入
mkdir pmm-server
cd pmm-server
- 创建
compose.yaml
文件,填入以下内容
version: "3"
services:
mongodb:
hostname: mongodb
image: 'mongo:6'
environment:
- 'MONGO_INITDB_DATABASE=pmm'
- 'MONGO_INITDB_ROOT_USERNAME=admin'
- 'MONGO_INITDB_ROOT_PASSWORD=admin'
ports:
- "27017:27017"
command: [ "mongod", "--profile", "2", "--slowms", "200"]
pmm-server:
hostname: pmm-server
image: "percona/pmm-server:2"
ports:
- "443:443"
restart: always
- 启动容器
docker compose up
初始化容器设置
- 设置 pmm 管理员密码
docker exec -t pmm-server-pmm-server-1 change-admin-password admin
- 使用 mongosh 连接到 mongodb
docker exec -it pmm-server-mongodb-1 /bin/mongosh --port 27017 --host localhost
- 在 mongodb 上创建一个用于 pmm 监控的用户
use admin
db.auth("admin", "admin")
db.getSiblingDB("admin").createRole({
role: "explainRole",
privileges: [
{
resource: {
db: "",
collection: ""
},
actions: [
"listIndexes",
"listCollections",
"dbStats",
"dbHash",
"collStats",
"find"
]
},
{
resource: {
db: "",
collection: "system.profile"
},
actions: [
"collStats",
"dbStats",
"indexStats"
]
}
],
roles: []
})
db.getSiblingDB("admin").createRole({
"role": "pbmAnyAction",
"privileges": [{
"resource": {
"anyResource": true
},
"actions": [
"anyAction"
]
}],
"roles": []
})
db.getSiblingDB("admin").createUser({
user: "pmm",
pwd: "pmm",
roles: [
{ role: "explainRole", db: "admin" },
{ role: "clusterMonitor", db: "admin" },
{ role: "read", db: "local" },
{ "db": "admin", "role": "readWrite", "collection": "" },
{ "db": "admin", "role": "backup" },
{ "db": "admin", "role": "clusterMonitor" },
{ "db": "admin", "role": "restore" },
{ "db": "admin", "role": "pbmAnyAction" }
]
})
PMM 添加 MongoDB 监控
- 添加监控
docker exec -t pmm-server-pmm-server-1 pmm-admin --server-url=https://admin:admin@pmm-server --server-insecure-tls add mongodb --username=pmm --password=pmm --enable-all-collectors mongodb_srv_1 mongodb:27017
- 访问 https://localhost:443 webUI,登录 pmm,username=admin,password=admin