Skip to content

Instantly share code, notes, and snippets.

@diggzhang
Created August 6, 2015 13:23
Show Gist options
  • Save diggzhang/df83f364e5a3b5f7a4ff to your computer and use it in GitHub Desktop.
Save diggzhang/df83f364e5a3b5f7a4ff to your computer and use it in GitHub Desktop.
#!/bin/sh
# mongodb部署脚本
# https://gist.github.com/chappy84/4400325/download#
# diggzh 2015/7/2
# MongoDB Version
MONGODB_DISC='linux-x86_64'
MONGODB_VER='3.0.4'
TAR_TGZ='tgz'
# SetupDir
SETUP_DIR=/home/master/Download/
# 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-$MONGODB_DISC-$MONGODB_VER.$TAR_TGZ
tar xfz mongodb-$MONGODB_DISC-$MONGODB_VER.$TAR_TGZ
cd mongodb-$MONGODB_DISC-$MONGODB_VER.$TAR_TGZ
# Cp Install
cp * /usr/bin/
# 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