"Mongdb Ops" Mongdb automatic installation Script--rpm package installation version

Source: Internet
Author: User
Tags install mongodb

#!/bin/bash
# version:v1.0 by Jason_asia on 2014-05-14
# Desc:auto Install MongoDB RPM packages


Software_dir=/home/dba/software/mongodb

##{{{Check MongoDB Install status

Mongod_thread_status= "' NETSTAT-NLTP | grep Mongod | Wc-l ' "

If [${mongod_thread_status}-gt 0];then
echo "Critical:mongod is running."
Exit
Fi

[' which Mongod '] && echo "Critical:mongodb have been installed on this server." && exit

##}}}


##{{{Install MongoDB RPMs
function Rpm_install () {
echo "Info:start to install Mongo-10gen and mongo-10gen-server ..."

# Check RPMs
CD $software _dir

Mongo_10gen_rpm= "mongo-10gen-[0-9]*mongodb*x86_64.rpm"
Mongo_10gen_server_rpm= "mongo-10gen-server-[0-9]*mongodb*x86_64.rpm"
# Examples:
# mongo-10gen-server-2.4.10-mongodb_1.x86_64.rpm
# mongo-10gen-2.4.10-mongodb_1.x86_64.rpm

mongo_10gen_status= "' ls ${mongo_10gen_rpm} >/dev/null 2>&1; echo $? ' "
mongo_10gen_server_status= "' ls ${mongo_10gen_server_rpm} >/dev/null 2>&1; echo $? ' "

if ["${mongo_10gen_status}"-ne 0];then
echo "Error:mongo-10gen doesn ' t exists in $software _dir/."
Exit
elif ["${mongo_10gen_server_status}"-ne 0];then
echo "Error:mongo-10gen-server doesn ' t exists in $software _dir/."
Exit
Else
echo "Info:mongo-10gen and Mongo-10gen-server are OK."
Fi

# Install MongoDB

RPM-IVH ${software_dir}/${mongo_10gen_rpm}
Mongo_10gen_install_status= "echo $?"
If [${mongo_10gen_install_status}-ne 0];then
echo "Error:mongo-10gen install failed."
Fi

RPM-IVH ${software_dir}/${mongo_10gen_server_rpm}
Mongo_10gen_server_install_status= "echo $?"
If [${mongo_10gen_server_install_status}-ne 0];then
echo "Error:mongo-10gen-server install failed."
Fi

echo "Info:mongodb Install Status:"
Rpm-aq |grep MONGO

echo "Info:finish installing MongoDB."
echo ""
}

##}}}

##{{{Set MongoDB configuration file
function Configure () {
echo "Info:start to configure MongoDB ..."

# Add User Mongd
Useradd Mongod

# Make MongoDB directories
Mkdir-p/home/mongodb
Chown-r Mongod.mongod/home/mongodb

Mongod_conf=/etc/mongod.conf

# check/etc/mongod.conf
if [!-F ${mongod_conf}];then
echo "Error:file ${mongod_conf} doesn ' t."
Exit
Fi


# Set Configurations
echo "Info:set ${mongod_conf}."

Sed-i ' 2 Amaster = True ' ${mongod_conf}

Sed-i ' 2 aport = 27017 ' ${mongod_conf}

Sed-i ' 2 Aauth = True ' ${mongod_conf}

Sed-i ' s/^pidfilepath\ (. *\)/#pidfilepath \1/g ' ${mongod_conf}
Sed-i ' 2 apidfilepath=/home/mongodb/mongod.pid ' ${mongod_conf}

Sed-i ' s/^dbpath\ (. *\)/#dbpath \1/g ' ${mongod_conf}
Sed-i ' 2 Adbpath=/home/mongodb ' ${mongod_conf}

Sed-i ' s/^logpath\ (. *\)/#logpath \1/g ' ${mongod_conf}
Sed-i ' 2 Alogpath=/home/mongodb/mongod.log ' ${mongod_conf}

Egrep ' ^dbpath|^logpath|^pidfilepath|^port ' ${mongod_conf}

# Set Mongod Service
echo "Info:set Mogod service autostart."
Chkconfig--level 2345 Mongod on
Chkconfig--list | grep Mongod

echo "Info:finish configuring MongoDB."
echo ""

}
##}}}


Rpm_install
Configure


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.