MongoDB automatic installation and deployment this article is divided into two parts: MongoDB automatic installation directory description; MongoDB automatic installation script content. The first part of MongoDB automatic installation script directory Description: # ls view the current directory -- install_mongodb.sh # MongoDB automatic installation script -- mongo-10gen-2.4.10-mongodb_1.x86_64.rpm # mo
MongoDB automatic installation and deployment this article is divided into two parts: MongoDB automatic installation directory description; MongoDB automatic installation script content. The first part of MongoDB automatic installation script directory Description: # ls view the current directory -- install_mongodb.sh # MongoDB automatic installation script -- mongo-10gen-2.4.10-mongodb_1.x86_64.rpm # mo
Automatic MongoDB installation and deployment
This article consists of two parts:
Description of the automatic installation directory of MongoDB;
MongoDB automatic installation script content.
Part 1
MongoDB automatic installation script directory description:
# Ls view the current directory
-- Install_mongodb.sh # MongoDB automatic installation script
-- Mongo-10gen-2.4.10-mongodb_1.x86_64.rpm # mongodb installation package
-- Mongo-10gen-server-2.4.10-mongodb_1.x86_64.rpm # mongodb installation package
Part 2
########################### Start of the MongoDB automatic installation script content (install_mongodb.sh) #######################
#! /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
Export d_thread_status = "'netstat-nltp | grep mongod | wc-l "'
If [$ {mongod_thread_status}-gt 0]; then
Echo "Critical: running D is running ."
Exit
Fi
['Which mongod'] & echo "Critical: mongodb has 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"
Export _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
Export _10gen_status = "'ls $ {export _10gen_rpm}>/dev/null 2> & 1; echo $? "'
Export _10gen_server_status = "'ls $ {export _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}/$ {pai_10gen_rpm}
Performance_10gen_install_status = "echo $? "
If [$ {cmd_10gen_install_status}-ne 0]; then
Echo "Error: mongo-10gen install failed ."
Fi
Rpm-ivh $ {software_dir}/$ {pai_10gen_server_rpm}
Performance_10gen_server_install_status = "echo $? "
If [$ {cmd_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
Export d_conf =/etc/export D. 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 = 100' $ {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. Pi' $ {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 your d service
Echo "Info: set mogod service autostart ."
Chkconfig -- level 2345 mongod on
Chkconfig -- list | grep mongod
Echo "Info: finish copying ing mongodb ."
Echo ""
}
##}}}
Rpm_install
Configure
########################## End of the MongoDB automatic installation script (install_mongodb.sh) #######################