这段时间都在折腾mongodb,把笔记整理了一下,发布出来,希望对大家有用。
mongodb就不叙述了,如果你没有听过,还是不要往下面看了。
首先下载mongodb,建议使用3.x版本
win http://www.mongodb.org/dl/win32/
linux http://www.mongodb.org/dl/linux/
无疑,下面介绍的是linux下面的安装。
其实安装也没有怎么说,直接查看你服务器系统版本,下载官方的二进制包,解压启动服务就可以,或者你也可以使用源码包编译,这里介绍的直接二进制包。
#!/bin/bash #果果.IT www.guoguo.it #mongodb自动安装 yum install -y wget wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz echo "===install mongodb===" mongoduser=mongod mongodgroup=mongod replSetstr=mongoSet mongoport=27010 mongohttpport=`expr ${mongoport} + 1000` mongodinstallpath=/usr/local/mongodb${mongoport} mongotarname="mongodb-linux-x86_64-rhel62-3.0.7" mongotarpath="./${mongotarname}.tgz" mongobindir="./${mongotarname}/bin/" if [ -d ./${mongobindir} ]; then echo "find mongod dir" elif [ -f ./${mongotarpath} ]; then tar zxf ${mongotarpath} else #exit 4 echo "failed" fi echo "== set mongod user" id ${mongoduser} >& /dev/null if [ $? -ne 0 ];then groupadd $mongodgroup useradd -s /sbin/nologin -g $mongodgroup $mongoduser else echo "${mongoduser} is existing! pass useradd" fi echo "== Create mongodb directory" #默认安装目录为/usr/local/mongodb mkdir -p ${mongodinstallpath}/bin mkdir -p ${mongodinstallpath}/etc mkdir -p ${mongodinstallpath}/scripts touch ${mongodinstallpath}/etc/mongod.conf touch ${mongodinstallpath}/etc/keyfile cp ${mongobindir}/* ${mongodinstallpath}/bin/ chown -R $mongoduser:$mongod ${mongodinstallpath} #chmod -R 755 /usr/local/mongodb chmod 400 ${mongodinstallpath}/etc/keyfile echo "== mkdir db directory" #默认数据文件存放目录为/db/mongodb databasepath=/db/mongodb${mongoport}/ mkdir -p ${databasepath}/dbs mkdir -p ${databasepath}/logs chown -R $mongoduser:$mongodgroup ${databasepath} echo " set mongod.conf" cat <<EOF > ${mongodinstallpath}/etc/mongod.conf dbpath=${databasepath}/dbs pidfilepath=${databasepath}/dbs/mongod.pid logpath=${databasepath}/logs/mongodb.log logappend=true directoryperdb = true port=${mongoport} fork = true auth=true replSet=$replSetstr oplogSize=10240 #keyFile=${mongodinstallpath}/etc/keyfile nohttpinterface=true #rest=true storageEngine=wiredTiger wiredTigerCacheSizeGB=6 wiredTigerStatisticsLogDelaySecs=0 wiredTigerJournalCompressor=snappy wiredTigerDirectoryForIndexes=true wiredTigerCollectionBlockCompressor=snappy wiredTigerIndexPrefixCompression=1 EOF echo "set keyfile" #keyfile每个集群都是不一样的,但是同一个集群要统一 #echo "repl replication" > ${mongodinstallpath}/etc/keyfile echo "===mongodb install end==="
好吧,直接写成一键安装脚本,直接运行上面脚本即可安装mongdb3.0.7 ,可以修改上面端口,目录,下载的版本安装其他版本。
最后说一下,果果用的是centos6.x版本,其他版本请自行测试。
/usr/local/mongodb27010/bin/mongod -f /usr/local/mongodb27010/etc/mongod.conf
启动mongodb,安装完毕。
转载请注明:果果.IT » 果果.IT 笔记-Mongodb安装篇