How To Install MongoDB 4 on CentOS 6 / RHEL 6

0

MongoDB is an open source, document-oriented database designed with both scalability and developer agility in mind. Instead of storing your data in tables and rows as you would with a relational database, in MongoDB you store JSON-like documents with dynamic schemas.

MongoDB is available for Windows, Linux, OS X, and Solaris, MongoDB is available for free under the GNU Affero General Public License. The language drivers are available under an Apache License.

Here is the tutorial about installing latest MongoDB( MongoDB 4.0.5 ) on CentOS 6 / RHEL 6.

Starting from version 3.4, MongoDB no longer supports 32-bit operating systems.

Switch to the root user.

$ su -

Set up MongoDB Repository

The MongoDB package is not available in the base repository, and the version available in the EPEL repository is too old. So, we will set up MongoDB repository on the system to get the latest version of MongoDB package.

Create a repository file under the /etc/yum.repos.d directory.

vi /etc/yum.repos.d/mongodb.repo

Add the following line.

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

Install MongoDB

Install MongoDB package using the yum command.

yum install -y mongodb-org

Control MongoDB Service

MongoDB can be started/stopped by easy known commands.

To start MongoDB service, run:

service mongod start

To stop MongoDB service, run: (if required)

service mongod stop

To check the status of MongoDB service, run:

service mongod status

Confirm the version of MongoDB.

mongod --version

Output:

db version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel62
    distarch: x86_64
    target_arch: x86_64

Access MongoDB

Run the below command to access MongoDB shell.

mongo

Output:

MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("965553bd-6ffd-4357-89a2-064f20a9a605") }
MongoDB server version: 4.0.5
Server has startup warnings: 
2019-01-18T03:09:32.611+0000 I STORAGE  [initandlisten] 
2019-01-18T03:09:32.611+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-01-18T03:09:32.611+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-01-18T03:09:33.351+0000 I CONTROL  [initandlisten] 
2019-01-18T03:09:33.351+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-18T03:09:33.351+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-01-18T03:09:33.351+0000 I CONTROL  [initandlisten] 
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] 
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] 
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] 
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

Fix MongoDB errors

Error 1

019-01-18T03:09:32.611+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-01-18T03:09:32.611+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem

To clear this issue, use XFS filesystem.

Error 2

2019-01-18T03:09:33.351+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-18T03:09:33.351+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

To resolve this issue, edit the configuration file and enable access control.

vi /etc/mongod.conf

Add below lines to the mongod.conf file.

security:
  authorization: enabled

Error 3

2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] 
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-18T03:09:33.352+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

To clear this issue, you need to disable transparent huge pages.

Error 4

2019-01-18T03:09:33.352+0000 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.

To clear this issue, set ulimit.

That’s all.

Further Reading

You might also like

How To Install MongoDB 4 on CentOS 6 / RHEL 6

0