[root@mongoDB ~]# mkdir -p /data/data/r0
[root@mongoDB ~]# mkdir -p /data/data/r1
[root@mongoDB ~]# mkdir -p /data/data/r2
2、创建日志文件路径
[root@mongoDB ~]# mkdir -p /data/log
3、创建主从key文件
[root@mongoDB ~]# mkdir -p /data/key
[root@mongoDB ~]# echo "this is rs1 super secret key" > /data/key/r0
[root@mongoDB ~]# echo "this is rs1 super secret key" > /data/key/r1
[root@mongoDB ~]# echo "this is rs1 super secret key" > /data/key/r2
4.启动3个实例
mongod --replSet rs1 --keyFile /data/key/r0 --fork --port 28010 --dbpath /data/data/r0 --logpath=/data/log/r0.log --logappend
mongod --replSet rs1 --keyFile /data/key/r1 --fork --port 28011 --dbpath /data/data/r1 --logpath=/data/log/r1.log --logappend
mongod --replSet rs1 --keyFile /data/key/r2 --fork --port 28012 --dbpath /data/data/r2 --logpath=/data/log/r2.log --logappend
5.配置及初始化replica sets
mongo -port 28010
config_rs1 = {_id: 'rs1', members: [{_id: 0, host: 'localhost:28010', priority:1},{_id: 1, host: 'localhost:28011'},{_id: 2, host: 'localhost:28012'}]}
rs.initiate(config_rs1);
查看复制集状态
rs.status()
/Apps/mongo/bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath /data/shard1_1 --logpath /data/shard1_1/shard1_1.log --logappend --fork
/Apps/mongo/bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath /data/shard1_2 --logpath /data/shard1_2/shard1_2.log --logappend --fork
/Apps/mongo/bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath /data/shard1_3 --logpath /data/shard1_3/shard1_3.log --logappend --fork
/Apps/mongo/bin/mongod --shardsvr --replSet shard2 --port 27018 --dbpath /data/shard2_2 --logpath /data/shard2_2/shard2_2.log --logappend --fork
/Apps/mongo/bin/mongod --shardsvr --replSet shard2 --port 27018 --dbpath /data/shard2_3 --logpath /data/shard2_3/shard2_3.log --logappend --fork
config = {_id: 'shard2', members: [
{_id: 0, host: '10.0.0.6:27018'},
{_id: 1, host: '10.0.0.85:27018'},
{_id: 2, host: '10.0.0.17:27018'}]
}
/Apps/mongo/bin/mongod --configsvr --dbpath /data/config --port 20000 --logpath /data/config/config.log --logappend --fork
/Apps/mongo/bin/mongos --configdb 10.0.0.6:20000,10.0.0.85:20000,10.0.0.17:20000 --port 30000 --chunkSize 1 --logpath /data/mongos.log --logappend --fork
db.runCommand({addshard:"shard1/10.0.0.6:27017,10.0.0.85:27017,10.0.0.17:27017"});
备注:
ERROR: child process failed, exited with error number 1
keyfile文件缺失或生成方式以及文件权限可能有问题
==================================openssl rand -base64 755 > keyfile
chmod 400 keyfile