MongoDB Installation Script/startup script/configuration file

Source: Internet
Author: User

Installation scripts

#!/bin/bash  #author:  qingfeng#qq: 530035210#blog: http://my.oschina.net/pwd/blog # Automatic installation of MongoDB and initialization configuration # The default configuration is as follows  logdir=/data/log/shell            #日志路径log = $logdir/shell.log             #日志文件  is_font=1                  #终端是否打印日志:  1 printing  0 not printing  is_log=0                   #是否记录日志:  1 record  0 not recorded random_time=$ (date +%y%m%d_%h%m%s) Mongodb_pakges= "Mongodb-linux-x86_64-2.4.9.tgz"  mongodb_conf=mongodb.confmongodb_init=mongodbdatef () {Date   "+%y-%m-%d %h:%m:%s"} print_log () {if [[  $is _log -eq 1  ]];then[[  -d  $logdir  ]] | |  mkdir -p  $logdirecho   "[ $ (DATEF)  ] $1"  >>  $logfiif [[  $is _font -eq 1  ]];thenecho -e  "[ $ (DATEF)  ] $1 "fi}if [[  ! -f  $mongodb _conf ]];thenprint_log " MongoDB configuration file does not exist, exit: $mongodb _ Conf "exitelse.  $mongodb _conffi install () {If [[  -d  /usr/local/mongodb   ]];thenprint_log  "MongoDB has been installed, please do not repeat the installation:/usr/local/mongodb" exitfiprint_log  "unzip the file, please later ..." tar -zxf  $mongodb _pakges  -c /usr/local/mv /usr/local/$ (echo  $mongodb _ pakges|sed  "s/.tgz//g")    /usr/local/mongodbif [[  -d  /usr/local /mongodb  ]];thenprint_log  "MongoDB has been installed successfully:/usr/local/mongodb" elseprint_log  "MongoDB has failed to install :/usr/local/mongodb "fiif [[ -d  $dbpath   ]];thenprint_log " mongodb:  Data Catalog: $ DBPath already exists "elsemkdir -p   $dbpath  fi lastname=$ (echo " $logpath " |awk -f '/'   ' {print $nf } ') mongodblog=$ (echo  $logpath  | sed  "s/$lastname//g") if [[ -d $ mongodblog  ]];thenprint_log  "mongodb:  log directory: $mongodblog already exists" elsemkdir -p  $ mongodblogfi if [[ !  -d /usr/local/mongodb/conf ]];thenmkdir -p   /usr/local/mongodb/confcp  $mongodb _conf  /usr/local/mongodb/conffiprofile_num=$ (cat  /etc/profile |grep mongodb |wc -l) if [[  $profile _num -eq 0   ]];thenecho  "Mongodbpath=/usr/local/mongodb/bin:\ $PATH"   >> /etc/profileecho  " Export mongodbpath " >> /etc/profilefiif [[ ! -f  $mongodb _init    ]];thenprint_log  "mongodb:  startup script already exists." elsecp  $mongodb _init  /etc/init.d/chmod a+x /etc/init.d/$mongodb _initchkconfig - -add  $mongodb _initchkconfig  $mongodb _init onfi print_log  "Initialization configuration complete." print_log  "Data directory: $dbpath   log file: $mongodblog" print_log  "configuration directory is:/usr/local/mongodb/conf" Print_log   "Startup script:/etc/init.d/$mongodb _init"} install

Startup scripts

#!/bin/sh  # chkconfig: 2345 93 18  # author:qingfeng #  description:mongodb (MongoDB-2.4.9)    #默认参数设置 #mongodb  Home directory   mongodb_home=/usr/ local/mongodb#mongodb  Start command   mongodb_bin= $MONGODB _home/bin/mongod#mongodb  configuration file mongodb_conf= $MONGODB _home/conf/mongodb.conf#mongodb pidmongodb_pid=/var/run/mongo.pid# Maximum file open number limit system_maxfd=65535# mongodb  name   mongodb_name= "MONGODB".  /etc/rc.d/init.d/functionsif [ ! -f   $MONGODB _bin ]then        echo  "$MONGODB _name  startup:  $MONGODB _bin not exists!  "           exitfistart () { ulimit -hsn  $SYSTEM _maxfd  $MONGODB _bin --config= "$MONGODB _conf"    ret=$? if [  $ret  -eq 0 ]; then     action $ "starting  $MONGodb_name:  " /bin/true else    action $" Starting  $MONGODB _name:   " /bin/false fi      }stop () {         pid=$ (ps aux |grep  "$MONGODB _name"  |grep  "$MONGODB _conf"  |grep  -V GREP |WC -L)          if [[  $PID  -eq 0  ]];then        action $ "Stopping   $MONGODB _name:  " /bin/false        exit         fi        kill -HUP  ' Cat   $MONGODB _pid '         ret=$?         if [  $ret  -eq 0 ]; then                 action $ "stopping  $MONGODB _name: "  /bin/true                 rm -f  $MONGODB _pid         else                    action $ "stopping  $MONGODB _name: "  /bin/false        fi}restart ()  {         stop        sleep 2         start}case  "$"  in         Start)                 start                 ;;         sTop)                 stop                 ;;         status)         status   $prog                 ;;         restart)                  restart                 ;;         *)                  echo $ "Usage: $0 {start|stop|status|restart}" Esac

MongoDB configuration file

dbpath=/data/db #数据目录存在位置logpath =/data/logs/mongodb/mongodb.log #日志文件存放目录port =27017 #端口fork =true #以守护程序的方式启用, That is, in the background run #auth=true #开始认证verbose =truevvvv=true #启动verbose冗长信息, it has a level of vv~vvvvv,v more levels, the more information recorded in the log file. maxconns=20000 # Default value: Depends on the system (that is, the Ulimit and file descriptor) limits. MongoDB does not restrict its own connections. Logappend=true #写日志的模式: Set to True for append. Pidfilepath=/var/run/mongo.pid#cpu=true #设置为true会强制mongodb每4s报告cpu利用率和io等待 to write log messages to standard output or log files. Directoryperdb=ture #数据目录存储模式, if you directly modify the original data will be missing #nohttpinterface=false #28017 Port open Services. Default false, support #notablescan=false# does not prohibit table scan operation Profile=0 #数据库分析等级设置, 0 off 2 on. Includes all operations. 1 Open. Only slow operations are included. slowms=200 #记录profile分析的慢查询的时间, the default is 100 milliseconds. Quiet=true syncdelay=60 #刷写数据到日志的频率 to manipulate data by Fsync. Default 60 seconds


MongoDB Installation Script/startup script/configuration file

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.