MongoDB is an extremely flexible index support and rich query database. It is a NoSQL database that provides a grid for large media storage. MongoDB has released a new stable version 4.0 with many major new features. This article will introduce how to install MongoDB 4.0 on CentOS 7/6 and Red Hat 7/6 systems.
Step 1: Add MongoDB yum repository
According to the required MongoDB version and system architecture, configure the yum repository Add the following content to the file mongodb.repo. For this article, we are using a MongoDB 4.0 repository.
CentOS and RedHat systems only
# vi /etc/yum.repos.d/mongodb.repo
[MongoDB] name=MongoDB Repository baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/ gpgcheck=0 enabled=1
Fedora users can install it from its official yum repository.
Step 2: Install MongoDB Server
Let us use the yum package manager to install the mongodb-org package, which will automatically install all its dependencies. To install any specific version of MongoDB, specify the package name, such as mongodb-org-4.0.0. The following command will install the latest stable version.
# yum install mongodb-org
Step 3: Start the MongoDB service
The mongodb org server package provides the mongodb init script, use this script to start the service.
# /etc/init.d/mongod restart
Configure MongoDB to start automatically when the system starts.
# chkconfig mongod on
Step 4: Check MongoDB version
Check the installed MongoDB version using the following command
[root@tecadmin ~]# mongod --version db version v4.0.0 git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51 OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010 allocator: tcmalloc modules: none build environment: distmod: amazon distarch: x86_64 target_arch: x86_64
Connect to MongoDB using the command line and execute some Test the command to check if it works properly.
[root@tecadmin ~]# mongo > use mydb; > db.test.save( { a: 1 } ) > db.test.find() { "_id" : ObjectId("54fc2a4c71b56443ced99ba2"), "a" : 1 }
The MongoDB server has been successfully installed on the system.
This article has ended here. For more other exciting content, you can pay attention to the MongoDB Video Tutorial column on the PHP Chinese website!
The above is the detailed content of How to install MongoDB4.0 on CentOS and RHEL. For more information, please follow other related articles on the PHP Chinese website!