重启后Mongodb服务失败

时间:2018-08-28 20:42:38

标签: linux service debian systemd systemctl

我正在尝试为我的开发环境设置一个副本集,并让三台运行带mongod服务的debian 9.3 Stretch的机器。副本集正在运行,并且一切正常。

但是当我重新启动其中一台服务器时,mongod服务不会启动。当我检查状态时,它说失败status = 48

    mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2018-08-28 22:17:37 CEST; 10s ago
     Docs: https://docs.mongodb.org/manual
  Process: 392 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=48)
 Main PID: 392 (code=exited, status=48)
      CPU: 33ms

aug 28 22:17:37 staging-manager-1 systemd[1]: Started MongoDB Database Server.
aug 28 22:17:37 staging-manager-1 mongod[392]: 2018-08-28T22:17:37.389+0200 I CONTROL  [main] Automatically disabling TLS 1.0, to fo
aug 28 22:17:37 staging-manager-1 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
aug 28 22:17:37 staging-manager-1 systemd[1]: mongod.service: Unit entered failed state.
aug 28 22:17:37 staging-manager-1 systemd[1]: mongod.service: Failed with result 'exit-code'.

我已经使用systemctl enable mongod启用了该服务,并且在状态下我可以看到它确实已启用,但是为什么重新启动计算机后它会失败?

更新:

root@machine:/home/<user># journalctl -u mongod
-- Logs begin at Thu 2018-08-30 21:11:33 CEST, end at Thu 2018-08-30 21:26:42 CEST. --
aug 30 21:11:33 staging-manager-1 systemd[1]: Started MongoDB Database Server.
aug 30 21:11:33 staging-manager-1 mongod[398]: 2018-08-30T21:11:33.388+0200 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
aug 30 21:11:33 staging-manager-1 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
aug 30 21:11:33 staging-manager-1 systemd[1]: mongod.service: Unit entered failed state.
aug 30 21:11:33 staging-manager-1 systemd[1]: mongod.service: Failed with result 'exit-code'.


