Install MongoDB database under CentOS7

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 between relational and non-relational databases. It is the most versatile and most like relational database among non-relational databases. The data structure it supports is very loose, and it is a bson format similar to json, so it can store more complex data types.

The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is similar to an object-oriented query language. It can almost achieve most of the functions similar to single-table queries in relational databases, and it also supports indexing of data.

The following describes the installation of MongoDB under CentOS7

1、 Download the rpm installation package of the RHEL7 version of MongoDB Server and the rpm installation package of the MongoDB shell from the official website

https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.1-1.el7.x86_64.rpm

https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-shell-4.2.1-1.el7.x86_64.rpm

2、 rpm -ivh to install

rpm -ivh mongodb-org-server-4.2.1-1.el7.x86_64.rpm

rpm -ivh mongodb-org-shell-4.2.1-1.el7.x86_64.rpm

3、 Start MongoDB service

systemctl start mongod.service

And set it to start systemctl enable mongod.service

The default listening port of the MongoDB database is 27017

Enter mongo to log in to the database and enter the shell command line

4、 MongoDB commonly used commands

show dbs: View the database list;

db: View the current database;

db.createCollection('The name of the table to be created'): Create a new table;

show collections: View the tables under the current database;

db.table name.drop(): delete the specified table in the current database

db.dropDatabase(): delete the current database

show users: View all users in the current library

db.cloneDatabase("127.0.0.1"): Clone the data of the database on the specified machine to the current database

db.copyDatabase("mydb", "temp", "127.0.0.1"): Copy the data of the local mydb to the temp database

db.repairDatabase(): Repair the current database

db.getName(): View the currently used database

db.stats(): Display the current db status

db.version(): current db version

db.getMongo(): View the link machine address of the current db

db.serverStatus().connections.current: View the current number of connections

5、 Create administrator and database accounts

use admin
db.createUser({
 user:"admin",
 pwd:"P@ssw0rd",
 roles:[{ role:"root", db:"admin"},{ role:"userAdminAnyDatabase", db:"admin"}]})

Create a test database Lab and the database account

use Lab
db.createUser({
 user:"yuanfan",
 pwd:"lab@2019",
 roles:[{ role:"dbOwner", db:"Lab"}]})

And insert the test data db.Lab.insert({"name":"yuanfan"})

The default database in MongoDB is test. If you do not create a new database, the collection will be stored in the test database.

Note: In MongoDB, the collection will only be created after the content is inserted, that is to say, after creating the collection (data table), insert a document (record) before the collection is actually created

6、 Turn on account authentication and remote access

[ root@VM_Server ~]# cp /etc/mongod.conf /etc/mongod.conf_bak
[ root@VM_Server ~]# vi /etc/mongod.conf

Modify the following two places

bindIp:0.0.0.0
security:
 authorization: enabled

Remember, all colons in the configuration file must be followed by a space!
Do not write in the top box on the second line, add two spaces

Then restart the mongod service systemctl restart mongod.service

7、 Log in with account and password when logging in by shell

mongo -u "yuanfan"-p "Lab@2019"--authenticationDatabase "Lab"

8、 Use database management visualization tools

1) E.g. Navicat

  1. Free version of Robo 3T

Robo3T integrates the mongoDB shell, you can right-click the database to open the Shell

Recommended Posts

Install MongoDB database under CentOS7
Install Oracle11gR2 database under CentOS6.9
CentOS 6.8 under linux install mongodb
Install mysql5.7 under CentOS7
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
Install MongoDB on CentOS 7
Centos7 install mongodb 4.x
Install mysql under Centos 7
Centos7 install Mysql database
Install MariaDB under MariaDB Centos7
Install mysql5.1 under CentOS6.5
Install MySQL under Linux (CentOS 7)
Centos6.5 install and configure mongodb
Install Java JDK8 under CentOS6
Install Mesos tutorial under CentOS7
1.5 Install Centos7
Install and configure keepalived under CentOS 5.9
[Introduction to redis] Install redis under Centos
Install Percona Server database (in CentOS 8)
Install Harbor mirror warehouse under CentOS
​Install Oracle database on CentOS Linux
CentOS7.2 install lepus database monitoring system
Install the latest OpenCV4.3 under Centos8
Install and use docker under CentOS 6.8
How to install MongoDB on CentOS 7
Install Python3 and Py under CentOS7
How to install MongoDB on CentOS 8
Install Mono 3.2 and Jexus 5.4 under CentOS 6.3
Compile and install libmodbus library under CentOS7
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
CentOS7 install MySQL
Centos7 install protobuf
CentOS 7 install Docker
CentOS7 install GlusterFS
CentOS 7.4 install Zabbix 3.4
CentOS7 install Docker
Centos6.5 install Tomcat
Vmware install CentOS6
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
Install mysql8.0.13 version under Linux CentOS7 system
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
CentOS6 install mist.io
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
centos7 install docker