当前位置: 首页 > 工具软件 > pam-mongodb > 使用案例 >

记一次死坑,mongodb无法启动报错 reason: errno:111 Connection refused

漆雕令秋
2023-12-01

这个问题是真,,,,,,,哎,不说了。

过程如下:

mongodb启动报错

  1. [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
  2. [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed

然后journalctl -xe看一下详情

  1. localhost.localdomain polkitd[686]: Unregistered Authentication Agent for unix-process:7798:588850 (system bus name
  2. :1.165, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale zh_CN.UTF-8) (disconnected from bus)
  3.  localhost.localdomain mongod[7804]: about to fork child process, waiting until server is ready for connections.
  4.  localhost.localdomain mongod[7804]: forked process: 7806
  5.  localhost.localdomain mongod[7804]: ERROR: child process failed, exited with error number 14
  6.  localhost.localdomain systemd[1]: mongod.service: main process exited, code=exited, status=14/n/a
  7. localhost.localdomain systemd[1]: Unit mongod.service entered failed state.
  8.  localhost.localdomain systemd[1]: mongod.service failed.
  9.  localhost.localdomain polkitd[686]: Registered Authentication Agent for unix-process:7912:600595 (system bus name
  10. :1.166 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale
  11.  localhost.localdomain polkitd[686]: Unregistered Authentication Agent for unix-process:7912:600595 (system bus name
  12. :1.166, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale zh_CN.UTF-8) (disconnected from bus)
  13.  localhost.localdomain yum[8016]: Erased: mongodb-org-3.2.21-1.el7.x86_64
  14.  localhost.localdomain systemd[1]: Reloading.
  15.  localhost.localdomain yum[8016]: Erased: mongodb-org-server-3.2.21-1.el7.x86_64
  16. localhost.localdomain yum[8016]: Erased: mongodb-org-shell-3.2.21-1.el7.x86_64
  17.  localhost.localdomain yum[8016]: Erased: mongodb-org-mongos-3.2.21-1.el7.x86_64
  18.  localhost.localdomain yum[8016]: Erased: mongodb-org-tools-3.2.21-1.el7.x86_64
  19.  localhost.localdomain yum[8198]: Installed: mongodb-org-tools-3.2.21-1.el7.x86_64
  20.  localhost.localdomain yum[8198]: Installed: mongodb-org-mongos-3.2.21-1.el7.x86_64
  21.  localhost.localdomain yum[8198]: Installed: mongodb-org-shell-3.2.21-1.el7.x86_64
  22.  localhost.localdomain systemd[1]: Reloading.
  23.  localhost.localdomain yum[8198]: Installed: mongodb-org-server-3.2.21-1.el7.x86_64
  24.  localhost.localdomain yum[8198]: Installed: mongodb-org-3.2.21-1.el7.x86_64
  25.  localhost.localdomain polkitd[686]: Registered Authentication Agent for unix-process:8253:634451 (system bus name
  26. :1.167 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale
  27. zh_CN.UTF-8)
  28.  localhost.localdomain systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database...

发现如下字段:

  1. pam_unix(runuser:session): session opened for user mongod by (uid=0)
  2.  pam_unix(runuser:session): session closed for user mongod

看着像权限问题,推测数据文件权限不够,mongo 需要执行的文件有两个,分别是数据存储文件 /var/lib/mongo和日志存储文件 /var/log/mongodb,运行如下命令解决。

chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongodb

然后重新journalctl -xe,发现报错信息变了出现如下字段

  1. Error starting mongod. /var/run/mongodb/mongod.pid exists

这句话比较好理解,因为这个进程的存在导致错误启动,只要删除即可,命令如下。

rm /var/run/mongodb/mongod.pid exists

再次启动发现还是失败,继续journalctl -xe。发现如下字段:

  1. mongod.service: control process exited, code=exited status=1
  2. Failed to start SYSV: Mongo is a scalable, document-oriented database

貌似是这个mongod.service文件有问题,于是通过命令搜索找出来,发现是空的,所以就编辑一下。

[Unit]
Description=Mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/www/server/mongodb/mongodb.pid
ExecStartPre=/bin/rm -rf /www/server/mongodb/mongod.lock
ExecStart=/bin/su - mongodb -c "/www/server/mongodb/bin/mongod --config /www/server/mongodb/mongodb.conf"
ExecStop=/bin/kill -2 $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true

[Install]
WantedBy=multi-user.target

vi /etc/systemd/system/multi-user.target.wants/mongod.service

 

 

操作完发现还是不行,哇塞,于是这次去找log文件,看一下又是哪块小饼干在抽疯。

vi /var/log/mongodb/mongod.log

看到内容中的错误字段如下,

  1. ***aborting after fassert() failure

  2. 2018-09-14T10:58:45.640+0800 I CONTROL  [main] ***** SERVER RESTARTED *****

  3. 2018-09-14T10:58:45.644+0800 I CONTROL  [initandlisten] MongoDB starting : pid=8710 port=27017 dbpath=/var/lib/mongo 64-bit host=localhost.localdomain

  4. 2018-09-14T10:58:45.644+0800 I CONTROL  [initandlisten] db version v3.2.21

  5. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten] git version: 1ab1010737145ba3761318508ff65ba74dfe8155

  6. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013

  7. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten] allocator: tcmalloc

  8. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten] modules: none

  9. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten] build environment:

  10. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten]     distmod: rhel70

  11. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten]     distarch: x86_64

  12. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten]     target_arch: x86_64

  13. 2018-09-14T10:58:45.645+0800 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }

  14. 2018-09-14T10:58:45.660+0800 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted

  15. 2018-09-14T10:58:45.660+0800 I -        [initandlisten] Fatal Assertion 28578

  16. 2018-09-14T10:58:45.660+0800 I -        [initandlisten]

    ***aborting after fassert() failure

​​​​​​​发现连接不到一个socket文件,于是过去打开发现是空的~那就干脆直接删掉,让mongo启动时候自己去新建去。

rm /tmp/mongodb-27017.sock

然后再去启动,发现还是不行,好的吧那就继续journalctl -xe

  1. Error starting mongod. /var/run/mongodb/mongod.pid exists.

​​​​​​​这鬼东西又出来了,好吧那就继续删除,刚呗,who怕who啊~

rm /var/run/mongodb/mongod.pid

然后再用systemctl start mongod ,发现这狗日的mongo终于运行了~~~

 类似资料: