Install MongoDB in Linux
MongoDB provides 32-bit and 64-bit installation packages on Linux. You can download the installation packages from the official website.
: Http://www.mongodb.org/downloads
Download the installation package and decompress tgz (the installation on 64-bit Linux is demonstrated below ).
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 # unzip mv mongodb-linux-x86_64-3.0.6 // usr/local/mongodb # copy the package to the specified directory
The executable file of MongoDB is located in the bin directory, so you can add it to the PATH:
export PATH=<mongodb-install-directory>/bin:$PATH
<Mongodb-install-directory> is your MongoDB installation path. For example,/usr/local/mongodb in this article.
Create Database directory
MongoDB data is stored in the db directory of the data directory, but this directory is not automatically created during the installation process. Therefore, you need to manually create the data DIRECTORY and create a 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 database path (-- dbpath) started by MongoDB ).
mkdir -p /data/db
Run the MongoDB service in the command line
You can execute the mongod command in the bin directory of the mongo installation directory in the command line to start the mongdb service.
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 JOURNAL [initandlisten] preallocateIsFaster=true3.162015-09-25T16:39:51.206+0800 I JOURNAL [initandlisten] preallocateIsFaster=true3.522015-09-25T16:39:52.775+0800 I JOURNAL [initandlisten] preallocateIsFaster=true7.7
MongoDB background management Shell
If you need to go to the MongoDB background management, you need to first open the bin directory under the mongodb installation directory, and then execute the mongo command file.
MongoDB Shell is an interactive Javascript shell that comes with MongoDB. It is used to operate and manage MongoDB in an interactive environment.
When you enter the mongoDB background, it will be linked to the test document (database) by default ):
$ cd /usr/local/mongodb/bin$ ./mongoMongoDB shell version:3.0.6connecting to: testWelcome to the MongoDB shell.……
Because it is a JavaScript shell, you can run some simple arithmetic operations:
>2+24>3+69
Now let's insert some simple data and search the inserted data:
> db.runoob.insert({x:10})WriteResult({"nInserted":1})> db.runoob.find(){"_id":ObjectId("5604ff74a274a611b0c990aa"),"x":10}>
The first command inserts the number 10 into the x field of the runoob set.
MongoDb web user interface
MongoDB provides a simple HTTP user interface. If you want to enable this function, you must specify the parameter -- rest at startup.
$ ./mongod --dbpath=/data/db --rest
The MongoDB Web interface access port is 1000 more than the service port.
If your MongoDB running port uses the default 27017 port, you can access the web user interface on port 28017, that is, the address is http: // localhost: 28017.
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: