Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

Installing And Configuring MongoDB On CentOS

MongoDB is a document-oriented database that stores records as flexible BSON documents rather than rows and columns. On CentOS, a reliable deployment depends on choosing a supported operating system, adding the correct Yum repository, controlling network access, and enabling authentication before applications connect to the server.

The commands below suit CentOS Stream and closely related Red Hat Enterprise Linux systems. Package names and repository definitions can change between MongoDB releases, so pinning a major version is safer than allowing an unattended upgrade to select a different database series.

Choose A Supported CentOS Release

CentOS 7 reached end of life in 2024, so it should not be used for a new MongoDB installation exposed to a production network. CentOS Stream 9 or a supported RHEL-compatible distribution is a better foundation. Confirm the operating system and architecture before proceeding:

cat /etc/centos-release
uname -m
sudo dnf update -y

MongoDB requires a 64-bit operating system and sufficient disk space for both database files and journal activity. For an Australian business operating in Sydney, Melbourne, or Brisbane, select a hosting region close to application users where possible. Lower network latency helps application response times, while local data residency requirements may influence the choice of cloud provider and backup location.

Create an administrative account with sudo access, and ensure the server has a stable hostname. A predictable hostname simplifies monitoring, replica-set configuration, and log analysis when several database nodes are deployed.

Create The MongoDB Repository

Create a repository file for MongoDB 7.0 on a compatible RHEL 8 or CentOS Stream system. The repository is preferable to downloading random RPM files because it provides dependency handling and signed package metadata.

sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo > /dev/null <<'EOF'
[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
EOF

Refresh metadata and install the MongoDB server, shell, database tools, and supporting packages:

sudo dnf clean all
sudo dnf makecache
sudo dnf install -y mongodb-org

If the repository reports an unsupported platform, stop and check the MongoDB compatibility matrix rather than forcing installation. CentOS Stream versions can differ from the RHEL release represented in a repository, and an apparently successful installation may still create upgrade or library problems.

Install And Secure The Service

Start MongoDB and configure it to launch after a reboot:

sudo systemctl enable --now mongod
sudo systemctl status mongod

The default configuration is stored in /etc/mongod.conf, while the standard database path is /var/lib/mongo and logs are commonly written under /var/log/mongodb. Check the service log if startup fails:

sudo journalctl -u mongod -b --no-pager

Before allowing application traffic, enable access control. Edit the configuration and add or uncomment:

security:
  authorization: enabled

Restart the service, then create the first administrator while local access is still available. The exact shell command depends on the MongoDB Shell version, but a typical session is:

mongosh

Inside the shell:

use admin
db.createUser({
  user: "siteAdmin",
  pwd: passwordPrompt(),
  roles: [ { role: "root", db: "admin" } ]
})

Exit, restart MongoDB, and test authentication. Use separate users with limited roles for applications; an application should not connect with a cluster-wide administrator account. Developers working on Android may find broader database design notes useful when mapping entities and persistence responsibilities, even though Room and MongoDB use different storage models.

Configure Network And Firewall Access

MongoDB listens on localhost by default, which is a safe starting point. Keep this setting when the application runs on the same host. For a separate application server, change bindIp in /etc/mongod.conf to the private address or trusted interface, not to every interface:

net:
  port: 27017
  bindIp: 127.0.0.1,10.0.2.15

Allow port 27017 only from the application subnet or a specific server. With firewalld, replace the example address with the real source:

sudo firewall-cmd --permanent \
  --add-rich-rule='rule family="ipv4" source address="10.0.2.20/32" port protocol="tcp" port="27017" accept"
sudo firewall-cmd --reload

Cloud security groups must enforce the same restriction. Never expose MongoDB directly to the public internet. Australian offices may connect through business VPNs or fixed corporate IP ranges, but firewall rules should still use the narrowest source range. If the host also runs Nginx, consult these web server guides when separating reverse-proxy traffic from database traffic.

Verify, Maintain And Troubleshoot

After restarting MongoDB, verify that it is listening and that authenticated access works:

sudo systemctl restart mongod
sudo ss -lntp | grep 27017
mongosh --host 127.0.0.1 -u siteAdmin -p --authenticationDatabase admin

Inside mongosh, inspect basic server information:

db.runCommand({ connectionStatus: 1 })
db.serverStatus()

Monitor disk usage, memory pressure, replication lag, authentication failures, and slow queries. MongoDB can use substantial memory for its WiredTiger cache, so avoid placing it on a small virtual machine alongside unrelated workloads. Configure log rotation and test restores from backups rather than assuming a successful backup command guarantees recoverability.

Use Australian Eastern Standard Time or Australian Eastern Daylight Time consistently when interpreting operational events, while storing application timestamps in UTC. This avoids confusion around daylight saving changes in New South Wales and Victoria, which do not apply in Queensland. The essential principle is simple: keep MongoDB patched, private, authenticated, backed up, and limited to the clients that genuinely need it.