monogodb主备配置dockercompose版
Posted gsls200808
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了monogodb主备配置dockercompose版相关的知识,希望对你有一定的参考价值。
准备两台虚拟机,系统centos7
ip分配
host1:192.168.3.53
host2:192.168.3.54
安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install -y docker-ce-18.09.0 docker-ce-cli-18.09.0
systemctl start docker.service
systemctl enable docker.service
docker version
安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
host1的docker-compose.yml
version: '3'
services:
mongo_rs1:
image: mongo:3.4
container_name: mongo_rs1
volumes:
- ~/commpwr/mongodb/log/:/mongodb
- ~/commpwr/mongodb/db/:/data/db/
command:
- /bin/bash
- -c
- mongod --logpath /mongodb/mongo.log --logappend --dbpath /data/db/ --master --slave --source 192.168.3.54:27017 --autoresync
ulimits:
nproc: 65535
hostname: mongo_rs1
restart: always
ports:
- "27017:27017"
host2的docker-compose.yml
version: '3'
services:
mongo_rs2:
image: mongo:3.4
container_name: mongo_rs2
volumes:
- ~/commpwr/mongodb/log/:/mongodb
- ~/commpwr/mongodb/db/:/data/db/
command:
- /bin/bash
- -c
- mongod --logpath /mongodb/mongo.log --logappend --dbpath /data/db/ --master --slave --source 192.168.3.53:27017 --autoresync
ulimits:
nproc: 65535
hostname: mongo_rs2
restart: always
ports:
- "27017:27017"
开启防火墙
firewall-cmd --permanent --add-port=27017/tcp
firewall-cmd --reload
开机后使用navicate新建数据库和集合
两台机器均可读写,新建空数据库不会同步,在数据库里新建修改集合都会同步。
以上是关于monogodb主备配置dockercompose版的主要内容,如果未能解决你的问题,请参考以下文章