AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1061025
Accepted
Mr.Dobby
Mr.Dobby
Asked: 2021-04-21 20:37:35 +0800 CST2021-04-21 20:37:35 +0800 CST 2021-04-21 20:37:35 +0800 CST

无法连接到 127.0.0.1:27017,连接被拒绝

  • 772

所以我目前正在尝试为我的 centos 机器设置 mongodb 在本地运行和托管。但是当我尝试连接时,我得到了这个:

#mongo
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017
2021-04-20T22:06:51.585+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2021-04-20T22:06:51.585+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed

我现在已经阅读了很多关于它的内容。

  • 用户 mongod 是 /var/lib/monogodb 的所有者
  • 文件 /var/lib/mongodb/mongod.lock 不存在
  • 重新启动服务器导致此问题。

我认为(个人)认为这与 iptables 有关。当我启动 mongodb 服务时,我得到了这个:

# service mongod status
Redirecting to /bin/systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-04-20 22:05:26 UTC; 27s ago
     Docs: https://docs.mongodb.org/manual
  Process: 1772 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=51)
  Process: 1770 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 1768 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 1766 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Apr 20 22:05:25 Server-Elf systemd[1]: Starting MongoDB Database Server...
Apr 20 22:05:25 Server-Elf mongod[1772]: about to fork child process, waiting until server is ready for connections.
Apr 20 22:05:25 Server-Elf mongod[1772]: forked process: 1774
Apr 20 22:05:26 Server-Elf mongod[1772]: ERROR: child process failed, exited with error number 51
Apr 20 22:05:26 Server-Elf systemd[1]: mongod.service: Control process exited, code=exited status=51
Apr 20 22:05:26 Server-Elf systemd[1]: mongod.service: Failed with result 'exit-code'.
Apr 20 22:05:26 Server-Elf systemd[1]: Failed to start MongoDB Database Server.

iptables 设置:

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

/etc/mongod.conf 显示:net: bindIp: 127.0.0.1

即使在停止 iptables 之后错误仍然存​​在。我很迷茫 非常感谢帮助。非常感谢你提前

centos iptables mongodb
  • 1 1 个回答
  • 2269 Views

1 个回答

  • Voted
  1. Best Answer
    Mr.Dobby
    2021-04-22T06:48:08+08:002021-04-22T06:48:08+08:00

    烦人,但只能解决:恢复整个服务器的旧备份。

    虽然这显然不理想,但我找不到重新打开对 127.0.0.1:27017 的访问的方法

    一些数据丢失了,但是哦,好吧,我已经备份了大部分数据 - 现在只是重新设置它。

    感谢您的帮助/建议。

    • 0

相关问题

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 使用 crontab 和 /etc/cron.hourly,daily,weekly 的区别

  • 持续监控许多服务器运行状况的简单方法?

  • Hudson 无法在 tomcat5 中启动

  • CentOS 的依赖挑战

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve