MongoDB Database Installation Steps
I will install MongoDB community edition 7.0.9 on Oracle Linux Server release 8.7 with 4.18.0-425.3.1.el8.x86_64 kernel. MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK).
[root@mongo01 ~]# ifconfig bond0
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1440
inet 192.168.60.201 netmask 255.255.255.0 broadcast 192.168.60.255
inet6 fe80::a00:27ff:fe58:5d0a prefixlen 64 scopeid 0x20<link>
ether 08:00:27:58:5d:0a txqueuelen 1000 (Ethernet)
RX packets 188 bytes 14528 (14.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 284 bytes 26781 (26.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
To ascertain the current default kernel configured for boot, execute the command grubby --default-kernel. For further verification of the currently running kernel, execute uname -r.
In the displayed Oracle Linux 8 instance, the default kernel set for boot is UEK, and the system is presently running UEK.
[root@mongo01 ~]# uname -r
5.15.0-3.60.5.1.el8uek.x86_64
[root@mongo01 ~]# grubby --default-kernel
/boot/vmlinuz-5.15.0-3.60.5.1.el8uek.x86_64
Utilize the command grubby --info=ALL | grep ^kernel to display all installed and configured kernels on your system. For additional insights into the boot configuration of each kernel within the system’s /boot directory, execute grubby --info=ALL without piping through grep.
Oracle Linux kernel names signify whether it’s RHCK or UEK, along with the system architecture. In the provided example, the suffix “el8” denotes RHCK, while “el8uek” indicates UEK.
[root@mongo01 ~]# grubby --info=ALL | grep ^kernel
kernel="/boot/vmlinuz-5.15.0-3.60.5.1.el8uek.x86_64"
kernel="/boot/vmlinuz-4.18.0-425.3.1.el8.x86_64"
kernel="/boot/vmlinuz-0-rescue-a576882a66ff4836bc3f4be46dff1827"
Switch to an alternate default kernel by executing the command grubby --set-default followed by the chosen kernel. In the example provided, we are changing the default kernel to RHCK (4.18.0-425.3.1.el8.x86_64).
The modification becomes effective immediately, requiring only a system reboot.
[root@mongo01 ~]# grubby --set-default /boot/vmlinuz-4.18.0-425.3.1.el8.x86_64
The default is /boot/loader/entries/a576882a66ff4836bc3f4be46dff1827-4.18.0-425.3.1.el8.x86_64.conf with index 1 and kernel /boot/vmlinuz-4.18.0-425.3.1.el8.x86_64
The selected default kernel remains in effect across system reboots. Hence, upon rebooting the instance, your system will operate using the kernel you selected. Now we can add the MongoDB repository to the list of repositories and proceed to install MongoDB.
[root@mongo01 ~]# uname -r
4.18.0-425.3.1.el8.x86_64
[root@mongo01 ~]# vi /etc/yum.repos.d/mongodb-org-7.0.repo
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc
[root@mongo01 ~]# yum install -y mongodb-org
| Directory / File | Description |
| /etc/mongod.conf | Configuration file of MongoDB [ By default localhost IP (127.0.0.1) is bind IP and 27017 is the default port ] |
| /var/lib/mongo | Data directory of MongoDB |
| /var/log/mongodb/mongod.log | Log file of MongoDB |
I have kept the SELinux status as disabled.
[root@mongo01 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@mongo01 ~]# getenforce
Disabled
MongoDB listening port is changed to 27001.
[root@mongo01 ~]# vi /etc/mongod.conf
...
# network interfaces
net:
port: 27001
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
...
[root@mongo01 ~]# systemctl start mongod
[root@mongo01 ~]# systemctl enable mongod
[root@mongo01 ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2024-05-02 19:01:30 +03; 11s ago
Docs: https://docs.mongodb.org/manual
Main PID: 32550 (mongod)
Memory: 75.7M
CGroup: /system.slice/mongod.service
└─32550 /usr/bin/mongod -f /etc/mongod.conf
May 02 19:01:30 mongo01.localdomain systemd[1]: Started MongoDB Database Server.
May 02 19:01:30 mongo01.localdomain mongod[32550]: {"t":{"$date":"2024-05-02T16:01:30.720Z"},"s":"I", "c":"CONTROL", "id":7484500, "ctx":"main","msg":"Enviro>
lines 1-11/11 (END)
Disable transparent hugepages and configure the maximum number of memory map areas a process may have to an upper limit.
[root@mongo01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@mongo01 ~]# vi /etc/systemd/system/mongodb-hugepage-fix.service
[Unit]
Description="Disable Transparent Hugepage before MongoDB boots"
#WARN: check service name on your system
# If you are using MongoDB Cloud, service name is "mongodb-mms-automation-agent.service"
Before=mongod.service
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'
[Install]
#WARN: check service name on your system
# If you are using MongoDB Cloud, service name is "mongodb-mms-automation-agent.service"
RequiredBy=mongod.service
[root@mongo01 ~]# systemctl daemon-reload
[root@mongo01 ~]# systemctl enable mongodb-hugepage-fix
Created symlink /etc/systemd/system/mongod.service.requires/mongodb-hugepage-fix.service → /etc/systemd/system/mongodb-hugepage-fix.service.
[root@mongo01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@mongo01 ~]# cat /proc/sys/vm/max_map_count
65530
[root@mongo01 ~]# vi /etc/sysctl.conf
vm.max_map_count = 102400
[root@mongo01 ~]# sysctl -p
net.ipv4.ip_local_port_range = 9000 65535
vm.max_map_count = 102400
[root@mongo01 ~]# systemctl restart mongod
I will create a mongodb user (insanedba) with admin privilege on test database and will create our first collection. (posts)
[root@mongo01 ~]# mongosh --port 27001
Current Mongosh Log ID: 6633bc26cca36639162202d7
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5
Using MongoDB: 7.0.9
Using Mongosh: 2.2.5
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2024-05-02T19:15:32.484+03:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------
admin>db.createUser(
{
user: "insanedba",
pwd: "insane",
roles: [ { role: "readWrite", db: "test" } ]
}
);
{ ok: 1 }
admin> use test
test> db.createCollection("posts", { station_name : String, measurement : Number } )
Hope it helps.


Leave your comment