First step: Download the installation package
Download version: 3.0.1
Download Link:http://www.mongodb.org/downloads
First, unzip the installer in Linux
Operation by Command:
Decompression: [Root@localhost soft]# TAR-ZXVF mongodb-linux-i686-3.0.1.tgz
The decompression process is as follows:
We renamed the mongodb-linux-i686-3.0.1.tgz unpacked folder to MongoDB .
We put a new data directory in the MongoDB directory to hold the information, create a new log directory to hold the log, and then create a new log file under the directory, for example, we named Mongodb.log
DOS Code
[Email protected] mongodb]# mkdir log
[Email protected] mongodb]# mkdir data
[[Email protected] mongodb]# CD log
[email protected] log]# Touch Mongodb.log
and navigate to the Mongodb/bin directory.
Use the Mongod command to establish a MongoDB database link with the port number set to 100001 (default port is 27017), the database path is/mongodb/data, and the log path is/mongodb/log/mongodb.log
Start Command :
DOS Code
[email protected] mongodb]#/bin/mongod-port 10001--dbpath data/--logpath log/mongodb.log
Use the client to connect to the database
Re-open a terminal and switch to the MongoDB directory:
DOS Code
[Email protected]/]# CD Usr/local/mongodb
Then use the Bin/mongo command to connect to the database
DOS Code
[Email protected] mongodb]#./bin/mongo localhost:10001
MongoDB Shell version:3.0.1
Connecting To:localhost:10001/test
>
Inserting values into the database
DOS Code
Connecting To:localhost:10001/test
> Db.foo.save ({A:1})
Querying from the database
DOS Code
> Db.foo.find ()
{ "_id": ObjectId ("4ee66eb440ef7803a9873d2d"), "a": 1}
>
Access via browser
In the browser address bar, enter: http://localhost:10001/ and then enter to access
You can see the following tip: It looks like you is trying to access MongoDB over HTTP on the native driver port.
Configuring MongoDB with configuration Files
First create a new file in the MongoDB directory, the file name arbitrary, here I named: mongodb.conf
DOS Code
[Email protected] mongodb]# VI mongodb.conf
Then add the configuration information in the configuration file
TXT code
port=10001
dbpath=data/
Logpath=log/mongodb.log
Logappend=true
Explanatory notes:
Port=10001 "represents the port number and defaults to 27017 if not specified "
dbpath=data/"Database Path"
Logpath=log/mongodb.log "Log Path"
Logappend=true "Log files automatically accumulate, not overwrite"
Start MongoDB Service
DOS Code
[Email protected] mongodb]#/bin/mongod-f mongodb.conf
All output Going To:log/mongodb.log
and then access the same way as before.
Ubuntu Installation MongoDB database