MongoDB Auto-Start script

Source: Internet
Author: User


After the installation of MongoDB, has been the following start, specify Dbpath,logpath, verify auth, etc.


./mongod--dbpath=/usr/bin/mongodb/mongodb/data--logpath=/usr/bin/mongodb/mongodb/log/mongodb.log--auth


But more and more trouble, write more parameters, and are prone to error, because decided to enable a MongoDB automatic script


    1. Writing parameters to a configuration file

Vim/usr/bin/mongodb/init.d/mongodb.conf
port=27017 #端口dbpath =e:/mongodb/mongodb/db #数据库存储路径logpath =e:/mongodb/mongodb/log/mongodb.log #日志存储路径logappend =tr UE Auth=true #开启鉴权


At this point, after using the configuration file, the startup method is simple, as follows

./mongod--config=/usr/bin/mongodb/init.d/mongodb.conf #conf配置文件所在位置


2. Shell script, self-booting MongoDB

Vim/usr/bin/mongodb/init.d/mongodb
#!/bin/bash# #chkconfig: 2345 90#description:mongodbstart () {/usr/bin/mongodb/mongodb/bin/mongod-f/usr/bin/ Mongodb/mongodb/bin/mongodb.conf & Echo "MongoDB is running background ..."}stop () {/usr/bin/mongodb/mongodb/bin/ Mongod-f/usr/bin/mongodb/mongodb/bin/mongodb.conf--shutdown echo "MongoDB is stopped."}  Case "$" in start) start;  stop) stop;;  restart) stop start;; *) echo $ "Usage: $ Start|stop|restart}" Exit 1esac


As above, the self-startup script is completed


MongoDB Boot

/usr/bin/mongodb/init.d/mongodb start

MongoDB off

/usr/bin/mongodb/init.d/mongodb stop


This article is from the "Bulajunjun" blog, make sure to keep this source http://5148737.blog.51cto.com/5138737/1650703

MongoDB Auto-Start script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.