mongodb - MongoDB replica set initiate
问题描述
I am quite new to MongoDB and have following question for replica set initiation.
When I tried to initiate a replica set from standalone mongod, I tried:
> use admin
> config = {id: "rs_name", members: [{id: 0, host: "127.0.0.1:27017"}]}
> db.runCommand('replSetInitiate', config)
"info2" : "no configuration specified. Using a default configuration for the set",
"ok": 1
...
Here is the first curiosity: Why did it show "no configuration" as I already assigned "config" as replica set configuration?
Though replica set was founded, when I tired:
> use local
> db.system.replset.find().pretty()
...
"members": [
{
"host": "here is hostname insted of host IP"
}
...
Here is the second ponit I didn't get: Why did the replica information show host name instead of host IP as value of property "host"?
But When I tried a different way:
> use admin
> config = {id: "rs_name", members: [{id: 0, host: "127.0.0.1:27017"}]}
> rs.initiate(config)
It went well and did not give any message like "no configuration specified". Replica information also showed host IP instead of host name.
Here is the last one: What is the difference between mechanism of replSetInitiate
and rs.initiate
when we try to initiate a replica set?
解决方案
配置 = {id:“rs_name”,成员:[{id:0,主机:“127.0.0.1:27017”}]}
- 将 id 替换为 _id
db.runCommand('replSetInitiate', 配置)
db.runCommand({replSetInitiate : config})
改为使用
这是我没有得到的第二个要点:为什么副本信息显示主机名而不是主机 IP 作为属性“主机”的值?
- 正如 mongodb 文档所描述的那样
When possible, use a logical DNS hostname instead of an ip address, particularly when configuring replica set members or sharded cluster members.
。在第一步中,您得到了no configuration specified. Using a default configuration for the set
,默认配置可能使用主机名而不是 IP 地址。
来自:https ://docs.mongodb.com/manual/reference/command/replSetInitiate/
推荐阅读
- javascript - 如何在 php/javascript 中获取图像 src
- c# - 来自数据库表的 ASP.NET Core 2 授权
- java - 无法理解程序的输出。界面
- python-3.x - 将 numpy 数组 d.type uint8 输入到自适应阈值函数中时出错
- html - 左侧最多一列,容器中最多一列
- r - 筛选日期早于另一个变量指定的行的行
- angular - Angular Injected 服务未分配给对象实例
- google-identity-toolkit - Google Identity Toolkit 无法注册新用户:错误代码:遇到内部错误
- java - spring-cloud-dataflow-server 中部署的服务如何连接到另一个数据库而不是 dataflow-sever 使用的数据库?
- azure-data-factory-2 - 使用布尔变量时 ADF V2 失败