Download work:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.5.tgz
Unzip the downloaded file to the specified directory
Tar XF mongodb-linux-x86_64-rhel62-3.4.5.tgz-c/usr/
MV mongodb-linux-x86_64-rhel62-3.4.5 MONGO
Create data storage directory, log file directory, master configuration file directory
Mkdir/data/dbmkdir/usr/mongo/logmkdir/usr/mongo/conf
Create a log file
Cd/usr/mongo/logtouch Mongo.log
Finish this and then run the program.
cd/usr/mongo/bin./mongod-port=21707--dbpath=/data/db--logpath=/usr/mongo/log/mongo.log
This is the way the foreground starts the MongoDB process, and if the session window closes, the MongoDB process also stops. But MongoDB also provides a background daemon way to start, only need to add a "--fork" parameter, it is worth noting that the "--fork" parameter must be enabled "--logpath" parameter.
Nohup./bin/mongod--dbpath data/--logpath Log/mongodb.log &
Or use nohup this brought life in the background, generally use--fork parameters, but also to see personal habits!
-------------------------------------------------------------------------------------------------------------
Each boot needs to manually specify the log files, data storage location is too cumbersome, you can create a profile, the program every time you start to specify the contents of the configuration file, convenient many!
Cd/usr/mongo/congvim mongo.conf
port=21707
dbpath=/data/db/
Logpath=/usr/mongo/log/mongo.log
Logappend=true #这里的参数是日志文件的内容是追加的形式添加, if you do not write this parameter, add the form of the overlay
Fork=true #这里是启动后台执行程序
Start the program
./usr/mongo/bin/mongod-f/usr/mongo/conf/mongo.conf #参数都将按照配置文件的内容启动
————————————————————————————————————————————————————
Test:
Re-open a terminal
./usr/mongo/bin/mongo 127.0.0.1:21707 #注意这里的程序文件是mongo
In the database, enter
Insert value into Database > Db.foo.save ({a:1}) Writeresult ({"ninserted": 1}) query from Database > Db.foo.find () {"_ ID ": ObjectId (" 54f02e3b577c993352468185 ")," a ": 1}
Ok!
MongoDB Learning (a) Centos6.5 installation of MongoDB