赞
踩
docker pull mysql:5.6
建立挂载的数据卷
mkdir -p /opt/mysql/data
虚拟机3306端口和容器里的3306端口对应,虚拟机路径和容器路径
docker run -p 3306:3306 --restart=always --name mysql -v /opt/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d --provoleged=true mysql:latest
进入mysql容器
docker exec -it mysql /bin/bash
进入容器后,登陆容器类数据库
mysql -uroot -proot
在操作容器里数据的同时,数据也进到了 /opt/mysql/data 目录里,两边是同步的
docker run -d \
-p 9104:9104 \
--net="host" \
--pid="host" \
-e DATA_SOURCE_NAME="root:Abc_12345678@(172.17.0.1:3306)/" \
prom/mysqld-exporter
- job_name: 'mysql'
static_configs:
- targets: ['192.168.1.36:9104']
labels:
instance: mysql
然后重启prometheus容器,
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
授权文件
chmod +x /opt
然后编辑docker-compose-mysql-exporter.yml文件
version: '2' networks: monitor: driver: bridge services: mysql-exporter: image: prom/mysqld-exporter container_name: mysql-exporter hostname: mysql-exporter restart: always ports: - "9104:9104" networks: - my-mysql-network environment: DATA_SOURCE_NAME: "root:123456@(192.168.1.36:3306)/" networks: my-mysql-network: driver: bridge
通过docker-compose启动
docker-compose -f /opt/docker-compose-mysql-exporter.yml up -d
删除容器
docker-compose -f /opt/docker-compose-mysql-exporter.yml down
重启容器:
docker restart 容器id
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。