gpt4 book ai didi

mongodb - 如何为 MongoDB 服务器从属副本指定套接字超时

转载 作者:IT老高 更新时间:2023-10-28 13:28:28 31 4
gpt4 key购买 nike

当 Mongo 数据库(版本 3.0.5)从主数据库服务器复制到从服务器时,我收到套接字错误 110(连接超时),更准确地说是在提交该数据库的复制时(从服务器的日志如下)。我想可能是因为数据库很大,发送操作来提交它需要太多时间。

如何为 mongo 服务器指定不同的套接字超时?如果不可能,有没有其他方法可以修复复制?

我发现这样一个选项仅适用于 mongo 客户端(连接字符串选项 socketTimeoutMS),但它对 Mongo 服务器没有帮助。

2016-04-26T13:36:34.693+0100 I INDEX    [rsSync]         done building bottom layer, going to commit     
2016-04-26T13:36:34.693+0100 I INDEX [rsSync] build index done. scanned 30980334 total records. 4072 secs
2016-04-26T13:36:34.772+0100 I REPL [rsSync] initial sync cloning db: {skipped db name}
2016-04-26T13:36:34.823+0100 I NETWORK [rsSync] Socket say send() errno:110 Connection timed out {skipped ip}:27017
2016-04-26T13:36:34.828+0100 E REPL [rsSync] 9001 socket exception [SEND_ERROR] server [{skipped ip}:27017]
2016-04-26T13:36:34.828+0100 E REPL [rsSync] initial sync attempt failed, 9 attempts remaining

更新。我被要求在评论中输出 rs.status():

{       "set" : "<skippedsetname>",
"date" : ISODate("2016-05-04T15:35:06.717Z"),
"myState" : 5,
"syncingTo" : "<skipped domain name of other server>:27017",
"members" : [
{
"_id" : 0,
"name" : "<skipped domain name of this server>:27017",
"health" : 1,
"state" : 5,
"stateStr" : "STARTUP2",
"uptime" : 29,
"optime" : Timestamp(0, 0),
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"syncingTo" : "<skipped domain name of other server>:27017",
"configVersion" : 9,
"self" : true
},
{
"_id" : 2,
"name" : "10.0.1.7:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 26,
"lastHeartbeat" : ISODate("2016-05-04T15:35:05.859Z"),
"lastHeartbeatRecv" : ISODate("2016-05-04T15:35:06.347Z"),
"pingMs" : 3,
"configVersion" : 9
},
{
"_id" : 3,
"name" : "<skipped domain name of other server>:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 26,
"optime" : Timestamp(1462376105, 196),
"optimeDate" : ISODate("2016-05-04T15:35:05Z"),
"lastHeartbeat" : ISODate("2016-05-04T15:35:05.859Z"),
"lastHeartbeatRecv" : ISODate("2016-05-04T15:35:06.086Z"),
"pingMs" : 4,
"electionTime" : Timestamp(1461688501, 1),
"electionDate" : ISODate("2016-04-26T16:35:01Z"),
"configVersion" : 9
}
],
"ok" : 1 }

更新。我应该但没有提到使用的托管是 Azure。 Answer and explanation通过查询“azure mongodb connection timeout”完美搜索。我的错。

最佳答案

您对错误原因的假设是错误的。

  • Connection timed out:在尝试建立 TCP 连接的过程中,在给定的时间限制内,对方没有响应。

换句话说,这是建立套接字的问题,而不是复制数据库需要多长时间的问题。

调整 TCP 超时是一项系统设置,而不是您为每个应用程序执行的操作。 linux 上的设置在系统范围内 /etc/sysctl.conf你可以play around使用 net.ipv4.tcp_syn_retries -- 然而 你几乎从不改变建立套接字的超时时间(对于任何程序,包括 mongo),我改变了几次是为了更快地得到错误而缩短它,而不是增加它——增加它不太可能是任何实际应用中的正确解决方案。

问题可能是配置问题 - 例如您的设置中有一些错误的 IP 地址,或者是网络问题,例如防火墙、路由表或网络交换机有问题,有时会在 60-120 秒内无法工作一次。

关于mongodb - 如何为 MongoDB 服务器从属副本指定套接字超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36870822/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com