After connecting to the server remotely, start the mongodb service on the server. How to keep the service running after disconnecting the remote connection
Use mongod -f to add the configuration file, set fork=true in it and run it in the background.
My mongo configuration file is in /data/mongo/27017.conf
port=27017 #端口號(hào)
fork=true #以守護(hù)進(jìn)程的方式運(yùn)行,創(chuàng)建服務(wù)器進(jìn)程
master=true #單主從配置時(shí)設(shè)為主服務(wù)器
#salve=true ##單主從配置時(shí)設(shè)為從服務(wù)器
logpath=/data/mongo/27017/mongo.log #日志輸出文件路徑
logappend=true #日志輸出方式
dbpath=/data/mongo/27017 #數(shù)據(jù)庫(kù)路徑
#replSet=testrs #設(shè)置富本集的名字
#shardsvr=true #設(shè)置是否分片
auth=true#是否開(kāi)啟授權(quán)
Run the command mongod -f /data/mongo/27017.conf and it’s done
Thanks.
If I understand your question correctly, you use ssh to remotely log in to the server and start mongodb; then close the ssh connection and the service stops running.
It is recommended that when starting mongodb, let it run as a daemon process.
mongod adds --fork startup option.