Download install start and connect the mongodb database

  • 2020-12-16 06:11:19
  • OfStack

This article describes the mongodb database download, installation, startup, and connection operations. To share for your reference, the details are as follows:

Brief introduction:

MongoDB is a database based on distributed file storage. Written by C++ language. Designed to provide scalable, high-performance data storage solutions for WEB applications.

MongoDB is a product that lies between relational and non-relational databases. It is the most featureless and most relational database like among non-relational databases.

1, download

Download the package from the official website,

Website address: https: / / www mongodb. com/download - center/v2 / community.

Download command:


wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.3.tgz

2, decompression


tar zxvf mongodb-linux-x86_64-rhel70-4.0.3.tgz
# Move the directory to where you want it 
rm -rf /usr/local/mongodb/
mv mongodb-linux-x86_64-rhel70-4.0.3 /usr/local/mongodb

Introduction to the catalogue:

3. Start the service

The MongoDB data is stored in the data directory under the db directory, but this directory is not automatically created during the installation process, so you need to manually create the data directory and the db directory.

Note:

(1) /data/db is the default startup database path for MongoDB. The custom specified path is configured using the parameter --dbpath.

(2) After creating the directory, pay attention to check the directory permission, or it will fail to start.

(3) Since mongodb takes up disk space, check the available space to configure the location of data and log storage (ES59en-ES60en), and reserve about 4G. If you add --smallfiles option when starting, it will only take about 400M.

Activation:


[test@localhost bin]$ ./mongod --dbpath=/mongodb/db --logpath=/mongodb/log/mongodb.log --fork --port=27017
2018-10-16T13:35:44.345+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 1415
child process started successfully, parent exiting

Parameter interpretation:

--dbpath data storage directory
--logpath log storage directory
--fork backend process running

4. Connection service


[test@localhost bin]$ ./mongo
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("65e265a1-bb45-4842-9c1b-b6171dc5d178") }
MongoDB server version: 4.0.3
....
>


>show databases;
admin  0.000GB
config 0.000GB
local  0.000GB

I hope this article has been helpful to the MongoDB database programming.


Related articles: