1. 下载二进制版的安装文件:
文件版本:mongodb-linux-x86_64-2.6.11.tgz
下载地址:https://www.mongodb.org/downloads
整合配置文件模板及服务器安装文件的版本:mongodb-linux-x86_64-2.6.11.tar.gz
2. 解压二进制版安装文件:
# cd/usr/local/src
# tar xzvfmongodb-linux-x86_64-2.6.11.tar.gz
# mvmongodb-linux-x86_64-2.6.11 /usr/local/mongodb
#/usr/local/mongodb/bin/mongo --version
MongoDB shellversion: 2.6.11
3. 设置环境变量:
# vi /etc/profile
exportPATH=/usr/local/mongodb/bin:$PATH
# source/etc/profile
4. 创建数据存储目录:
# mkdir -p/data/mongod
## 本例中使用主从模式,直接以参数形式启动服务器后台进程
5. 启动主服务器:
# /usr/local/mongodb/bin/mongod--dbpath=/data/mongod --logpath=/usr/local/mongodb/mongod.log --master--oplogSize 256 --logappend --port=27017 --fork
# vi /etc/rc.local
/usr/local/mongodb/bin/mongod--dbpath=/data/mongod --logpath=/usr/local/mongodb/mongod.log --master--oplogSize 256 --logappend --port=27017 --fork
6. 启动从服务器:
# /usr/local/mongodb/bin/mongod--dbpath=/data/mongod --logpath=/usr/local/mongodb/mongod.log --slave --source10.6.1.77 --slavedelay 10 --autoresync --logappend --port=27017 --fork
# netstat -ant
tcp 0 0 10.6.1.78:35833 10.6.1.77:27017 ESTABLISHED
# vi/usr/local/mongodb/mongod.log
2015-09-24T17:56:31.542+0800[replslave] repl: syncing from host:10.6.1.77
2015-09-24T17:56:31.544+0800[replslave] repl: applied 1 operations
2015-09-24T17:56:31.544+0800[replslave] repl: syncedTo: Sep 2417:56:20 5603c8c4:1
2015-09-24T17:56:31.544+0800[replslave] waiting until: 1443088601 to continue
2015-09-24T17:56:31.544+0800[replslave] repl: sleep 10 sec before next pass
# vi /etc/rc.local
/usr/local/mongodb/bin/mongod--dbpath=/data/mongod --logpath=/usr/local/mongodb/mongod.log --slave --source10.6.1.77 --slavedelay 10 --autoresync --logappend --port=27017 --fork
## 如果使用单服务器模式,可将/usr/local/mongodb/support-files中的配置文件模板及服务器安装文件用上:
# cp/usr/local/mongodb/support-files/mongod.conf /etc/mongod.conf
# vi /etc/mongod.conf
logpath=/usr/local/mongodb/mongod.log
port=27017
dbpath=/data/mongod
pidfilepath=/usr/local/mongodb/mongod.pid
# cp/usr/local/mongodb/support-files/init.d-mongod /etc/rc.d/init.d/mongod
# chmod 755 /etc/rc.d/init.d/mongod
# chkconfig mongodon
# vi /etc/rc.d/init.d/mongod
mongod=${MONGOD-/usr/local/mongodb/bin/mongod}
MONGO_USER=root
MONGO_GROUP=root
killproc -p"$PIDFILE" -d 300 /usr/local/mongodb/bin/mongod
# service mongodstart
# mongo
转载于:https://blog.51cto.com/3803569/1765454