MongoDB Charts 安装和使用

1.什么是MongoDB Charts
2.安装和运行MongoDB Charts

2.1 准备环境
Mac/Linux 系统 Docker version 18.09.1 MongoDB shell version v4.2.0
2.2 创建一个目录存储图表配置
mkdir mongodb-charts
cd mongodb-charts
2.3 下载MongoDB Charts Docker Compose file

version: '3.3'
services:
charts:
image: quay.io/mongodb/charts:19.12.1
hostname: charts
ports:
# host:container port mapping. If you want MongoDB Charts to be
# reachable on a different port on the docker host, change this
# to
:80, e.g. 8888:80. - 80:80
- 443:443
volumes:
- keys:/mongodb-charts/volumes/keys
- logs:/mongodb-charts/volumes/logs
- db-certs:/mongodb-charts/volumes/db-certs
- web-certs:/mongodb-charts/volumes/web-certs
environment:
# The presence of following 2 environment variables will enable HTTPS on Charts server.
# All HTTP requests will be redirected to HTTPS as well.
# To enable HTTPS, upload your certificate and key file to the web-certs volume,
# uncomment the following lines and replace with the names of your certificate and key file.
# CHARTS_HTTPS_CERTIFICATE_FILE: charts-https.crt
# CHARTS_HTTPS_CERTIFICATE_KEY_FILE: charts-https.key
# This environment variable controls the built-in support widget and
# metrics collection in MongoDB Charts. To disable both, set the value
# to "off". The default is "on".
CHARTS_SUPPORT_WIDGET_AND_METRICS: 'on'
# Directory where you can upload SSL certificates (.pem format) which
# should be considered trusted self-signed or root certificates when
# Charts is accessing MongoDB servers with ?ssl=true
SSL_CERT_DIR: /mongodb-charts/volumes/db-certs
networks:
- backend
secrets:
- charts-mongodb-uri
networks:
backend:
volumes:
keys:
logs:
db-certs:
web-certs:
secrets:
charts-mongodb-uri:
external: true
2.4 Enable Docker Swarm mode
docker swarm init
2.5 拉取MongoDB Charts image 镜像
docker pull quay.io/mongodb/charts:19.12.1
2.6 测试连接到 MongoDB 数据库
docker run --rm quay.io/mongodb/charts:19.12.1 charts-cli test-connection 'mongodb://:@host.docker.internal'
docker run --rm quay.io/mongodb/charts:19.12.1 charts-cli test-connection 'mongodb://host.docker.internal'

2.7 创建一个Docker secret 为MongoDB Charts
echo "" | docker secret create charts-mongodb-uri -
我的输入:
echo "mongodb://host.docker,internal" | docker secret create charts-mongodb-uri -
2.8 运行MongoDB Charts 容器
docker stack deploy -c charts-docker-swarm-19.12.1.yml mongodb-charts
2.9 查看运行状态
docker service ls
2.10 创建 MongoDB Charts 访问 Users账号
docker exec -it \
$(docker container ls --filter name=_charts -q) \
charts-cli add-user --first-name "
" --last-name " " \ --email "
" --password " " \ --role "
"
docker exec -it `
$(docker container ls --filter name=_charts -q) `
charts-cli add-user --first-name "
" --last-name " " ` --email "
" --password " " ` --role "
"


2.11 直接访问 Compose file 里配置的端口

3. MongoDB Charts 使用
3.1 首先先关联一个 MongoDB 数据源

3.2 选择一个MongoDB数据库
3.3 在Dashboard 一栏New Dashboard


3.4 新增一个Chart


4. Embed Chart 导出你的图表 嵌入到自己的Web环境
4.1 保存你设置好的图表后

4.2 开启匿名访问图表 并且复制 Embed Code

4.3 创建HTML 文件
mongo-charts
Mongodb-Charts

5. 总结
评论