【发布时间】:2015-11-02 04:30:39
【问题描述】:
我的操作系统是 Centos 7,我使用 systemd 创建了一个服务来午餐我的 mongodb 数据库,我在“/usr/lib/systemd/system/”下创建了该服务,我将它命名为“mongo.service”
当我使用
启动我的服务时sudo systemctl start mongo.service
没有报错但是看不到mongodb在指定的27017端口监听,说明它根本没有启动。
当我使用脚本启动数据库时:
sudo /usr/local/iot/mongodb-linux-x86_64-3.0.5/start_mongod.sh
数据库开始监听。
这是 mongo.service 包含的内容
[Unit]
Description= mongo db data base
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/iot/mongodb-linux-x86_64-3.0.5/start_mongod.sh
[Install]
WantedBy=multi-user.target
这是我的脚本 start_mongod.sh 包含的内容:
#!/bin/bash
/usr/local/iot/mongodb-linux-x86_64-3.0.5/bin/mongod --dbpath /usr/local/iot/mongodb-linux-x86_64-3.0.5/data/db --port 27017 --smallfiles --logpath /usr/local/iot/mongodb-linux-x86_64-3.0.5/log/mongoc.log --pidfilepath /usr/local/iot/mongodb-linux-x86_64-3.0.5/log/mongod.pid --logappend &
为了能够将我的 mongo db 作为服务启动,我在这里错过了什么? 提前感谢您的帮助!
【问题讨论】:
-
能否查看/usr/local/iot/mongodb-linux-x86_64-3.0.5/log/mongoc.log中的日志
-
sudo systemctl status mongo.service说什么? -
你可以试试
ExecStart=/bin/bash /usr/local/iot/mongodb-linux-x86_64-3.0.5/start_mongod.sh -
@Vishal:“mongoc.log”中没有考虑将mongodb作为服务启动的操作,该操作没有生成新的日志。
-
@t_thirupathi :systemctl 状态给了我这个:“[egm@localhost bin]$ sudo systemctl status mongo.service mongo.service - mongo db 数据库已加载:已加载 (/usr/lib/systemd /system/mongo.service; 已禁用)活动:非活动(死)8 月 10 日 08:47:07 localhost.localdomain systemd [1]:正在启动 mongo db 数据库... 8 月 10 日 08:47:07 localhost.localdomain systemd [ 1]:启动 mongo db 数据库。”我尝试使用“/bin/bash”,但也没有用:(
标签: linux bash mongodb service centos