Thứ Tư, 27 tháng 11, 2019

Install MongoDB 4.2 on CentOS/RHEL 8/7/6

MongoDB has released a new stable version 4.2 with lots of major enhancements. This tutorial latest tested on CentOS 7 and help you to install MongoDB 4.2 on CentOS 8/7/6 and RHEL 8/7/6 systems.

Step 1 – Add MongoDB Yum Repository

Add the following content in yum repository configuration file mongodb.repo as per your required MongoDB version and system architecture. For this article, we are using 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.2/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Step 2 – Install MongoDB Server

Let’s use the yum package manager to install mongodb-org package, it will automatically install all its dependencies. To install any specific revision of MongoDB specify package name with version like mongodb-org-4.0.0. The following command will install the latest stable version available.
sudo yum install mongodb-org

Step 3 – Start MongoDB Service

Package mongodb-org-server provided MongoDB init script, Use that script to start service.
systemctl start mongod.service    # For CentOS 8/7 
service mongod restart            # For CentOS 6 
Configure MongoDB to autostart on system boot.
systemctl enable mongod.service    # For CentOS 8/7 
chkconfig mongod on                # For CentOS 6 

Step 4 – Check MongoDB Version

Use the following command to check installed MongoDB version
[root@tecadmin ~]# mongod --version

db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64
Connect MongoDB using the command line and execute some test commands for checking proper working.
[root@tecadmin ~]#  mongo

> use mydb;

> db.test.save( { a: 1 } )

> db.test.find()

  { "_id" : ObjectId("54fc2a4c71b56443ced99ba2"), "a" : 1 }

Congratulation’s You have successfully installed mongodb server on your system. For practice only you may use MongoDB browser shell.
Nguồn bài đăng: tecadmin.net

Không có nhận xét nào:

Đăng nhận xét