gpt4 book ai didi

linux - ubuntu:启动( Upstart )mongodb的第二个实例

转载 作者:IT老高 更新时间:2023-10-28 13:11:32 25 4
gpt4 key购买 nike

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

最佳答案

我无法让“标准” 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

exec sudo -u mongodb /usr/bin/mongod --config /etc/mongodb.conf

end script

如果您想运行其他 mongodb 实例,只需复制 *.conf 文件并对 /etc/mongodb2.conf/etc/init/mongodb2.conf 进行更改

# 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

exec sudo -u mongodb /usr/bin/mongod --config /etc/mongodb2.conf

end script

我认为唯一不起作用的是 restart mongodb - 你必须 stop 然后再次 start ...

关于linux - ubuntu:启动( Upstart )mongodb的第二个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7300109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com