Refer their Install MongoDB Community Edition on Linux page for installation instructions of your Linux distro
For installing on MongoDB Community Edition on Fedora we’ll refer their RedHat guide
Configure the yum
repository by creating a .repo
file, for example: sudo nano /etc/yum.repos.d/mongodb-org-8.0.repo
and paste given contents inside it:
[mongodb-org-8.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/8.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-8.0.asc
Install the latest stable version of MongoDB:
sudo yum install -y mongodb-org
yum
automatically upgrades packages when newer versions become available
By default, MongoDB runs using the mongod
user account and uses the following default directories:
/var/lib/mongo
as the data directory/var/log/mongodb
as the log directoryThe package manager creates the default directories during installation. The owner and group name are mongod
. To use non-default directories, refer here
Configure SELinux policy (assuming default settings):
# Install required dependencies
sudo yum install git make checkpolicy policycoreutils selinux-policy-devel
# Download the policy repository
git clone https://github.com/mongodb/mongodb-selinux
# Build the policy
cd mongodb-selinux
make
# Apply the policy
sudo make install
The SELinux policy is designed to work with the configuration that results from a standard MongoDB .rpm
installation and makes these assumptions. It is designed for mongod
servers and does not apply to other MongoDB daemons or tools such as mongos
, mongosh
To uninstall the policy, go to the directory where you downloaded the policy repository and run sudo make uninstall
To run MongoDB Community Edition, check your Init System and follow the procedure accordingly accordingly:
ps --no-headers -o comm 1
Mine was systemd
(systemctl
). Sol I’ll do the following to start, enable and verify the mongod
service:
sudo systemctl daemon-reload
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
The output should look like:
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: disabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: active (running) since Sat 2024-11-02 15:21:19 IST; 3s ago
Invocation: a2a394e4298640bf98dd7a842064821d
Docs: https://docs.mongodb.org/manual
Main PID: 12577 (mongod)
Memory: 189.9M (peak: 275.8M)
CPU: 316ms
CGroup: /system.slice/mongod.service
└─12577 /usr/bin/mongod -f /etc/mongod.conf
Nov 02 15:21:19 fedora-pc systemd[1]: Started mongod.service - MongoDB Database Server.
Nov 02 15:21:19 fedora-pc mongod[12577]: {"t":{"$date":"2024-11-02T09:51:19.218Z"},"s":"I", "c":"CONTROL", "id":748>● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: disabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: active (running) since Sat 2024-11-02 15:21:19 IST; 3s ago
Invocation: a2a394e4298640bf98dd7a842064821d
Docs: https://docs.mongodb.org/manual
Main PID: 12577 (mongod)
Memory: 189.9M (peak: 275.8M)
CPU: 316ms
CGroup: /system.slice/mongod.service
└─12577 /usr/bin/mongod -f /etc/mongod.conf
Nov 02 15:21:19 fedora-pc systemd[1]: Started mongod.service - MongoDB Database Server.
Nov 02 15:21:19 fedora-pc mongod[12577]: {"t":{"$date":"2024-11-02T09:51:19.218Z"},"s":"I", "c":"CONTROL", "id":748>
Launch the mongo shell:
mongosh
If you get connection refused due stating some openssl
configuration error, you might need to install openssl variant of the mongosh
package as mentioned by this answer:
sudo yum remove mongodb-mongosh
sudo yum install mongodb-mongosh-shared-openssl3
sudo dnf install mongodb-org
When you enter open mongosh
, the output would like below. Enter help
to know commands and press Ctrl d
to exit
Current Mongosh Log ID: 67254482d59e272c2c6b128b
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.3.3
Using MongoDB: 8.0.3
Using Mongosh: 2.3.3
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/
------
The server generated these startup warnings when booting
2024-11-02T02:41:47.410+05:30: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2024-11-02T02:41:47.410+05:30: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2024-11-02T02:41:47.410+05:30: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2024-11-02T02:41:47.410+05:30: We suggest setting the contents of sysfsFile to 0.
2024-11-02T02:41:47.410+05:30: We suggest setting swappiness to 0 or 1, as swapping can cause performance problems.
------
test>
Configure Access Control:
test> use admin
switched to db admin
admin> db.createUser(
... {
... user: "kumar",
... pwd: passwordPrompt(),
... roles: [
... { role: "userAdminAnyDatabase", db: "admin" },
... { role: "readWriteAnyDatabase", db: "admin" }
... ]
... }
... )
Enter password
********{ ok: 1 }
admin> disableTelemetry()
Telemetry is now disabled.
admin>
As per their docs, we’ll download the .rpm
package for Fedora
# Download Compass
wget https://downloads.mongodb.com/compass/mongodb-compass-1.44.5.x86_64.rpm
# Install Compass
sudo yum install mongodb-compass-1.44.5.x86_64.rpm
# Launch Compass
mongodb-compass