Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB installation and multiple instances enabled by MongoDB

Shulou Source: shulou.com Published: 2022-06-01 13:04:18 10月03日 Update

MongoDB installation method

I. compilation and installation by hand

Software package Baidu network disk

Link: https://pan.baidu.com/s/19oPP-3k7MiPsemO2cLsdng password: k86h

1. Mount the local file and decompress it to the opt directory.

Tar zxf mongodb-linux-x86_64-rhel70-4.0.0.tgz-C / opt/

2. Move the extracted package to the / usr/local/ directory and rename it

Mv mongodb-linux-x86_64-rhel70-4.0.0 / / usr/local/mongodb

3. Create a configuration file

Cd / usr/local/mongodb/bin / / go to the bin directory of MongoDB first

Vim mongodb.conf / / create a configuration file directory

Dbpath = / usr/local/mongodb/data/db

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

Port = 27017

Fork = true

Chmod + x mongodb.conf / execute permissions to the newly created configuration file mkdir-p / usr/local/mongodb/data/db Recursive create data file storage directory mkdir-p / usr/local//mongodb/logs/ recursive creation log file storage directory cd / usr/local//mongodb/logs/touch mongodb.log / create log file

4. Add environment variables

Sed-I'$an export MONGODB_HOME=/usr/local/mongodb' / etc/profile

Sed-I'$an export PATH=$PATH:$MONGODB_HOME/bin' / etc/profile

Sed-I'$a PATH=$PATH:/usr/local/mongodb/bin' / etc/profile

Add the environment of MongoDB to the system environment and let the system identify

Source / etc/profile / / refresh environment variables

5. Start MongoDB

Cd / usr/local/mongodb/bin

Mongod-f\ mongodb.conf (executed under the bin directory) starts

Mongod-- config\ mongodb.conf-- shutdown is closed

6. Log in to MongoDB database using mongo

2. Yum one click to install MongoDB

1. Create a yum warehouse

Vim / etc/yum.repos.d/mongodb-org.repo / / write the following command

[mongodb-org]

Name=MongoDB Repository

Baseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/

Gpgcheck=1

Enabled=1

Gpgkey= https://www.mongodb.org/static/pgp/server-3.6.asc

2. Install the database

Yum clean all

Yum list

Yum install-y mongodb-org

3. Modify the configuration file

Vi / etc/mongod.conf / / change the following

BindIp: 0.0.0.0 # listening address

Port: 27017 # listening port

4. Start the service, check the port, and log in to MongoDB

Systemctl start mongod.service

Netstat-anpt | grep 27017

Mongo / / enter the database

Db.version () / / View the database version

3. Enable multiple instances in MongoDB

And use the MongoDB installed by yum to do the experiment.

Copy the configuration file and modify it

Cp-p / etc/mongod.conf / etc/mongod2.conf / / copy configuration file

Vim / etc/mongod2.conf / / modify a few items

Path: / data/mongodb/mongod2.log / / change the directory where log files are stored

DbPath: / data/mongodb/mongo / / change the data storage directory

Port: 27018 / / change the port number

Second, create the corresponding file directory

Mkdir-p / data/mongodb/mongo / / create a data storage directory

Cd / data/mongodb/

Touch mongod2.log / / create a log storage directory

Chmod 777mongod2.log / / guarantees a 777permission to allow others to read and write

Third, start the service

Mongod-f / etc/mongod2.conf / / start the service

Mongo-- port 27018 / / Log in using this port number

Tags: Directories files data configuration databases logs environment services logins variables slogans permissions ports systems one-click recursion monitoring instances warehouses content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Shulou Tech Info Shulou Technology Shulou Information