假设我有一个三服务器设置。两台服务器存储数据,而一台服务器是仲裁器。
上周,我的“ PRIMARY”服务器出现故障,并且按预期方式升级了“ SECONDARY”,并且一切按预期进行。
但是,我现在正在调试应用程序中的另一个错误,我认为 可能与复制设置中的此更改有关。
有什么方法可以(从日志中或其他方式)找出何时确切地发生选举?
答案 0 :(得分:1)
您可以在(新“ PRIMARY”的)日志中找到以下几行:
2018-08-02T03:56:49.817+0000 I REPL [ReplicationExecutor] Standing for election
2018-08-02T03:56:49.818+0000 I REPL [ReplicationExecutor] not electing self, ip-xxx-xxx-xxx-xxx.eu-west-1.compute.internal:27017 has same OpTime as us: { : Timestamp 1533182831000|1 }
2018-08-02T03:56:49.818+0000 I REPL [ReplicationExecutor] possible election tie; sleeping 445ms until 2018-08-02T03:56:50.263+0000
2018-08-02T03:56:50.263+0000 I REPL [ReplicationExecutor] Standing for election
2018-08-02T03:56:50.265+0000 I REPL [ReplicationExecutor] not electing self, ip-xxx-xxx-xxx-xxx.eu-west-1.compute.internal:27017 has same OpTime as us: { : Timestamp 1533182831000|1 }
2018-08-02T03:56:50.265+0000 I REPL [ReplicationExecutor] running for election; slept last election, so running regardless of possible tie
2018-08-02T03:56:50.265+0000 I REPL [ReplicationExecutor] received vote: 1 votes from ip-xxx-xxx-xxx-xxx.eu-west-1.compute.internal:27017
2018-08-02T03:56:50.265+0000 I REPL [ReplicationExecutor] election succeeded, assuming primary role
2018-08-02T03:56:50.265+0000 I REPL [ReplicationExecutor] transition to PRIMARY
您可以看到选举在世界标准时间上午3:56举行。
我建议您使用less
工具在日志文件中进行搜索:
less /var/log/mongodb/mongod.log
然后,使用 G 导航到文件的末尾,然后使用?向后搜索,并搜索“待选”