简体   繁体   中英

How do i install MongoDb on Ubuntu and set the config at install time

I am creating an automated deployment for a cloud server and I need to get Mongodb installed, configured and running in one script. I won't have access to the server as the deployment server pulls my scripts from git.

My issue is I need to set the logpath and dbpath to another location. How do i do this using apt-get. What I use at the moment is below but it sets the path to the default location.

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list
apt-get -y update
apt-get -y install mongodb-10gen

To do this easily, write the mongodb.conf first yourself (use sudo, create it as /etc/mongodb.conf with permissions of 644 and root:root) - use an existing one as a template or grab it from git and alter the dbpath and logpath appropriately.

Also easy - just remove those default folders and create symbolic links to point at your desired install paths - no modification to files necessary at all.

If, for some reason you don't want to do that, and you want to do it post-install, then you are going to have to stop the service from starting up with the configured file so that it doesn't start up, pre-allocate files etc. There are a couple of options to do that, that have been covered in pretty decent detail here .

As described there, your options are to either temporarily block all new services from starting or do a download-only fetch with apt-get and manipulate the files to not start mongod automatically before you install, or alter the package to manipulate the config file before it starts.

Or, finally, you can install as normal and let it start, then stop the mongod service ( service mongod stop ), remove the files that were created in the configured paths, and then alter the mongodb.conf with your new values (or overwrite with your own), restart the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM