自定义MongDB启动关闭脚本

正常MongDB启动和关闭:

1.进入mongdb安装目录,执行./bin/mongod命令启动,注意带参数,命令为:

/usr/local/mongdb/mongodb-linux-x86_64-2.2.3/bin/mongod --fork --port 12006 --dbpath /usr/local/mongdb/mongodb-linux-x86_64-2.2.3/data --logpath /usr/local/mongdb/mongodb-linux-x86_64-2.2.3/log/log.log

2.正常关闭mongdb

[root@localhost bin]# ./mongo localhost:12006
MongoDB shell version: 2.2.3
connecting to: localhost:12006/test
> use admin
switched to db admin
> db.shutdownServer();
Mon Aug 12 03:20:31 DBClientCursor::init call() failed
Mon Aug 12 03:20:31 query failed : admin.$cmd { shutdown: 1.0 } to: localhost:12006
server should be down...
Mon Aug 12 03:20:31 trying reconnect to localhost:12006
Mon Aug 12 03:20:31 reconnect localhost:12006 failed couldn't connect to server localhost:12006
> exit
bye
[root@localhost bin]# ps -ef|grep mongdb
root     13232 13047  0 03:20 pts/1    00:00:00 grep mongdb


至此,mongdb已经安全关闭。

 

--------------------------------------------------------------------------------------------

 

下面介绍自定义启动脚本:

1.自定义start.sh脚本

将上面的启动命令写入start.sh里面保存至/usr/local/mongdb/mongodb-linux-x86_64-2.2.3/bin/目录下即可。

进入bin目录,使用 ./start.sh 即可启动mongdb。

2.自定义stop.sh脚本

vi stop.sh

./mongo localhost:12006/admin --eval "db.shutdownServer()"

 

保存即可用。

进入bin目录, 使用 ./stop.sh 命令即可关闭mongdb。

你可能感兴趣的:(Sharing)