1、新增配置文件mongo27017.conf:
processManagement:
fork: true
net:
bindIp: 127.0.0.1
port: 27017
storage:
dbPath: db27017
systemLog:
destination: file
path: log/mongo27017.log
logAppend: true
storage:
journal:
enabled: true
security:
authorization: enabled
replication:
replSetName: member
2、新增副本集配置文件replsetConfig.js:
config = {
"_id" : "member",
"members":[
{"_id":0,"host":"127.0.0.1:27017"},
{"_id":1,"host":"127.0.0.1:27018"},
{"_id":2,"host":"127.0.0.1:27019"}
]
}
3、建立各个节点启动文件 start27017.sh:
bin/mongod -f mongo27017.conf
4、连接到27017:
[admin]$./bin/mongo 127.0.0.1:27017
5、加载副本集配置文件:
> load("replsetConfig.js")
6、初始化副本集:
> rs.initiate(config)
{
"ok" : 0,
"errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: 127.0.0.1:27019 failed with not authorized on admin to execute command { replSetHeartbeat: \"member\", pv: 1, v: 1, from: \"127.0.0.1:27017\", fromId: 0, checkEmpty: true }, 127.0.0.1:27018 failed with not authorized on admin to execute command { replSetHeartbeat: \"member\", pv: 1, v: 1, from: \"127.0.0.1:27017\", fromId: 0, checkEmpty: true }",
"code" : 74
}
7、为什么会报错呢?
是因为我们开启了验证:
security:
authorization: enabled
当我们开启认证之后,就需要建立节点间的相互认证,然后让节点彼此间进行访问
【待续】见内部认证章节