也可以註冊爲系統服務(Systemd方式),實現開機自啓,步驟如下:
(config server和mongos的其他配置,請參考:http://blog.csdn.net/clementad/article/details/52538364)
註冊config-server爲系統服務:
1、創建配置文件:
vi /usr/lib/systemd/system/mongo-config.service
[Unit]
Description=Mongo Config Service
After=mongod.service syslog.target network.target
[Service]
Type=forking
User=mongod
ExecStart=/usr/bin/mongod --config /opt/mongodb/configsvr1/mongod.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
注:Type=forking很重要,沒這行就老是啓動不了。2、註冊開機啓動:
systemctl enable mongo-config.service
啓動:
systemctl start mongo-config.service
檢查狀態:
systemctl status mongo-config.service
註冊mongos爲系統服務:
1、創建配置文件:
vi /usr/lib/systemd/system/mongos.service
[Unit]
Description=Mongo Router Service
After=mongo-config.service
[Service]
Type=forking
User=mongod
ExecStart=/usr/bin/mongos --config /opt/mongodb/mongos1/mongod.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
2、註冊開機啓動:
systemctl enable mongos.service
啓動:
systemctl start mongos.service
檢查狀態:
systemctl status mongos.service