我正在测试MongoDB中的分片
我首先启动配置服务器,然后使用两种方法来完成它。
方法1 /配置文件(不起作用) 这是我的配置文件
systemLog:
destination: file
path: "G:/data/replicas/server2/logs/server1.log"
logAppend: true
storage:
dbPath: "G:/data/replicas/server2/db"
engine: wiredTiger
journal:
enabled: true
#security:
# authorization: enabled
replication:
oplogSizeMB: 128
replSetName: rsData
#processManagement:
# fork: true
net:
bindIp: 127.0.0.1
port: 27018
当我运行rs.initiate时,我收到错误。
> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "HORUS:27019",
"ok" : 0,
"errmsg" : "No host described in new configuration 1 for replica set rsConfSvr maps to this node",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig"
}
当我在rs.initiate()之后运行rs.status()时,我收到错误。
> rs.status()
{
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94,
"codeName" : "NotYetInitialized"
}
方法2 /使用命令行
这有效
除非我错了,否则命令行与配置文件
具有相同的选项mongod --configsvr --dbpath G:/data/shards/cfgserverA/data --port 27019 --replSet rsConfigSvr --logpath "G:/data/shards/cfgserverA/logs/cfgserverA.log"
--logappend true --directoryperdb true
现在rs.initiate()和rs.status()在核心工作。
rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "HORUS:27019",
"ok" : 1
}
rsConfigSvr:OTHER>
rs.status()['configsvr']
true
有人可以解释一下吗?我不明白这种差异的原因。