Mongodb installation script (with server self-booting)

Source: Internet
Author: User
Tags install mongodb touch

First, the purpose

To simplify the MongoDB quick Install deployment, and add to the service startup item, boot up.

Second, the script

2.1 GitHub Address

GitHub links
2.2 Script Content

#!/bin/bash#mail:[email protected] #function: Auto Install mongodb[$ (id-u)! = "0"] && echo "Error:you must Be root to run this script "&& exit 1[$ (rpm-q centos-release|cut-d--f3)! =" 6 "] && echo" please use C entos6.x "&& exit 1clearecho" ########################################## "echo" # Auto Install MongoDB for CentOS 6.x # # "echo" # Press Ctrl + C to cancel # # ' echo ' # any key To continue # # "echo" ########################################## "echo" (1) Install M ongodb-3.2 "echo" (2) Install Mongodb-3.4 "echo" (3) Install Mongodb-3.6 "echo" (4) EXIT "read-p" Please input your choice: " Numcase $NUM in1) mongodb_url= "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.20.tgz" soft Ware_version= "mongodb-3.2";; 2) mongodb_url= "Https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.10.tgz" Software_versioN= "mongodb-3.4";; 3) mongodb_url= "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.5.tgz" software_version= "mo ngodb-3.6 ";; 4) echo-e "\033[41;37m You choice channel! \033[0m "&& exit 0; *) echo-e "\033[41;37m Input error! Place input{1|2|3|4} \033[0m "&& exit 1; Esacclearsoftdir= "/software" installdir= "/usr/local" Sys_init () {CLEARECHO-E "\033[42;5m initialization system ... \ 033[0m "Sleep 2sed-i" s/selinux=enforcing/selinux=disabled/"/etc/selinux/config/etc/init.d/iptables status >/dev /null[$?-eq 0] && iptables-i input-p TCP--dport 27017-j accept[$?-eq 0] &&/etc/init.d/iptables Saveyum-y Install wget >/dev/nullsetenforce 0}download_software () {clearecho-e "\033[42;5m download software ... \033  [0m] Sleep 2if [!-D ${softdir}];then mkdir ${softdir} && CD ${softdir}else CD ${softdir}fifor Software_url In ${mongodb_url}do wget-c ${software_url} If [$?-eq 0];then foR software in ' ls ' do tar zxf $software-c $installdir done Fidone}install_software () {Clearec HO-E "\033[42;5m Install server ... \033[0m" Sleep 2mongodbdir=$ (ls ${installdir}|grep "mongodb-linux-x86_64") ln-s ${ Installdir}/${mongodbdir} ${installdir}/mongodbmkdir ${installdir}/mongodb/{conf,mongodata,mongolog}touch ${ Installdir}/mongodb/mongolog/mongodb.logecho "Export path=\ $PATH: ${installdir}/mongodb/bin" >/etc/profile.d/ Mongodb.shsource/etc/profile.d/mongodb.shcat >${installdir}/mongodb/conf/mongodb.conf <<EOFdbpath=${ Installdir}/mongodb/mongodatalogpath=${installdir}/mongodb/mongolog/mongodb.loglogappend=truejournal=truequiet =trueport=27017pidfilepath=/var/run/mongod.pid#replset =rsmaxconns=20000#httpinterface=truefork=true#auth= Trueeof}start_server () {CLEARECHO-E "\033[42;5m configuration server ... \033[0m" Cat >/etc/init.d/mongodb-server <<eof#!/bin/bash#auth:kaliarch# MongoDB Startup script for MongoDB processes## chkconfig: 90 10# Description:mongodb provides fast memory based storage.# Processname:mongodb. /etc/rc.d/init.d/functionsbash_dir= "/usr/local/mongodb" mongod= "\${bash_dir}/bin/mongod" config= "\${bash_dir}/ Conf/mongodb.conf "getpid=\$ (pidof mongod) lockfile=" \${bash_dir}/mongodb.lock "pidfile="/var/run/mongod.pid "#user    =nobodystart () {action $ "starting \ $prog:"/bin/true # starting MongoDB on port 27017 as Deamon and user nobody    \ $mongod-F \${config} >/dev/null retval=$? [\ $RETVAL = 0] && touch \${lockfile} return \ $RETVAL}stop () {if test "x\${getpid}"! = x; then ACTI    On $ "stopping \ $prog"/bin/true killall mongod fi retval=\$? [\ $RETVAL = 0] && rm-rf \${lockfile} \${pidfile} return \ $RETVAL}case "\$1" in Start) star        t;;        stop) stop;;            Status) status-p \${pidfile} \${mongod} retval=\$?        ;;  Restart) stop start          ;; *) echo $ "Usage: \$0 {start|status|stop|restart}" exit 1esacexit \${retval}eofcd/chmod +x/etc/init . d/mongodb-serverchkconfig mongodb-server Onservice mongodb-server start}check_server () {CLEARECHO-E "\033[42;5m Check Server Status ... \033[0m "server_port=$ (Netstat-lntup|grep mongod|wc-l) server_proc=$ (ps-ef |grep mongodb.conf| Grep-v grep|wc-l) if [${server_port}-gt 0-a ${server_port}-gt 0];thenecho-e "\033[42;37m mongodb-server install suc cessful! \033[0m "Echo-e" \033[42;37m version:${software_version} \033[0m "Echo-e" \033[42;37m bashpath:${installdir}/mongodb \ 033[0m "ELSEECHO-E" \033[42;37m MongoDB install error! \033[0m "Fi}main () {Sys_initdownload_softwareinstall_softwarestart_servercheck_server}main
Third, testing





Mongodb installation script (with server self-booting)

Related Article

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.