Mongo replica set + sharding

架构

mongodb replica set+sharding-LMLPHP

角色分配

主机

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 Setsshard1”,执行:

[root@localhost bin]# ./mongo --port 27017

备注:
ERROR: child process failed, exited with error number 1

keyfile文件缺失或生成方式以及文件权限可能有问题
==================================
openssl rand -base64 755 > keyfile
chmod 400 keyfile

10-10 05:09