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 and configure MongoDB

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly explains "how to install and configure MongoDB". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to install and configure MongoDB.

System environment:

[root@D2-LZY245 ~] # cat / etc/centos-release

CentOS Linux release 7.2.1511 (Core)

If it is the RHEL6 version, you need to upgrade openssl first:

[root@oeldb1 ~] # rpm-qa | grep openssl

Openssl-devel-1.0.1e-57.el6.x86_64

Openssl098e-0.9.8e-17.0.1.el6_2.2.x86_64

Openssl-1.0.1e-57.el6.x86_64

Installation package and version:

Download address: https://www.mongodb.com/download-cente

[root@D2-LZY245 ~] # ll mongodb-linux-x86_64-rhel70-3.4.7.tgz

-rw-rw-r-- 1 root root 100670645 Aug 10 17:06 mongodb-linux-x86_64-rhel70-3.4.7.tgz

Create the installation directory:

[root@D2-LZY245 ~] # mkdir / usr/local/mongodb

Extract the installation package:

[root@D2-LZY245] # tar-xvzf mongodb-linux-x86_64-rhel70-3.4.7.tgz

Move the extracted files to the installation directory:

[root@D2-LZY245] # mv mongodb-linux-x86_64-rhel70-3.4.7Universe * / usr/local/mongodb/

[root@D2-LZY245 ~] # ll / usr/local/mongodb/

Total 120

Drwxrwxr-x 2 root root 4096 Aug 10 17:11 bin

-rw-r--r-- 1 root root 34520 Aug 8 03:37 GNU-AGPL-3.0

-rw-r--r-- 1 root root 16726 Aug 8 03:37 MPL-2

-rw-r--r-- 1 root root 1359 Aug 8 03:37 README

-rw-r--r-- 1 root root 55625 Aug 8 03:37 THIRD-PARTY-NOTICES

Configure PATH:

[root@D2-LZY245 ~] # grep PATH .bash _ profile

PATH=$PATH:$HOME/bin

Export PATH

Export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

Export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH:/usr/local/mongodb/bin/

[root@D2-LZY245 ~] # source .bash _ profile

Create database directories and log files:

[root@D2-LZY245 ~] # mkdir / usr/local/mongodb/db

[root@D2-LZY245 ~] # mkdir / usr/local/mongodb/log

[root@D2-LZY245 ~] # touch / usr/local/mongodb/log/mongodb.log

Create a parameter file:

[root@D2-LZY245 ~] # vim / usr/local/mongodb/mongodb.conf

Dbpath=/usr/local/mongodb/db

Logpath=/usr/local/mongodb/log/mongodb.log

Logappend=true

Noauth=true

Port=27017

Fork=true

Start:

[root@D2-LZY245] # mongod-f / usr/local/mongodb/mongodb.conf

About to fork child process, waiting until server is ready for connections.

Forked process: 12610

Child process started successfully, parent exiting

Configure boot up:

[root@D2-LZY245 ~] # vi / etc/rc.d/rc.local

/ usr/local/mongodb/bin/mongod-f / usr/local/mongodb/mongodb.conf

When the MongoDB service starts, you can use the mongo command to connect to the database.

[root@oeldb1 ~] # mongo

MongoDB shell version v3.4.7

Connecting to: mongodb://127.0.0.1:27017

MongoDB server version: 3.4.7

Welcome to the MongoDB shell.

# query all databases:

> show databases

Admin 0.000GB

Local 0.000GB

# close the database.

> use admin

Switched to db admin

> db.shutdownServer ()

Or:

[root@oeldb1] # mongod-f / usr/local/mongodb/mongodb.conf-- shutdown

Killing process with pid: 11580

At this point, I believe you have a deeper understanding of "how to install and configure MongoDB". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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