Skip to content

Instantly share code, notes, and snippets.

@chappy84
Last active January 23, 2018 16:11
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save chappy84/4400325 to your computer and use it in GitHub Desktop.
Save chappy84/4400325 to your computer and use it in GitHub Desktop.
Install MongoDB from source on Fedora/RedHat based Linux with SystemD
#!/bin/sh
# MongoDB Version
MONGODB_VER='2.2.2'
# Get all the dependencies up to date
yum -y update
yum -y install scons gcc-c++ glibc-devel
# Get the source
cd /usr/local/src/
wget http://downloads.mongodb.org/src/mongodb-src-r$MONGODB_VER.tar.gz
tar xfz mongodb-src-r$MONGODB_VER.tar.gz
cd mongodb-src-r$MONGODB_VER
# Compile and Install
scons all
scons install
# Create the SystemD dependant files
echo '[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target network.target
[Service]
Type=forking
User=mongod
Group=mongod
PIDFile=/var/run/mongodb/mongod.pid
EnvironmentFile=/etc/sysconfig/mongod
ExecStart=/usr/local/bin/mongod $OPTIONS run
[Install]
WantedBy=multi-user.target' > /lib/systemd/system/mongod.service
echo 'OPTIONS="--quiet -f /etc/mongod.conf"' > /etc/sysconfig/mongod
# Setup the required user and group
useradd -r -U mongod
# Setup the required directories
mkdir -p /var/run/mongodb/
mkdir -p /var/log/mongo/
mkdir -p /var/lib/mongo/
chown mongod:mongod /var/run/mongodb/
chown mongod:mongod /var/log/mongo/
chown mongod:mongod /var/lib/mongo/
chmod 0755 /var/log/mongo/
chmod 0755 /var/run/mongodb/
chmod 0755 /var/lib/mongo
# Start the new service and enable it on boot
systemctl --system daemon-reload
systemctl start mongod.service
systemctl enable mongod.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment