bitsowit


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

  • 站点地图

  • 公益404

  • 搜索

使用docker-compose 搭建 MongoDB 集群

发表于 2018-05-31 |

这里主要介绍Replica Set 模式

  1. docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
version: '3'
services:
ms1:
image: mongo:3.2.11
volumes:
- /data/mongo/db/ms1:/data/db
- /data/mongo/conf/ms1:/data/conf
- /data/mongo/log/ms1:/data/log
command: mongod --config /data/conf/mongo.conf
ports:
- "27017:27017"
ms2:
image: mongo:3.2.11
volumes:
- /data/mongo/db/ms2:/data/db
- /data/mongo/conf/ms2:/data/conf
- /data/mongo/log/ms2:/data/log
command: mongod --config /data/conf/mongo.conf
ports:
- "28017:27017"
ms3:
image: mongo:3.2.11
volumes:
- /data/mongo/db/ms3:/data/db
- /data/mongo/conf/ms3:/data/conf
- /data/mongo/log/ms3:/data/log
command: mongod --config /data/conf/mongo.conf
ports:
- "29017:27017"
  1. 创建文件夹
1
2
3
mkdir -p /data/mongo/db/ms1 /data/mongo/db/ms2 /data/mongo/db/ms3
mkdir -p /data/mongo/conf/ms1 /data/mongo/conf/ms2 /data/mongo/conf/ms3
mkdir -p /data/mongo/log/ms1 /data/mongo/log/ms2 /data/mongo/log/ms3

这里的三个路径分别存放数据,配置及日志。

  1. mongo.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /data/db
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /data/log/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
replication:
replSetName: bitsowit

将配置文件 mongod.conf 拷贝至三个节点对应的配置文件目录下

  1. 启动MongoDB 集群
1
docker-compose up -d

这行命令会将三个几点都启动

  1. 集群初始化

登录ms1这个节点

1
docker-compose exec ms1 mongo

通过这条命令可以连接到ms1这个节点的客户端

接下来我们进行初始化集群的操作

1
2
3
4
5
rs.initiate()
rs.add('ms2:27017')
rs.add('ms3:27017')
rs.conf() //查看配置
rs.status() //查看集群状态

Hello World

发表于 2017-06-18 |

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

bitsowit

bitsowit

2 日志
1 标签
© 2018 bitsowit
由 Hexo 强力驱动
主题 - NexT.Pisces