Manually Manipulating MongoDB Installations
Today we'll be covering how you can manually set up your own MongoDB installation to be used with Deadline.
WAIT... YOU CAN DO THAT?
It may come as a shock, but you can indeed use a manually installed instance of MongoDB with Deadline. In fact, this has been supported in previous versions of Deadline too. Some of you may wonder why anyone would do this when the Deadline Repository installer will download and install MongoDB for you? Well, controlling your own MongoDB installation gives greater control over things like customization, security, and authentication, whereas our Repository installer only installs MongoDB with the minimum configuration required to use it with Deadline. For example, if MongoDB releases a security patch, you can upgrade your manual installation to stay up-to-date, which is something Deadline doesn't do for you.
Our documentation actually covers manually installing MongoDB, but it only focuses on installing MongoDB from the zip/tar files that you can download from the MongoDB Download Center. This blog post is meant to supplement the documentation by covering two additional ways of manually installing MongoDB.
On Linux and Mac OS X, package managers make this process fast and simple in that they do most, if not all, of the hard work for us. For this walkthrough, we'll be using yum on a CentOS machine, but this carries over to other operating system equivalents like apt and homebrew. Just make sure to check Deadline's system requirements to confirm the versions of MongoDB that are supported.
Note that almost all of these instructions will be executed through the terminal and will mostly require administrator access.
To start this off we need to create a yum repository file.
sudo touch /etc/yum.repos.d/mongodb-org-3.0.repo
This will tell yum what version of MongoDB we want to download (latest 3.0 version) and where to find it. Depending on your familiarity with yum you can customize this file, otherwise we can copy and paste MongoDB's recommended settings for version 3.0.
[mongodb-org-3.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/ gpgcheck=0 enabled=1
With that complete, it's time to let yum do the hard work and install the latest 3.0 version. As a side note, the mongodb-org package will install all of the associated mongodb packages.
sudo yum install -y mongodb-org
Note that if you'd like to use the specific version of MongoDB that Deadline 8.0 downloads and installs for you, then you'll have to specify the 3.0.6 version for each package.
sudo yum install -y mongodb-org-3.0.6 mongodb-org-server-3.0.6 mongodb-org-shell-3.0.6 mongodb-org-mongos-3.0.6 mongodb-org-tools-3.0.6
This will install the MongoDB executables to /usr/bin/ and the configuration file to /etc/mongod.conf. The configuration file will be where you can really customize your MongoDB installation, with a full list of options located in MongoDB's configuration documentation. For our purposes, the variables we care about are:
- dbPath: Where MongoDB stores the data. The default value is /var/lib/mongo.
- systemLog: Where MongoDB stores the log files. The default value is /var/log/mongodb/mongod.log.
- port: The port MongoDB listens on. The default value is 27017.
You can change these values, as long as the paths exist and the port is open. For example, if you installed MongoDB through the Deadline Repository installer, then the database will listen on 27080.
In later versions of MongoDB, yum will also install the /etc/init.d/mongod script, which allows MongoDB to run as a daemon. If this script wasn't installed, then you have the following options:
- Grab the init.d script we use from our Manual MongoDB installation documentation.
- Grab the init.d script from MongoDB's github page.
- Create your own, if you're so inclined.
If you had to create the mongod init.d script, you'll need to ensure that it has executable permissions by running the following command.
sudo chmod 755 /etc/init.d/mongod
With your options set in the mongod.conf file and the init.d script in place, you can now start the MongoDB daemon with the following command:
sudo service mongod start
If everything has gone smoothly thus far, then you'll receive a success message that looks like this:
If you're still not convinced that it's running properly, then you can verify that by looking at the running MongoDB processes:
ps aux | grep mongo
Looking at the output, we can see that the mongod process is running with the configuration file as a command-line argument, which is exactly what we wanted!
Unlike Linux and Mac OS X, Windows doesn't come with a preinstalled package manager. However, MongoDB does provide an MSI installer to make installation just as easy.
You can download the MSI installer from the MongoDB Download Center, and copy it to the machine you want to install it on. If you want an older version of MongoDB, you'll have to select All Version Binaries in the Download Center and choose your preferred version.
Running the installer in interactive mode is fairly straight forward. Simply double-click the MSI file, and choose whether you want to do a Complete or Custom installation. Note that if you choose the Custom option, you can choose where MongoDB is installed to.
You can also run the installer in unattended mode, but it must be from a command prompt with administrative privileges. It's possible to specify the install location using this method as well. For example:
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-3.0.14-signed.msi INSTALLLOCATION="C:\Program Files\MongoDB\Server\3.0\" ADDLOCAL="all"
Now that MongoDB is installed, you still need to create a configuration file and create a Windows service for MongoDB. Thankfully, an example configuration file can be found in the Deadline documentation. Where you store the created configuration file is up to you, but for the sake of this walkthrough, I'll assume it's called mongodb.conf, and that it's stored in the MongoDB bin directory.
With your configuration file created (ie. C:\Program Files\MongoDB\Server\3.0\bin\mongod.conf), you're ready to create the Windows service. With an administrative prompt, run the following command:
sc create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.0\bin\mongod.exe\" --config \"C:\Program Files\MongoDB\Server\3.0\bin\mongod.conf\" --service" start= auto depend= TCPIP DisplayName= "MongoDB Service"
That was a doozy, but now we're able to start the service.
sc start MongoDB
Which gave us output verifying that it's started up!
FINISHING THE MONGODB SETUP
With MongoDB installed through one of the above methods, you can now run the Deadline Repository installer to finish setting up your MongoDB with Deadline. When prompted, choose Connect to an existing MongoDB database installation, which brings you to the MongoDB Database Settings page of the installer:
Ensure that port number you specify in the installer is the same as the one specified in your MongoDB configuration file (ie: /etc/mongod.conf). Deadline 8.0 uses 27080 by default, whereas MongoDB uses 27017 by default. With the proper information inserted, you can continue your Deadline installation as normal!
While the Deadline Repository installer can take care of the MongoDB installation for you, if you need a highly customized, up-to-date MongoDB installation, you can't beat a manual installation.
Mongo and MongoDB are registered trademarks of MongoDB, Inc.