root@machine:/home/<user># ll /etc/init
total 48
-rw-r--r-- 1 root root  278 mei 29  2017 anacron.conf
-rw-r--r-- 1 root root 1875 jul 18 21:01 docker.conf
-rw-r--r-- 1 root root 2493 jun  2  2015 networking.conf
-rw-r--r-- 1 root root  933 jun  2  2015 network-interface.conf
-rw-r--r-- 1 root root  530 jun  2  2015 network-interface-container.conf
-rw-r--r-- 1 root root 1756 jun  2  2015 network-interface-security.conf
-rw-r--r-- 1 root root 1359 mrt 14  2017 sddm.conf
-rw-r--r-- 1 root root  637 mrt  1 13:36 ssh.conf
-rw-r--r-- 1 root root  337 jun 13 22:20 udev.conf
-rw-r--r-- 1 root root  360 jun 13 22:20 udevmonitor.conf
-rw-r--r-- 1 root root  352 jun 13 22:20 udevtrigger.conf
-rw-r--r-- 1 root root  138 jan 23  2017 usb-modeswitch-upstart.conf
root@machine:/home/<user># ll /etc/init.d
total 168
-rwxr-xr-x 1 root root 5336 feb  1  2016 alsa-utils
-rwxr-xr-x 1 root root 2014 mei 29  2017 anacron
-rwxr-xr-x 1 root root 8181 apr  5 20:32 apache2
-rwxr-xr-x 1 root root 2489 mei 13 18:52 apache-htcacheclean
-rwxr-xr-x 1 root root 2401 jan 23  2017 avahi-daemon
-rwxr-xr-x 1 root root 2948 sep 13  2017 bluetooth
-rwxr-xr-x 1 root root 1904 nov 18  2015 cgroupfs-mount
-rwxr-xr-x 1 root root 1232 apr  7  2017 console-setup.sh
-rwxr-xr-x 1 root root 3049 okt  7  2017 cron
-rwxr-xr-x 1 root root 2816 jul 10 15:57 cups
-rwxr-xr-x 1 root root 1961 jan 19  2017 cups-browsed
-rwxr-xr-x 1 root root 2813 mrt  2 09:59 dbus
-rwxr-xr-x 1 root root 3843 jul 18 21:01 docker
-rwxr-x--- 1 root root 4285 jul 20 07:27 elasticsearch
-rwxr-xr-x 1 root root 3033 aug  9 21:30 gdm3
-rwxr-xr-x 1 root root 1604 feb  2  2017 gdomap
-rwxr-xr-x 1 root root 3809 mrt  7 19:29 hwclock.sh
-rwxr-xr-x 1 root root 1479 mei 19  2016 keyboard-setup.sh
-rwxr-xr-x 1 root root 2044 dec 26  2016 kmod
-rwxr-xr-x 1 root root 2241 apr 26  2017 minissdpd
-rwxr-xr-x 1 root root 4597 sep 16  2016 networking
-rwxr-xr-x 1 root root 1757 mrt 18  2017 network-manager
-rwxr-xr-x 1 root root  612 dec  4  2015 pppd-dns
-rwxr-xr-x 1 root root 1191 mei 17 12:56 procps
-rwxr-xr-x 1 root root 4355 dec 10  2017 rsync
-rwxr-xr-x 1 root root 2868 jan 18  2017 rsyslog
-rwxr-xr-x 1 root root 2330 mei 21  2017 saned
-rwxr-xr-x 1 root root 1222 apr  3  2017 screen-cleanup
-rwxr-xr-x 1 root root 1808 mrt 14  2017 sddm
-rwxr-xr-x 1 root root 2117 aug  2  2017 speech-dispatcher
-rwxr-xr-x 1 root root 2484 okt 12  2016 spice-vdagent
-rwxr-xr-x 1 root root 4033 mrt  1 13:36 ssh
-rwxr-xr-x 1 root root  731 jun  5  2017 sudo
-rwxr-xr-x 1 root root 6087 jun 13 22:20 udev
-rwxr-xr-x 1 root root 1391 mei  6  2017 unattended-upgrades
-rwxr-xr-x 1 root root 2757 nov 23  2016 x11-common

4 个答案:

答案 0 :(得分:0)

那是整个输出消息?

检查默认mongod端口(27017)是否未使用。

netstat -a

或者尝试从其他端口启动

mongod --fork --port 8000

答案 1 :(得分:0)

MongoDB defines exit code 48如下:“由于错误,新启动的mongod或mongos无法开始侦听传入的连接。”

您只为MongoDB服务粘贴了status输出。对于基于systemd的系统上的服务的完整日志,您应该查看systemd日记输出:

 journalctl -u mongod

正如卢卡(Lucca)所建议的那样,问题可能出在您尝试启动时端口上已经在运行其他东西。

通过在MongoDB/etc/init中查找/etc/init.d文件,检查您是否也不想通过Upstart或SysVInit启动MongoDB。如果找到任何文件,请将其移动到其他位置,以便仅使用systemd服务文件来启动服务。

答案 2 :(得分:0)

a@a-57:~$ sudo systemctl stop mongod.service
a@a-57:~$ sudo systemctl start mongod.service
a@a-57:~$ sudo systemctl status mongod.service
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor      preset: enabled)
Active: active (running) since Mon 2021-08-09 16:38:29 CST; 6s ago
 Docs: https://docs.mongodb.org/manual
Main PID: 2205 (mongod)
CGroup: /system.slice/mongod.service
       └─2205 /usr/bin/mongod --config /etc/mongod.conf
八  09 16:38:29 a-57 systemd[1]: Started MongoDB Database Server.

在现代,不知何故编辑 /etc 下的 rc 文件是危险的。正如我们所知,人们更喜欢使用系统命令 API。

答案 3 :(得分:-1)

您需要编辑etc/rc.local才能使其在启动时启动

只需将service mongod start添加到rc.local文件的末尾

相关问题