ubuntu:启动(暴发户)mongodb 的第二个实例

发布于 2024-12-02 15:45:28 字数 1514 浏览 3 评论 0原文

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 mongodb2and 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

寒江雪… 2024-12-09 15:45:28

我无法让“标准”新贵脚本工作(如上所述),所以我像这样更改了它:

# 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

我认为唯一不起作用的是重新启动 mongodb - 你必须停止,然后再次开始...

i couldn't get the "standard" upstart script to work (as described above), so i changed it like this:

# 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

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

# 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

i think the only thing that is not working is restart mongodb - you have to stop and then start again ...

¢蛋碎的人ぎ生 2024-12-09 15:45:28

我知道已经有一个公认的解决方案,但我认为这个更优雅。

另一种方法是使用start-stop-daemon 的pid 文件创建。例如,我有 2 个 mongos 在同一台服务器上运行,有 2 个不同的 upstart 脚本,两个神奇的行是:

exec start-stop-daemon --make-pidfile --pidfile /var/run/mongodb-router.pid --start --startas /data/bin/mongos --chuid mongo -- --logappend --logpath /mnt/log/mongos.log --configdb mongo2-config01,mongo2-config02,mongo2-config03


exec start-stop-daemon --make-pidfile --pidfile /var/run/mongodb-routerrt.pid --start --startas /data/bin/mongos --chuid mongo -- --logappend --logpath /mnt/log/mongos-rt.log --configdb mongort-config01,mongort-config02,mongort-config03 --port 27027

请注意,一个有 '--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:

exec start-stop-daemon --make-pidfile --pidfile /var/run/mongodb-router.pid --start --startas /data/bin/mongos --chuid mongo -- --logappend --logpath /mnt/log/mongos.log --configdb mongo2-config01,mongo2-config02,mongo2-config03


exec start-stop-daemon --make-pidfile --pidfile /var/run/mongodb-routerrt.pid --start --startas /data/bin/mongos --chuid mongo -- --logappend --logpath /mnt/log/mongos-rt.log --configdb mongort-config01,mongort-config02,mongort-config03 --port 27027

Note that one has '--pidfile /var/run/mongodb-router.pid' and the other has '--pidfile /var/run/mongodb-routerrt.pid' and a different port.

就此别过 2024-12-09 15:45:28

是的,我今天遇到了同样的问题。原因是默认脚本使用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.

甜扑 2024-12-09 15:45:28

我就是这样做的。
同一服务器上,

2 个带有 start-stop-daemon 的 mongodb 实例,位于我的 start-stop-daemon 配置的

exec start-stop-daemon --make-pidfile --pidfile /var/lib/mongodb/db1.pid --start --quiet --chuid mongodb --name mongod1 --exec /usr/bin/mongod -- --config etc/mongodb1.conf

exec start-stop-daemon --make-pidfile --pidfile /var/lib/mongodb/db2.pid --start --quiet --chuid mongodb --name mongod2 --exec /usr/bin/mongod -- --config etc/mongodb2.conf

请注意 --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

exec start-stop-daemon --make-pidfile --pidfile /var/lib/mongodb/db1.pid --start --quiet --chuid mongodb --name mongod1 --exec /usr/bin/mongod -- --config etc/mongodb1.conf

exec start-stop-daemon --make-pidfile --pidfile /var/lib/mongodb/db2.pid --start --quiet --chuid mongodb --name mongod2 --exec /usr/bin/mongod -- --config etc/mongodb2.conf

pay attention to the --name option. That did the trick for me

吹泡泡o 2024-12-09 15:45:28

这两个守护进程无法监听同一个 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.

樱娆 2024-12-09 15:45:28

我发现下面的新贵适合我

# Ubuntu upstart file at /etc/init/mongodb.conf

description "manage mongodb instance"

start on runlevel [2345]
stop on runlevel [06]

limit nofile 20000 20000

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

env MONGODB_USER=mongodb
env MONGODB_DATA=/var/lib/mongodb/
env MONGODB_LOG=/var/log/mongodb/
env MONGODB_PID=/var/run/mongodb.pid

pre-start script
  if [ ! -d $MONGODB_DATA ]; then
    mkdir -p $MONGODB_DATA
    chown $MONGODB_USER:$MONGODB_USER $MONGODB_DATA
  fi

  if [ ! -d $MONGODB_LOG ]; then
    mkdir -p $MONGODB_LOG
    chown $MONGODB_USER:$MOGODB_USER $MONGODB_LOG
  fi
end script

exec start-stop-daemon --start --pidfile $MONGODB_PID --chuid $MONGODB_USER:$MONGODB_USER --exec /usr/bin/mongod -- --config /etc/mongodb/mongodb.conf

pre-stop exec start-stop-daemon --signal QUIT --stop --quiet --pidfile $MONGODB_PID --chuid $MONGODB_USER:$MONGODB_USER --exec /usr/bin/mongod -- --config /etc/mongodb/mongodb.conf

I find the below upstart works for me

# Ubuntu upstart file at /etc/init/mongodb.conf

description "manage mongodb instance"

start on runlevel [2345]
stop on runlevel [06]

limit nofile 20000 20000

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

env MONGODB_USER=mongodb
env MONGODB_DATA=/var/lib/mongodb/
env MONGODB_LOG=/var/log/mongodb/
env MONGODB_PID=/var/run/mongodb.pid

pre-start script
  if [ ! -d $MONGODB_DATA ]; then
    mkdir -p $MONGODB_DATA
    chown $MONGODB_USER:$MONGODB_USER $MONGODB_DATA
  fi

  if [ ! -d $MONGODB_LOG ]; then
    mkdir -p $MONGODB_LOG
    chown $MONGODB_USER:$MOGODB_USER $MONGODB_LOG
  fi
end script

exec start-stop-daemon --start --pidfile $MONGODB_PID --chuid $MONGODB_USER:$MONGODB_USER --exec /usr/bin/mongod -- --config /etc/mongodb/mongodb.conf

pre-stop exec start-stop-daemon --signal QUIT --stop --quiet --pidfile $MONGODB_PID --chuid $MONGODB_USER:$MONGODB_USER --exec /usr/bin/mongod -- --config /etc/mongodb/mongodb.conf
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文