gpt4 book ai didi

mongodb - RHEL7 systemd自动启动mongo服务?

转载 作者:行者123 更新时间:2023-12-03 03:02:43 26 4
gpt4 key购买 nike

我有一个 RHEL7 服务器,它是 Mongo 集群的一部分。我希望在系统启动时自动启动三个 mongo 进程。一名 mongod、一名仲裁者和一名 mongos:

  • /usr/bin/mongod -f/etc/mongo_shard001.conf
  • /usr/bin/mongod -f/etc/mongoarb.conf
  • /usr/bin/mongos -f/etc/mongos.conf

我一直在尝试为这些命令创建 systemd 服务,即

[Unit]
Description=mongo configuration server
After=network.target

[Service]
User=mongod
Group=mongod
ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf

[Install]
WantedBy=multi-user.target

当我尝试执行 sudo systemctl daemon-reload && sudo systemctl start mongoconf 时,出现此错误

● mongoconf.service - mongo configuration server
Loaded: loaded (/etc/systemd/system/mongoconf.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2017-02-02 14:38:34 AWST; 20s ago
Process: 5114 ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf (code=exited, status=1/FAILURE)
Main PID: 5114 (code=exited, status=1/FAILURE)

Feb 02 14:38:34 mdb1 systemd[1]: Started mongo configuration server.
Feb 02 14:38:34 mdb1 systemd[1]: Starting mongo configuration server...
Feb 02 14:38:34 mdb1 systemd[1]: mongoconf.service: main process exited, code=exited, status=1/FAILURE
Feb 02 14:38:34 mdb1 systemd[1]: Unit mongoconf.service entered failed state.
Feb 02 14:38:34 mdb1 systemd[1]: mongoconf.service failed.

我还尝试过使用带有 pid 文件的 fork 类型:

[Unit]
Description=mongo configuration server
After=network.target

[Service]
User=mongod
Group=mongod
ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf --pidfilepath /var/lib/mongoconf/pid --fork
Type=forking
PIDFile=/var/run/mongodb/mongoconf/pid

[Install]
WantedBy=multi-user.target

但出现此错误

● mongoconf.service - mongo configuration server
Loaded: loaded (/etc/systemd/system/mongoconf.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2017-02-02 14:45:36 AWST; 4s ago
Process: 5256 ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf --pidfilepath /var/lib/mongoconf/pid --fork (code=exited, status=1/FAILURE)
Main PID: 5114 (code=exited, status=1/FAILURE)

Feb 02 14:45:36 mdb1 systemd[1]: Starting mongo configuration server...
Feb 02 14:45:36 mdb1 mongod[5256]: about to fork child process, waiting until server is ready for connections.
Feb 02 14:45:36 mdb1 mongod[5256]: forked process: 5258
Feb 02 14:45:36 mdb1 systemd[1]: mongoconf.service: control process exited, code=exited status=1
Feb 02 14:45:36 mdb1 systemd[1]: Failed to start mongo configuration server.
Feb 02 14:45:36 mdb1 systemd[1]: Unit mongoconf.service entered failed state.
Feb 02 14:45:36 mdb1 systemd[1]: mongoconf.service failed.

手动启动 mongo 配置工作正常并创建 pid 文件

/usr/bin/mongod -f /etc/mongoconf.conf --pidfilepath /var/lib/mongoconf/pid --fork

我使用的 mongod 版本是来自 mongodb.com 的版本,我按照他们的安装指南安装了它。

db version v3.4.1
git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64

来自此存储库

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

我想知道我是否以错误的方式处理这个问题,有更好的方法吗?

最佳答案

我知道你说的是 rhel7,但由于这是 duckduckgo 上针对此问题的唯一答案,因此这可能很有用。在 Ubuntu 15 及更高版本下:

sudo systemctl启用mongod.service

关于mongodb - RHEL7 systemd自动启动mongo服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41995913/

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