ubuntu:启动(暴发户)mongodb 的第二个实例
mongodb 附带的标准 upstart 脚本工作正常:
# Ubuntu upstart file at /etc/init/mongodb.conf
limit nofile 20000 20000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /var/lib/mongodb/
mkdir -p /var/log/mongodb/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf; fi
end script
如果我想运行 mongod 的第二个实例,我想我只需复制 /etc/mongodb.conf
-> /etc/mongodb2.conf
和 /etc/init/mongodb.conf
-> /etc/init/mongodb2.conf
并更改第一个conf文件中的std端口。然后调整上面的脚本以从新创建的 /etc/mongodb2.conf
开始。
然后我可以只说 start mongodb2
服务就会启动......但它在启动后就被杀死了。我需要改变什么才能让两个进程都启动并运行?
# Ubuntu upstart file at /etc/init/mongodb2.conf
limit nofile 20000 20000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /var/lib/mongodb2/
mkdir -p /var/log/mongodb2/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb2.conf; fi
end script
the standard upstart script that comes with mongodb works fine:
# Ubuntu upstart file at /etc/init/mongodb.conf
limit nofile 20000 20000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /var/lib/mongodb/
mkdir -p /var/log/mongodb/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf; fi
end script
if i want to run a second instance of mongod i thought i just copy both /etc/mongodb.conf
-> /etc/mongodb2.conf
and /etc/init/mongodb.conf
-> /etc/init/mongodb2.conf
and change the std port in the first conf-file. then adjust the script above to start with the newly created /etc/mongodb2.conf
.
i can then just say start mongodb2
and the service starts ... but it is killed right after starting. what do i change, to get both processes up and running?
# Ubuntu upstart file at /etc/init/mongodb2.conf
limit nofile 20000 20000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /var/lib/mongodb2/
mkdir -p /var/log/mongodb2/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb2.conf; fi
end script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我无法让“标准”新贵脚本工作(如上所述),所以我像这样更改了它:
如果您想运行 mongodb 的其他实例,只需复制 *.conf 文件并对
/etc/mongodb2.conf
和/etc/init/mongodb2.conf
我认为唯一不起作用的是
重新启动 mongodb
- 你必须停止
,然后再次开始
...i couldn't get the "standard" upstart script to work (as described above), so i changed it like this:
and if you want to run other instances of mongodb just copy the *.conf files and make the changes to
/etc/mongodb2.conf
and/etc/init/mongodb2.conf
i think the only thing that is not working is
restart mongodb
- you have tostop
and thenstart
again ...我知道已经有一个公认的解决方案,但我认为这个更优雅。
另一种方法是使用start-stop-daemon 的pid 文件创建。例如,我有 2 个 mongos 在同一台服务器上运行,有 2 个不同的 upstart 脚本,两个神奇的行是:
请注意,一个有 '--pidfile /var/run/mongodb-router.pid',另一个有 '- -pidfile /var/run/mongodb-routerrt.pid' 和不同的端口。
I know there's already an accepted solution but I think this one is more elegant.
The other way is to use start-stop-daemon's pid file creation. For example, I have 2 mongos running on the same server with 2 different upstart scripts, and the two magic lines are:
Note that one has '--pidfile /var/run/mongodb-router.pid' and the other has '--pidfile /var/run/mongodb-routerrt.pid' and a different port.
是的,我今天遇到了同样的问题。原因是默认脚本使用start-stop-daemon来启动mongo,这是专门为了确保一个进程只运行一个版本而设计的。您已经发现解决此问题的一种方法是不使用 start-stop-daemon 并自行启动二进制文件。我也是这样做的,但我很想知道是否有更好的方法。
Yeah I ran into this same issue today. The reason is that the default script uses the start-stop-daemon to start mongo, which is specifically designed to ensure that only one version of a process is running. You already figured out that one way to fix this is to not use start-stop-daemon and to start the binary yourself. That's the way I do it too but I'd be curious to hear if there's a better way.
我就是这样做的。
同一服务器上,
2 个带有 start-stop-daemon 的 mongodb 实例,位于我的 start-stop-daemon 配置的
请注意
--name
选项。这对我有用This is how I do it.
2 instances of mongodb, with start-stop-daemon, on the same server
that are my start-stop-daemon configs
pay attention to the
--name
option. That did the trick for me这两个守护进程无法监听同一个 tcp 端口,因此您必须更改 mongod2 的 --port 参数才能监听不同的端口。
两个守护进程不能共享相同的数据目录,因此您必须更改 mongod2 的 --data-dir 参数。
the two daemons cannot listen on the same tcp port, thus you have to change the --port parameter of mongod2 in order to listen to a different port.
the two daemons cannot share the same data dir, thus you have to change the --data-dir parameter of mongod2.
我发现下面的新贵适合我
I find the below upstart works for me