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

How to install MongoDB in Linux version

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "Linux version of how to install MongoDB", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux version how to install MongoDB" bar!

1. Environmental introduction

Linux environment application installation, there are mainly several standard ways: yum type integrated installation, set up the repository, the latest version of the installation and dependent package in one go; to solve the package dependency problem, using rpm or even zip compressed files to install directly; the last more "advanced", is to obtain the software source code, directly compile and install at the operating system level. In this article, the author uses the second way of compressing files for basic installation. The environment uses Red Hat version 6.5.

[root@oracle-test /] # cat / etc/redhat-release

Red Hat Enterprise Linux Server release 6.5 (Santiago)

Download the corresponding installation file from the official MongoDB website.

[root@oracle-test upload] # ls-l

Total 98124

-rw-r--r--. 1 root root 100477926 Jul 13 22:39 mongodb-linux-x86_64-rhel62-3.4.5.tgz

2. Install the system

Like Oracle and MySQL, we try not to use the root user as the database running principal. It is best to create a dedicated database user account.

[root@oracle-test /] # groupadd mongodb

[root@oracle-test /] # useradd-g mongodb mongodb

[root@oracle-test /] # id mongodb

Uid=501 (mongodb) gid=501 (mongodb) groups=501 (mongodb)

Create a separate directory to prevent unzipping files.

[root@oracle-test /] # mkdir / mongodb

[root@oracle-test /] # chown-R mongodb:mongodb mongodb

[root@oracle-test /] # ls-l | grep mongodb

Drwxr-xr-x. 2 mongodb mongodb 4096 Jul 13 22:38 mongodb

[root@oracle-test upload] # cp mongodb-linux-x86_64-rhel62-3.4.5.tgz / mongodb/

Extract the file:

[root@oracle-test mongodb] # tar zxvf mongodb-linux-x86_64-rhel62-3.4.5.tgz

Mongodb-linux-x86_64-rhel62-3.4.5/README

(for reasons of space, there are omissions. )

Mongodb-linux-x86_64-rhel62-3.4.5/bin/mongod

Mongodb-linux-x86_64-rhel62-3.4.5/bin/mongos

Mongodb-linux-x86_64-rhel62-3.4.5/bin/mongo

Set database user account permissions.

[root@oracle-test mongodb] # chown-R mongodb:mongodb *

[root@oracle-test mongodb] # ls-l

Total 4

Drwxr-xr-x. 3 mongodb mongodb 4096 Jul 13 22:41 mongodb-linux-x86_64-rhel62-3.4.5

Enter the unzipped directory and you can see the main bin folder, including most of the functional components. Among them, mongod is the database instance running program process and the core of Mongodb. Mongo, also known as mongo shell, is a client program similar to sqlplus. Others, such as import and export, backup and restore, are basically not different from other commercial databases.

[root@oracle-test mongodb-linux-x86_64-rhel62-3.4.5] # cd bin

[root@oracle-test bin] # ls-l

Total 277044

-rwxr-xr-x. 1 mongodb mongodb 10359081 Jun 14 05:37 bsondump

-rwxr-xr-x. 1 mongodb mongodb 29860072 Jun 14 06:02 mongo

-rwxr-xr-x. 1 mongodb mongodb 54387648 Jun 14 06:02 mongod

-rwxr-xr-x. 1 mongodb mongodb 12696783 Jun 14 05:38 mongodump

-rwxr-xr-x. 1 mongodb mongodb 10711297 Jun 14 05:38 mongoexport

-rwxr-xr-x. 1 mongodb mongodb 10593233 Jun 14 05:37 mongofiles

-rwxr-xr-x. 1 mongodb mongodb 10867956 Jun 14 05:38 mongoimport

-rwxr-xr-x. 1 mongodb mongodb 10361065 Jun 14 05:38 mongooplog

-rwxr-xr-x. 1 mongodb mongodb 53756680 Jun 14 06:02 mongoperf

-rwxr-xr-x. 1 mongodb mongodb 14000016 Jun 14 05:39 mongoreplay

-rwxr-xr-x. 1 mongodb mongodb 14054073 Jun 1405: 38 mongorestore

-rwxr-xr-x. 1 mongodb mongodb 30523368 Jun 14 06:02 mongos

-rwxr-xr-x. 1 mongodb mongodb 10931198 Jun 14 05:37 mongostat

-rwxr-xr-x. 1 mongodb mongodb 10557955 Jun 14 05:38 mongotop

3. Run and connect to the database

For convenience, add the bin path of mongodb to the PATH variable of the mongodb user.

[root@oracle-test bin] # su-mongodb

[mongodb@oracle-test ~] $vi .bash _ profile

PATH=$PATH:$HOME/bin

PATH=$PATH:/mongodb/mongodb-linux-x86_64-rhel62-3.4.5/bin

Export PATH

~

The first time you start, execute the mongod command directly from the command line to start the database.

[mongodb@oracle-test ~] $mongod

2017-07-13T22:47:36.872+0800 I CONTROL [initandlisten] MongoDB starting: pid=18996 port=27017 dbpath=/data/db 64-bit host=oracle-test

2017-07-13T22:47:36.872+0800 I CONTROL [initandlisten] db version v3.4.5

2017-07-13T22:47:36.872+0800 I CONTROL [initandlisten] git version:

(for reasons of space, there are omissions. )

2017-07-13T22:47:36.872+0800 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory / data/db not found., terminating

2017-07-13T22:47:36.872+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...

2017-07-13T22:47:36.872+0800 I NETWORK [initandlisten] shutdown: going to flush diaglog...

2017-07-13T22:47:36.872+0800 I CONTROL [initandlisten] now exiting

2017-07-13T22:47:36.872+0800 I CONTROL [initandlisten] shutting down with code:100

The database stopped after trying to start because the data directory did not exist. The default data directory is / data/db,Windows environment and C:\ data\ db. If you need to specify your own directory, you need to use the mongod parameter configuration. Let's add:

[root@oracle-test /] # mkdir-p / data/db

[root@oracle-test /] # chown-R mongodb:mongodb / data

[root@oracle-test /] # ls-l | grep data

Drwxr-xr-x. 3 mongodb mongodb 4096 Jul 13 22:49 data

The operation succeeded:

[mongodb@oracle-test ~] $mongod

2017-07-13T22:50:24.098+0800 I CONTROL [initandlisten] MongoDB starting: pid=19087 port=27017 dbpath=/data/db 64-bit host=oracle-test

2017-07-13T22:50:24.098+0800 I CONTROL [initandlisten] db version v3.4.5

(for reasons of space, there are omissions. )

2017-07-13T22:50:24.249+0800 I NETWORK [thread1] waiting for connections on port 27017

Connect from a remote client, normal.

:\ Users\ admin > mongo-- host 172.16.19.143

MongoDB shell version v3.4.5

Connecting to: mongodb://172.16.19.143:27017/

MongoDB server version: 3.4.5

Server has startup warnings:

2017-07-13T23:31:25.215+0800 I STORAGE [initandlisten]

(for reasons of space, there are omissions. .)

2017-07-13T23:31:25.771+0800 I CONTROL [initandlisten]

>

Thank you for your reading, the above is the "Linux version of how to install MongoDB" content, after the study of this article, I believe you on the Linux version of how to install MongoDB this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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