Recently in the study of MongoDB database, wrote a fully automatic installation of MongoDB database shell script, for reference only, welcome to shoot bricks, the contents are as follows:
#!/bin/bash# Shell Execution Options: #-N reads only the shell script, but does not actually execute #-x Enter the tracking mode, showing each command executed #-C"string"read command from strings # download directory Downloadsdir=/root/downloads# installation directory Appdir=/usr/local/mongodb# determine if the backup directory exists, and create a new directory when not in storage [! -D $downloadsDir] &&mkdir-p $downloadsDircd $downloadsDir # download Mongodbcurl-O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.7.tgz# Unzip MongoDBTar-ZXVF mongodb-linux-x86_64-2.6.7. tgzRM-RF $appDirmkdir-P $appDir # Copy the MongoDB database file into the $appdir directoryCP-r/root/downloads/mongodb-linux-x86_64-2.6.7/*$appDirmkdir-P $appDir/data/dbmkdir-p $appDir/logmkdir-p $appDir/confmkdir-p $appDir/binchmod-r 777 $APPDIRCD $a Ppdir/confecho "################################ zhaoxiace DEFINE ##############################" >> Mongod.confecho "port=27017 #指定服务端口号, default port 27017" >> mongod.confecho "Dbpath=data #指定数据库路径" >> Mongod.confecho "Logpath=log/mongod.log #指定MongoDB日志文件" >> mongod.confecho "Auth=false #启用验证" >> Mongod.confecho "Fork=true #以守护进程的方式运行MongoDB, creating a server process" >> MONGOD.CONFCD. /# start in Repair mode #./bin/mongod-f conf/mongod.conf--repair# start the Mongd service./bin/mongod-f conf/mongod.conf# connect to the database./bin/mongo
Shell scripts for fully automated MongoDB database installation