MongoDB provides a 64-bit installation package for each Linux distribution, and you can download the installation package on the website.
: https://www.mongodb.com/download-center#community
Download the installation package and unzip the tgz (The following shows the installation on 64-bit Linux).
curl -o https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # Download tar -zxvf mongodb-linux-x86_64-3.0.6.tgz # Decompression mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb # Copy the unpacked package to the specified directory
mongodb executable file is located in the bin directory, so it can be added to path in Path:
export path=<mongodb-install-directory>/bin: $PATH
<mongodb-install-directory> for your MongoDB installation path. As the /usr/local/mongodb of this article.
Create a database directory
MongoDB data is stored in the DB directory in the database directory, but this directory is not created automatically during the installation process, so you need to create the data directory manually and create the DB directory in the data directory.
In the following example we create the data directory under the root directory (/).
Note:/DATA/DB is the default startup database path for MongoDB (--dbpath).
Mkdir-p/data/db
Run MongoDB service on the command line
You can then execute the mongod command to start the MONGDB service by executing the bin directory in the MONGO installation directory on the command line.
Note: If your database directory is not/data/db, you can specify it through--dbpath.
$./mongod2015-09-25t16:39:50.549+0800 I JOURNAL [Initandlisten] JOURNAL dir=/data/db/journal2015-09-25t16:39:50.550 +0800 i JOURNAL [initandlisten] recover:no JOURNAL files present, no recovery needed2015-09-25t16:39:50.869+0800 I JOUR NAL [Initandlisten] preallocateisfaster=true 3.162015-09-25t16:39:51.206+0800 I JOURNAL [Initandlisten] Preallocateisfaster=true 3.522015-09-25t16:39:52.775+0800 I JOURNAL [Initandlisten] preallocateisfaster=true 7.7
MongoDB Background Management Shell
If you need to get into MongoDB background management, you need to first open the bin directory under the MongoDB directory and then execute the MONGO command file.
The MongoDB Shell is an interactive JavaScript shell that comes with MongoDB and is used to manipulate and manage MongoDB.
$ cd /usr/local/mongodb/bin$ ./mongomongodb shell version: 3.0.6connecting to: testwelcome to the mongodb shell ....
because it's a JavaScript shell, you can run some simple arithmetic operations:
> 2+24> 3+69
Now let's insert some simple data and retrieve the inserted data:
> db.runoob.insert ({x:10}) Writeresult ({ "ninserted" &NBSP;:&NBSP;1&NBSP;}) > Db.runoob.find () { "_id" : objectid ("5604FF74A274A611B0C990AA"), "X" &NBSP;:&NBSP;10&NBSP;}
The first command inserts the number 10 into the X field of the Runoob collection.
MongoDb Web user interface
MONGODB provides a simple HTTP user interface. If you want to enable this feature, you need to specify the parameter--rest at boot time.
$ ./mongod --dbpath=/data/db --rest
MongoDB's Web interface access port is 1000 more than the service's port.
If your MongoDB run port uses the default of 27017, you can access the Web user interface at the port number 28017, that is, the address is: http://localhost:28017.
Linux Platform Installation MongoDB