我正在研究MongoDBUniversity的 M101P:MongoDB for Developers 课程。
我在 MongoDB 3.2 上使用 WiredTiger 。
我目前的主题是副本集。
该课程要求我使用以下代码创建副本集:
mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork
但是我使用的是Windows,它不支持fork
,所以使用this gist(按照课程管理员的建议)我在创建了3个不同的控制台后同时运行这些行目录(运行mongod):
mongod --replSet rs1 --logpath "1.log" --dbpath rs1 --port 27018 --smallfiles --oplogSize64
mongod --replSet rs1 --logpath "2.log" --dbpath rs2 --port 27019 --smallfiles --oplogSize64
mongod --replSet rs1 --logpath "3.log" --dbpath rs3 --port 27020 --smallfiles --oplogSize64
这一切似乎都很好;我可以看到目录已经填满,日志文件都显示“等待连接”与相关的端口号。
最后,我运行以下代码将服务器统一为副本集:
config = {_id: "rs1", members: [
{ _id: 0, host: "localhost:27018"},
{ _id: 1, host: "localhost:27019"},
{ _id: 2, host: "localhost:27020"}
]
}
rs.initiate(config)
rs.status()
投掷:
"errmsg" : "This node was not started with the replSet option",
"code" : 76
我无法理解,因为我已清楚地为每个服务器使用--replSet
选项,并且确实提供了配置文件中使用的相同replSet名称。
我已经看过关于这个主题的其他问题了,但是很少,我找不到任何问题并为我解决这个问题。 This一个说明了错误中看起来很明显的内容:我的配置文件应该包含--replSet=rs1
,但是从阅读documentation我得到的印象是配置的_id
我定义服务的目的:
_id
输入:string副本集的名称。设置后,您无法更改名称 副本集。
_id 必须与replication.replSetName或命令行中指定给mongod的-replSet的值相同。
此外,这显然在课程材料视频演示中正确地以我试图使用它的方式正常运行。
我在我的智慧结束时,非常感谢帮助 杰克
答案 0 :(得分:8)
所以当我写完这个问题时,答案就像一个灯泡一样来到我身边,这似乎经常发生......但是这一次我想我会把这个答案留给其他任何挣扎过这个的人,考虑到论坛上有关此主题的问题/答案有点缺乏。
这是运行配置文件时使用的默认端口的简单情况
我使用<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_ticket_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="info.androidhive.navigationdrawer.activity.TicketInfoActivity">
<!--<include layout="@layout/actionbar_layout" />-->
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollbars="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
来运行我的配置并统一服务器以创建副本集。
只需添加一个有效服务器使用的端口,就可以正确运行:
mongo < init_replica.js
对于那个人来说,我有祸了,但是我希望这对那些也发现自己被困在某个类似地方的课程有所帮助。
杰克