Centos
無法連接到 127.0.0.1:27017,連接被拒絕
所以我目前正在嘗試為我的 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 之後錯誤仍然存在。我很迷茫 非常感謝幫助。非常感謝你提前
煩人,但只能解決:恢復整個伺服器的舊備份。
雖然這顯然不理想,但我找不到重新打開對 127.0.0.1:27017 的訪問的方法
一些數據失去了,但是哦,好吧,我已經備份了大部分數據 - 現在只是重新設置它。
感謝您的幫助/建議。