MongoDB:[Errno 111] 连接被拒绝
Posted
技术标签:
【中文标题】MongoDB:[Errno 111] 连接被拒绝【英文标题】:MongoDB: [Errno 111] Connection refused 【发布时间】:2019-12-13 22:53:11 【问题描述】:所以我有这个应用程序可以不断地将数据推送到我的数据库。 它已经运行良好一年多了。但是在过去的几天里,我不断收到此错误:
File "/usr/lib/python2.7/site-packages/veristats_backend-2.0.0_0-py2.7.egg/drivertest/utils.py", line 141, in lock
db.find_one_and_update(key, '$set': 'locked': False)
File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 2454, in find_one_and_update
sort, upsert, return_document, **kwargs)
File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 2222, in __find_and_modify
with self._socket_for_writes() as sock_info:
File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/lib64/python2.7/site-packages/pymongo/mongo_client.py", line 868, in _get_socket
server = self._get_topology().select_server(selector)
File "/usr/lib64/python2.7/site-packages/pymongo/topology.py", line 214, in select_server
address))
File "/usr/lib64/python2.7/site-packages/pymongo/topology.py", line 189, in select_servers
self._error_message(selector))
ServerSelectionTimeoutError: l-veristats-01:27017: [Errno 111] Connection refused
我的应用程序运行了一分钟左右,然后就这样崩溃了。
编辑 发生这种情况时,我得到:
# systemctl status mongodb
Unit mongodb.service could not be found.
我还在日志中看到这一行:
019-08-07T09:15:14.475+0300 I COMMAND [conn137619] warning: log line attempted (2200kB) over max size (10kB), printing beginning and end ...
莫非这就是mongod服务停止的原因?
EDIT2 我还看到 OOM 杀手实际上是在杀死服务:
# grep -i 'killed process' /var/log/messages
Aug 5 22:33:12 l-veristats-01 kernel: Killed process 18849 (mongod) total-vm:4871984kB, anon-rss:2287364kB, file-rss:0kB, shmem-rss:0kB
Aug 5 22:33:12 l-veristats-01 kernel: Killed process 18862 (mongod) total-vm:4871984kB, anon-rss:2313000kB, file-rss:0kB, shmem-rss:0kB
Aug 5 22:33:12 l-veristats-01 kernel: Killed process 18896 (mongod) total-vm:4871984kB, anon-rss:2312572kB, file-rss:0kB, shmem-rss:0kB
Aug 5 22:33:12 l-veristats-01 kernel: Killed process 19084 (mongod) total-vm:4871984kB, anon-rss:2312600kB, file-rss:0kB, shmem-rss:0kB
Aug 6 09:12:29 l-veristats-01 kernel: Killed process 1586 (mongod) total-vm:4052764kB, anon-rss:1544224kB, file-rss:0kB, shmem-rss:0kB
Aug 6 09:31:13 l-veristats-01 kernel: Killed process 31266 (mongod) total-vm:3517068kB, anon-rss:1589668kB, file-rss:0kB, shmem-rss:0kB
Aug 6 09:31:13 l-veristats-01 kernel: Killed process 31277 (mongod) total-vm:3517068kB, anon-rss:1597916kB, file-rss:0kB, shmem-rss:0kB
Aug 6 09:34:04 l-veristats-01 kernel: Killed process 31613 (veristats_drive) total-vm:3179060kB, anon-rss:1397368kB, file-rss:132kB, shmem-rss:8kB
Aug 6 09:46:13 l-veristats-01 kernel: Killed process 2781 (mongod) total-vm:3265204kB, anon-rss:676164kB, file-rss:0kB, shmem-rss:0kB
Aug 6 11:14:45 l-veristats-01 kernel: Killed process 1616 (mongod) total-vm:3566624kB, anon-rss:1608752kB, file-rss:0kB, shmem-rss:0kB
Aug 6 11:50:55 l-veristats-01 kernel: Killed process 2004 (mongod) total-vm:3220196kB, anon-rss:433892kB, file-rss:0kB, shmem-rss:0kB
Aug 6 13:31:18 l-veristats-01 kernel: Killed process 6914 (mongod) total-vm:2952284kB, anon-rss:509968kB, file-rss:0kB, shmem-rss:0kB
Aug 6 13:39:21 l-veristats-01 kernel: Killed process 7894 (veristats_drive) total-vm:2543372kB, anon-rss:1404448kB, file-rss:0kB, shmem-rss:0kB
Aug 6 13:39:33 l-veristats-01 kernel: Killed process 7895 (veristats_drive) total-vm:2550052kB, anon-rss:1277732kB, file-rss:0kB, shmem-rss:0kB
Aug 6 13:39:43 l-veristats-01 kernel: Killed process 7899 (veristats_drive) total-vm:2853180kB, anon-rss:1854872kB, file-rss:0kB, shmem-rss:0kB
Aug 6 13:41:15 l-veristats-01 kernel: Killed process 7579 (mongod) total-vm:3361372kB, anon-rss:713976kB, file-rss:0kB, shmem-rss:0kB
Aug 6 15:31:59 l-veristats-01 kernel: Killed process 5304 (veristats_drive) total-vm:2645104kB, anon-rss:1579280kB, file-rss:0kB, shmem-rss:0kB
Aug 6 15:32:43 l-veristats-01 kernel: Killed process 5309 (veristats_drive) total-vm:4463076kB, anon-rss:2628364kB, file-rss:0kB, shmem-rss:0kB
Aug 6 15:36:04 l-veristats-01 kernel: Killed process 1656 (mongod) total-vm:3106644kB, anon-rss:996140kB, file-rss:0kB, shmem-rss:0kB
Aug 6 15:36:20 l-veristats-01 kernel: Killed process 5682 (veristats_drive) total-vm:2127152kB, anon-rss:1161560kB, file-rss:0kB, shmem-rss:0kB
Aug 6 17:36:59 l-veristats-01 kernel: Killed process 1911 (mongod) total-vm:3687888kB, anon-rss:907436kB, file-rss:0kB, shmem-rss:0kB
Aug 7 09:15:17 l-veristats-01 kernel: Killed process 9349 (mongod) total-vm:4044552kB, anon-rss:1413928kB, file-rss:0kB, shmem-rss:0kB
Aug 7 09:30:55 l-veristats-01 kernel: Killed process 17966 (mongod) total-vm:3254812kB, anon-rss:1058928kB, file-rss:0kB, shmem-rss:0kB
Aug 7 09:35:15 l-veristats-01 kernel: Killed process 18993 (mongod) total-vm:2405540kB, anon-rss:361824kB, file-rss:0kB, shmem-rss:0kB
【问题讨论】:
那么 mongodb 的状态是什么? systemctl status mongodb 或类似的。尝试添加一些 mongodb 日志。问题可能是磁盘空间不足或其他原因 请查看编辑。 老实说,看起来问题不在 pymongo 中,而是在 VM 资源中。我想问题在于内存不足(因为 Linux OOM 杀手)。 /var/log/mongodb/mongod.log 中有什么有用的吗?不是警告而是错误? 当您在没有正确配置数据库索引的情况下读取查询时,也会发生内存不足的情况。在这种情况下尝试添加一些。 【参考方案1】:你有没有改变过 mongo 版本?尝试更新您的 pymongo。
【讨论】:
以上是关于MongoDB:[Errno 111] 连接被拒绝的主要内容,如果未能解决你的问题,请参考以下文章
Python socket.error:[Errno 111] 连接被拒绝
Django- [Errno 111] 使用 smtp 时连接被拒绝
将 Celery 与 SQS 一起使用时 Errno 111 连接被拒绝
无法连接到 amqp://guest:**@127.0.0.1:5672//: [Errno 111] 连接被拒绝
OperationalError:(2003,“无法连接到'localhost'上的MySQL服务器([Errno 111]连接被拒绝)”)[关闭]