英文:
MongoNetworkError: connect ECONNREFUSED after update
问题
在更新了Linux之后,我无法启动MongoDB。
[ec2-user@ip-172-31-28-249 mongodb]$ sudo systemctl start mongod
[ec2-user@ip-172-31-28-249 mongodb]$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Mon 2023-02-27 08:12:14 UTC; 4s ago
Docs: https://docs.mongodb.org/manual
Process: 3296 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
Main PID: 3296 (code=exited, status=1/FAILURE)
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: mongod.service failed.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: mongod.service holdoff time over, scheduling restart.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Stopped MongoDB Database Server.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: start request repeated too quickly for mongod.service
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: mongod.service failed.
当我尝试连接MongoDB Shell时,我得到了以下错误:
[ec2-user@ip-172-31-28-249 mongodb]$ mongosh
Current Mongosh Log ID: 63fc6638bdf3ce7a41cefff7
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.7.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
在mongod.log
中,我得到了以下信息:
{"t":{"$date":"2023-02-27T08:12:13.413+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-02-27T08:12:13.416+00:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}
{"t":{"$date":"2023-02-27T08:12:13.417+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2023-02-27T08:12:13.417+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2023-02-27T08:12:13.425+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2023-02-27T08:12:13.425+00:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-02-27T08:12:13.425+00:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-02-27T08:12:13.426+00:00"},"s":"I", "c":"CONTROL", "id":23330, "ctx":"main","msg":"ERROR: Cannot write pid file to {path_string}: {errAndStr_second}","attr":{"path_string":"/var/run/mongodb/mongod.pid","errAndStr_second":"No such file or directory"}}
端口27017是开放的。您可以尝试执行以下操作来解决此错误:
- 检查
mongod
的配置文件,确保它与更新后的系统兼容。 - 检查MongoDB日志文件以获取更多有关连接问题的信息。
- 检查MongoDB服务是否正在运行,使用
sudo systemctl status mongod
命令。 - 确保防火墙或安全组未阻止MongoDB端口(27017)的访问。
- 尝试手动启动MongoDB服务,使用
sudo mongod
命令,并查看是否有任何错误消息。 - 确保MongoDB的数据目录正确配置。
请注意,错误信息中提到找不到pid文件,您可能需要检查MongoDB配置文件中的pid文件路径,以确保它存在并具有正确的权限。
英文:
After updating linux i can't start my mongodb.
[ec2-user@ip-172-31-28-249 mongodb]$ sudo systemctl start mongod
[ec2-user@ip-172-31-28-249 mongodb]$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Mon 2023-02-27 08:12:14 UTC; 4s ago
Docs: https://docs.mongodb.org/manual
Process: 3296 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
Main PID: 3296 (code=exited, status=1/FAILURE)
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: mongod.service failed.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: mongod.service holdoff time over, scheduling restart.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Stopped MongoDB Database Server.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: start request repeated too quickly for mongod.service
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Feb 27 08:12:14 ip-172-31-28-249.eu-south-1.compute.internal systemd[1]: mongod.service failed.
and whet i try connect mongosh i get this
[ec2-user@ip-172-31-28-249 mongodb]$ mongosh
Current Mongosh Log ID: 63fc6638bdf3ce7a41cefff7
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.7.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
in mongod.log i get this
{"t":{"$date":"2023-02-27T08:12:13.413+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-02-27T08:12:13.416+00:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2023-02-27T08:12:13.417+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2023-02-27T08:12:13.417+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2023-02-27T08:12:13.425+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2023-02-27T08:12:13.425+00:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-02-27T08:12:13.425+00:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-02-27T08:12:13.426+00:00"},"s":"I", "c":"CONTROL", "id":23330, "ctx":"main","msg":"ERROR: Cannot write pid file to {path_string}: {errAndStr_second}","attr":{"path_string":"/var/run/mongodb/mongod.pid","errAndStr_second":"No such file or directory"}}
what can i do to fix this error?
答案1
得分: 1
请检查您的服务文件 /usr/lib/systemd/system/mongod.service
。
通常情况下,它应该包含以下内容:
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
我假设文件夹 /var/run/mongodb
已被删除(参见硬重启后/var/run中的目录被删除),因此您必须在启动服务时创建它并授予相应的权限。
请注意,您不应直接编辑文件 /usr/lib/systemd/system/mongod.service
。而是创建一个副本,保存在 /etc/systemd/system/mongod.service
,然后根据您的需求修改此副本。
英文:
Check your service file /usr/lib/systemd/system/mongod.service
Usually it should contain lines like these:
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
I assume folder /var/run/mongodb
was deleted (see
Directory in /var/run gets deleted after hard reboot), thus you must create it and grant permissions when service is started.
Note, you should not edit file /usr/lib/systemd/system/mongod.service
directly. Instead create a copy at /etc/systemd/system/mongod.service
and modify this copy according to your needs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论