我正在将我的应用程序迁移到新服务器,但我无法让 oplog tailing 工作。这个想法是建立一个单一的副本集,以便我的 Meteor 应用程序有一个 oplog 跟踪。我遵循与旧服务器相同的过程,它可以正常工作。
我的 MongoDB 没有访问控制,因为它仅在本地可用。
老服务器:
Ubuntu 16.04
MongoDB shell 版本 v3.4.1
新服务器:
Ubuntu 1.04
MongoDB shell 版 v4.0.6
我正在使用 Phusion Passenger 服务 Meteor 1.6 应用程序。
这是我设置副本集的方式:
/etc/mongod.conf
replication:
replSetName: rs0
oplogSizeMB: 100
/etc/hosts/
127.0.1.1 myhostname myhostname
127.0.0.1 localhost
127.0.0.1 myhostname
重启 MongoDB。然后在 Mongo shell 中:
use local
rs.initiate()
在我的乘客配置中:
sudo nano /etc/nginx/sites-enabled/myappname.conf
passenger_env_var MONGO_OPLOG_URL mongodb://localhost:27017/local;
并重启 Nginx。
我已经使用 rs.conf() 检查了 Mongo shell 中的副本集状态:
{
"_id" : "rs0",
"version" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5c7580c68631363039a485f1")
}
}
但是,在 Mongo 日志 /var/log/mongodb/mongod.log 我看到这个:
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] New replica set config in use: { _id: "rs0", version: 1, protocolVersion: 1, writeConcernMajorityJournalDefault: true, members: [ { _id: 0, host: "127.0.0.1:27017", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 } ], settings: { chainingAllowed: true, heartbeatIntervalMillis: 2000, heartbeatTimeoutSecs: 10, electionTimeoutMillis: 10000, catchUpTimeoutMillis: -1, catchUpTakeoverDelayMillis: 30000, getLastErrorModes: {}, getLastErrorDefaults: { w: 1, wtimeout: 0 }, replicaSetId: ObjectId('5c7580c68631363039a485f1') } }
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] This node is 127.0.0.1:27017 in the config
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] transition to STARTUP2 from STARTUP
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] Starting replication storage threads
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] transition to RECOVERING from STARTUP2
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] Starting replication fetcher thread
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] Starting replication applier thread
2019-02-27T10:26:14.783+0000 I REPL [replexec-0] Starting replication reporter thread
2019-02-27T10:26:14.784+0000 I NETWORK [LogicalSessionCacheRefresh] Starting new replica set monitor for rs0/127.0.0.1:27017
2019-02-27T10:26:14.784+0000 I NETWORK [listener] connection accepted from 127.0.0.1:34490 #2 (1 connection now open)
2019-02-27T10:26:14.785+0000 I REPL [rsSync-0] Starting oplog application
2019-02-27T10:26:14.785+0000 I REPL [rsSync-0] transition to SECONDARY from RECOVERING
2019-02-27T10:26:14.785+0000 I REPL [rsSync-0] conducting a dry run election to see if we could be elected. current term: 1
2019-02-27T10:26:14.785+0000 I REPL [replexec-0] dry election run succeeded, running for election in term 2
2019-02-27T10:26:14.786+0000 I NETWORK [conn2] received client metadata from 127.0.0.1:34490 conn2: { driver: { name: "MongoDB Internal Client", version: "4.0.6" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } }
2019-02-27T10:26:14.786+0000 I NETWORK [LogicalSessionCacheRefresh] Successfully connected to 127.0.0.1:27017 (1 connections now open to 127.0.0.1:27017 with a 5 second timeout)
2019-02-27T10:26:14.786+0000 I REPL [replexec-0] election succeeded, assuming primary role in term 2
2019-02-27T10:26:14.786+0000 I REPL [replexec-0] transition to PRIMARY from SECONDARY
2019-02-27T10:26:14.786+0000 I REPL [replexec-0] Resetting sync source to empty, which was :27017
2019-02-27T10:26:14.786+0000 I REPL [replexec-0] Entering primary catch-up mode.
2019-02-27T10:26:14.786+0000 I REPL [replexec-0] Exited primary catch-up mode.
2019-02-27T10:26:14.786+0000 I REPL [replexec-0] Stopping replication producer
2019-02-27T10:26:14.787+0000 W NETWORK [LogicalSessionCacheRefresh] Unable to reach primary for set rs0
消息“Unable to reach primary for set rs0”表明它不工作,而且在 mongod.log 文件中我看到查询记录超过 100 毫秒,如果 oplog 拖尾工作正常,这不应该发生。
有什么想法可能是错的吗?MongoDB 版本之间有什么变化吗?我四处寻找,但没有找到任何答案。
感谢您的任何帮助!