其他服务如 apache2 等工作正常。但是当我输入时,sudo service mongod start我收到此错误:
mongod: unrecognized service
Run Code Online (Sandbox Code Playgroud)
我有这个文件:
/lib/systemd/system/mongod.service
Run Code Online (Sandbox Code Playgroud)
它是这样说的:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
小智 4
拉取 ubuntu:17:04 docker 镜像并安装 mongodb-org 后我遇到了同样的问题
看起来 Mongodb 创建了一个 systemd 启动文件,该文件已经被 upstart 替换了。
作为解决方法:
创建一个新文件/etc/init/mongod.conf(需要 sudo 权限)。您可以使用:sudo gedit /etc/init/mongod.conf
将以下内容粘贴到新创建的 upstart 文件中:
# Ubuntu upstart file at /etc/init/mongod.conf
# Recommended ulimit values for mongod or mongos
# See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
#
limit fsize unlimited unlimited
limit cpu unlimited unlimited
limit as unlimited unlimited
limit nofile 64000 64000
limit rss unlimited unlimited
limit nproc 64000 64000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
DAEMONUSER=${DAEMONUSER:-mongodb}
if [ ! -d /var/lib/mongodb ]; then
mkdir -p /var/lib/mongodb && chown mongodb:mongodb /var/lib/mongodb
fi
if [ ! -d /var/log/mongodb ]; then
mkdir -p /var/log/mongodb && chown mongodb:mongodb /var/log/mongodb
fi
touch /var/run/mongodb.pid
chown $DAEMONUSER /var/run/mongodb.pid
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGOD="yes"
CONF=/etc/mongod.conf
DAEMON=/usr/bin/mongod
DAEMONUSER=${DAEMONUSER:-mongodb}
DAEMONGROUP=${DAEMONGROUP:-mongodb}
if [ -f /etc/default/mongod ]; then . /etc/default/mongod; fi
# Handle NUMA access to CPUs (SERVER-3574)
# This verifies the existence of numactl as well as testing that the command works
NUMACTL_ARGS="--interleave=all"
if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
then
NUMACTL="$(which numactl) -- $NUMACTL_ARGS"
DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"}
else
NUMACTL=""
DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"}
fi
if [ "x$ENABLE_MONGOD" = "xyes" ]
then
exec start-stop-daemon --start \
--chuid $DAEMONUSER:$DAEMONGROUP \
--pidfile /var/run/mongodb.pid \
--make-pidfile \
--exec $NUMACTL $DAEMON $DAEMON_OPTS
fi
end script
Run Code Online (Sandbox Code Playgroud)现在,您可以使用以下命令:
sudo service mongod start
sudo service mongod stop
sudo service mongod status
参考: https://github.com/mongodb/mongo/blob/master/debian/mongod.upstart
| 归档时间: |
|
| 查看次数: |
16038 次 |
| 最近记录: |