Mongo replica set + sharding
一 架构
二 角色分配
主机 | IP | 服务及端口 |
Server A | 10.0.0.6/27 | mongod shard1_1:27017 mongod shard2_1:27018 mongod config1:20000 mongs1:30000 |
Server B | 10.0.0.85/27 | mongod shard1_2:27017 mongod shard2_2:27018 mongod config2:20000 mongs2:30000 |
Server C | 10.0.0.17/27 | mongod shard1_3:27017 mongod shard2_3:27018 mongod config3:20000 mongs3:30000 |
1 创建数据目录
在ServerA 上:
[root@localhost bin]# mkdir -p /data/shard1_1
[root@localhost bin]# mkdir -p /data/shard2_1
[root@localhost bin]# mkdir -p /data/config
在Server B 上:
[root@localhost bin]# mkdir -p /data/shard1_2
[root@localhost bin]# mkdir -p /data/shard2_2
[root@localhost bin]# mkdir -p /data/config
在Server C 上:
[root@localhost bin]# mkdir -p /data/shard1_3
[root@localhost bin]# mkdir -p /data/shard2_3
[root@localhost bin]# mkdir -p /data/config
2 配置Replica Sets
2.1 配置shard1所用到的Replica Sets
在Server A 上:
[root@localhost bin]# /Apps/mongo/bin/mongod --shardsvr--replSet shard1 --port 27017
--dbpath /data/shard1_1 --logpath/data/shard1_1/shard1_1.log --logappend --fork
[root@localhost bin]# all output going to:/data/shard1_1/shard1_1.log
forked process: 18923
在Server B 上:
[root@localhost bin]# /Apps/mongo/bin/mongod --shardsvr--replSet shard1 --port 27017
--dbpath /data/shard1_2 --logpath/data/shard1_2/shard1_2.log --logappend --fork
forked process: 18859
[root@localhost bin]# all output going to:/data/shard1_2/shard1_2.log
[root@localhost bin]#
在Server C 上:
[root@localhost bin]# /Apps/mongo/bin/mongod --shardsvr--replSet shard1 --port 27017
--dbpath /data/shard1_3 --logpath/data/shard1_3/shard1_3.log --logappend --fork
all output going to: /data/shard1_3/shard1_3.log
forked process: 18768
[root@localhost bin]#
用mongo 连接其中一台机器的27017 端口的mongod,初始化Replica Sets“shard1”,执行:
[root@localhost bin]# ./mongo --port 27017
备注:
ERROR: child process failed, exited with error number 1
openssl rand -base64 755 > keyfile
chmod 400 keyfile