How to install MongoDB 2.6 on linux
官网地址:http://www.mongodb.org;
1. Download the binary files for the desired release of MongoDB.
wget http://124.202.164.12/files/113100000380F0C3/fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.0.tgz
2. Extract the files from the downloaded archive.
tar zxvf mongodb-linux-x86_64-2.6.0.tgz
3.Add new user ,Copy the extracted archive to the target directory.
useradd mongo
mkdir -p /mongodb
mkdir -p /data/db
chown -R mongo.mongo /mongodb
chown -R mongo.mongo /data/db
cp -R -n mongodb-linux-i686-2.6.0/ mongodb
TIP:
Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must specify that directory in the dbpath option when starting the mongod process later in this procedure.
for example ,specify to /mongo/data
mongod –journal –dbpath /mongo/data/;
4. Ensure the location of the binaries is in the PATH variable.
su – mongo
vi ~/.bash_profile
#Append
export PATH=/mongodb/mongodb-linux-x86_64-2.6.0/bin:$PATH
5. Run MongoDB
sh# mongod &
6 . verify
# check stat. [mongo@db231 bin]$ mongostat # manage [mongo@db231 ~]$ mongo MongoDB shell version: 2.6.0 connecting to: test 2014-04-28T14:40:30.748+0800 [initandlisten] connection accepted from 127.0.0.1:53531 #1 (1 connection now open) Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user > show dbs; admin (empty) local 0.078GB > show collections fs.chunks fs.files system.indexes > db test > db.testtab.insert({id:"01", name : 'anbob', addr : 'beijing'}); WriteResult({ "nInserted" : 1 }) > db.testtab.insert({id:"02", name : 'weejar', addr : 'beijing', blog : 'www.weejar.com'}); WriteResult({ "nInserted" : 1 }) > db.testtab.find(); { "_id" : ObjectId("535e17dac20010e9435a87a9"), "id" : "01", "name" : "anbob", "addr" : "beijing" } { "_id" : ObjectId("535e17fac20010e9435a87aa"), "id" : "02", "name" : "weejar", "addr" : "beijing", "blog" : "www.weejar.com" } > db.testtab.find({name:'weejar'}); { "_id" : ObjectId("535e17fac20010e9435a87aa"), "id" : "02", "name" : "weejar", "addr" : "beijing", "blog" : "www.weejar.com" } > db.testtab.update({name:'weejar'},{blog:'www.anbob.com'}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.testtab.find({name:'weejar'}); > db.testtab.find(); { "_id" : ObjectId("535e17dac20010e9435a87a9"), "id" : "01", "name" : "anbob", "addr" : "beijing" } { "_id" : ObjectId("535e17fac20010e9435a87aa"), "blog" : "www.anbob.com" } > db.testtab.remove({blog:'www.anbob.com'}); WriteResult({ "nRemoved" : 1 }) > db.testtab.count(); 1 >
7. shutdown mongoDB
[mongo@db231 bin]$ mongod -shutdown
killing process with pid: 25403
对不起,这篇文章暂时关闭评论。