Installing and configuring MongoDB on Oracle Enterprise Linux.

In this article I am installing MongoDB on Oracle Enterprise Linux 7 (OEL 7). This is 64 bit OEL 7 Installation. Installing MongoDB community Edition is done using yum repository. 

First step is to create a /etc/yum.repos.d/mongodb-org-4.2.repo file so that you can install MongoDB directly using yum:

[root@snode1 yum.repos.d]# cat mongodb-enterprise-4.2.repo
[mongodb-enterprise-4.2]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.2/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Install the MongoDB package

To install the latest stable version of MongoDB, issue the following command:

sudo yum install -y mongodb-org

This should install mongodb-org-4.2.2,mongodb-org-mongos-4.2.2,mongodb-org-server-4.2.2,mongodb-org-shell-4.2.2,mongodb-org-tools-4.2.2

Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
Installing:
mongodb-org x86_64 4.2.2-1.el6 mongodb-org-4.2 5.8 k
Installing for dependencies:
mongodb-org-mongos x86_64 4.2.2-1.el6 mongodb-org-4.2 14 M
mongodb-org-server x86_64 4.2.2-1.el6 mongodb-org-4.2 25 M
mongodb-org-shell x86_64 4.2.2-1.el6 mongodb-org-4.2 17 M
mongodb-org-tools x86_64 4.2.2-1.el6 mongodb-org-4.2 47 M
Transaction Summary
Install 1 Package (+4 Dependent packages)
Total download size: 103 M
Installed size: 260 M
Downloading packages:
warning: /var/cache/yum/x86_64/7Server/mongodb-org-4.2/packages/mongodb-org-4.2.2-1.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 058f8b6b: NOKEY
Public key for mongodb-org-4.2.2-1.el6.x86_64.rpm is not installed
(1/5): mongodb-org-4.2.2-1.el6.x86_64.rpm | 5.8 kB 00:00:01
(2/5): mongodb-org-mongos-4.2.2-1.el6.x86_64.rpm | 14 MB 00:00:05
(3/5): mongodb-org-server-4.2.2-1.el6.x86_64.rpm | 25 MB 00:00:07
(4/5): mongodb-org-shell-4.2.2-1.el6.x86_64.rpm | 17 MB 00:00:03
(5/5): mongodb-org-tools-4.2.2-1.el6.x86_64.rpm | 47 MB 00:00:09
Total 5.7 MB/s | 103 MB 00:00:18

By default, MongoDB runs using the mongod user account and uses the following default directories:

  • /var/lib/mongo (the data directory)
  • /var/log/mongodb (the log directory)
[root@snode1]# ps -ef | grep mongod
mongod 77877 1 1 2019 ? 04:18:24 /usr/bin/mongod -f /etc/mongod.conf
root 85957 83003 0 09:56 pts/0 00:00:00 grep --color=auto mongod

[root@snode1]# ls -ls /var/lib/mongo
total 1948
4 drwxr-xr-x. 39 root root 4096 Dec 27 07:32 ..
4 -rw------- 1 mongod mongod 21 Dec 27 07:35 WiredTiger.lock
4 -rw------- 1 mongod mongod 47 Dec 27 07:35 WiredTiger
4 -rw------- 1 mongod mongod 4096 Dec 27 07:35 WiredTigerLAS.wt
0 drwx------ 2 mongod mongod 107 Dec 27 07:35 journal
4 -rw------- 1 mongod mongod 6 Dec 27 07:35 mongod.lock
4 -rw------- 1 mongod mongod 114 Dec 27 07:35 storage.bson
20 -rw------- 1 mongod mongod 20480 Dec 27 07:36 index-3-3088403881070738327.wt
20 -rw------- 1 mongod mongod 20480 Dec 27 07:36 collection-2-3088403881070738327.wt
20 -rw------- 1 mongod mongod 20480 Dec 27 07:36 index-1-3088403881070738327.wt
20 -rw------- 1 mongod mongod 20480 Dec 27 07:36 collection-0-3088403881070738327.wt
20 -rw------- 1 mongod mongod 20480 Jan 3 11:51 index-9-3088403881070738327.wt
28 -rw------- 1 mongod mongod 28672 Jan 3 11:51 collection-8-3088403881070738327.wt
24 -rw------- 1 mongod mongod 24576 Jan 3 12:31 collection-4-3088403881070738327.wt
12 -rw------- 1 mongod mongod 12288 Jan 3 12:32 index-6-3088403881070738327.wt
312 -rw------- 1 mongod mongod 319488 Jan 3 14:05 index-11-3088403881070738327.wt
36 -rw------- 1 mongod mongod 36864 Jan 3 14:05 _mdb_catalog.wt
12 -rw------- 1 mongod mongod 12288 Jan 3 14:05 index-5-3088403881070738327.wt
36 -rw------- 1 mongod mongod 36864 Jan 3 14:06 sizeStorer.wt
1284 -rw------- 1 mongod mongod 1314816 Jan 3 14:06 collection-10-3088403881070738327.wt
68 -rw------- 1 mongod mongod 69632 Jan 3 14:07 WiredTiger.wt
4 -rw------- 1 mongod mongod 1191 Jan 3 14:07 WiredTiger.turtle
4 drwxr-xr-x 4 mongod mongod 4096 Jan 3 14:07 .
4 drwx------ 2 mongod mongod 4096 Jan 6 09:55 diagnostic.data

Please note if you are using tarball installation, MongoDB directories has to be pre-created.

MongoDB uses configuration file configuration file /etc/mongod.conf

[root@snode1]# cat /etc/mongod.conf 
mongod.conf
for documentation of all options, see:
http://docs.mongodb.org/manual/reference/configuration-options/
where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
engine:
wiredTiger:
how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
security:
operationProfiling:
replication:
sharding:
Enterprise-Only Options
auditLog:
snmp:

To change the default data directories, dbPath can be edited to appropriate path. Same way log location also can be changed in systemLog.

Starting mongodB can done using

sudo service mongod start

If it was started successfully, you will see waiting for connection message in the /var/log/mongodb/mongod.log. By default mongoDB listen on port 27017. It can be changed in the  /etc/mongod.conf´╗┐

2019-12-27T07:35:01.810-0800 I  FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data'
2019-12-27T07:35:01.814-0800 I NETWORK [initandlisten] Listening on /tmp/mongodb-27017.sock
2019-12-27T07:35:01.814-0800 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version:
2019-12-27T07:35:01.814-0800 I NETWORK [initandlisten] Listening on 127.0.0.1
2019-12-27T07:35:01.815-0800 I NETWORK [initandlisten] waiting for connections on port 27017

You can also connect to mongodb shell using mongo command

[root@snode1]# mongo
MongoDB shell version v4.2.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("ec707ce2-b072-4860-a06b-ec0d726cc68c") }
MongoDB server version: 4.2.2
Server has startup warnings:
2019-12-27T07:35:01.756-0800 I CONTROL [initandlisten]
2019-12-27T07:35:01.756-0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-12-27T07:35:01.756-0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-12-27T07:35:01.756-0800 I CONTROL [initandlisten]
MongoDB Enterprise > show databases
admin 0.000GB
business 0.000GB
config 0.000GB
local 0.000GB
test 0.002GB

In the next article, I am going to import a database and connect using Tableau

Leave a reply