Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Install MongoDB on Linux platform

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MongoDB provides 64-bit installation packages for all linux distributions, which you can download from the official website.

Download address: https://www.mongodb.com/download-center#community

Download the installation package and extract the 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 # extract mv mongodb-linux-x86_64-3.0.6 / / usr/local/mongodb # copy the unzipped package to the specified directory

The executable file for MongoDB is located in the bin directory, so you can add it to the PATH path:

Export PATH=/bin:$PATH

The installation path for your MongoDB. Such as / usr/local/mongodb in this article.

Create a database directory

MongoDB's data is stored in the db directory of the data directory, but this directory is not automatically created during installation, so you need to manually create the data directory 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 MongoDB startup database path (--dbpath).

Mkdir-p / data/db

Run the MongoDB service on the command line

You can start the mongdb service by executing the mongod command in the bin directory in the mongo installation directory from the command line.

Note: if your database directory is not / data/db, you can specify it with-- 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=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 backend manages Shell

If you need to enter 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, which is used to operate and manage MongoDB.

When you enter the mongoDB background, it will link 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:

> 2x 24 > 3m 69

Now let's insert some simple data and retrieve the inserted data:

> db.runoob.insert ({nInserted 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 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 startup.

$. / mongod-dbpath=/data/db-rest

MongoDB has 1000 more Web interface access ports than service ports.

If your MongoDB running port uses the default 27017, you can access the web user interface at port 28017, that is, http://localhost:28017.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report