{"id":12811,"date":"2025-12-13T13:58:00","date_gmt":"2025-12-13T08:28:00","guid":{"rendered":"https:\/\/www.youstable.com\/blog\/?p=12811"},"modified":"2025-12-24T16:14:29","modified_gmt":"2025-12-24T10:44:29","slug":"configure-mongodb-on-linux","status":"publish","type":"post","link":"https:\/\/www.youstable.com\/blog\/configure-mongodb-on-linux","title":{"rendered":"How to Configure MongoDB on Linux Server &#8211; (Step-by-Step Guide 2026)"},"content":{"rendered":"\n<p>To configure MongoDB on a Linux server, install the official MongoDB repository, install mongod, start and enable the service, set bindIp and security.authorization in mongod.conf, create an admin user via mongosh, open firewall rules, and enable TLS. Finally, tune Linux limits and storage for WiredTiger performance and set up backups and monitoring.<\/p>\n\n\n\n<p>In this step-by-step guide, you\u2019ll learn exactly how to configure MongoDB on a Linux server for production in 2026. We\u2019ll cover installation on Ubuntu\/Debian and RHEL-based systems, secure configuration, performance tuning, replica sets, backups, monitoring, and common fixes. The instructions are beginner-friendly but rooted in real-world ops experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"search-intent-and-what-youll-learn\"><strong>Search Intent and What You\u2019ll Learn<\/strong><\/h2>\n\n\n\n<p>This tutorial targets users searching for \u201chow to configure MongoDB on <a href=\"https:\/\/www.youstable.com\/blog\/install-yum-on-linux\/\">Linux server,<\/a>\u201d including admins deploying new instances, developers moving to production, and teams hardening existing installs. You\u2019ll get actionable commands, proven defaults, and context to make informed choices for Ubuntu, Debian, and RHEL-based distributions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"prerequisites-and-system-requirements\"><strong>Prerequisites and System Requirements<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.youstable.com\/blog\/install-iptables-on-linux\/\">Linux server<\/a> (Ubuntu 22.04\/24.04, Debian 12, RHEL\/AlmaLinux\/Rocky 8 or 9)<\/li>\n\n\n\n<li>64-bit CPU, 2+ cores (4+ recommended), 4 GB RAM minimum (8\u201332 GB for production)<\/li>\n\n\n\n<li>Root or sudo access<\/li>\n\n\n\n<li><strong>Open ports: <\/strong>27017\/TCP (MongoDB), 27018\/27019 if sharding or replication<\/li>\n\n\n\n<li>Time synchronized (chrony or systemd-timesyncd) to avoid auth and replication drift<\/li>\n\n\n\n<li><strong>Primary keyword focus: <\/strong>How to Configure <a href=\"https:\/\/www.youstable.com\/blog\/install-mongodb-on-linux\/\">MongoDB on Linux Server<\/a> (plus secondary: MongoDB installation, MongoDB configuration, security hardening, performance tuning)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-1-add-the-official-mongodb-repository\"><strong>Step 1: Add the Official MongoDB Repository<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"ubuntu-22-04-24-04-jammy-noble-and-debian-12-bookworm\"><strong>Ubuntu 22.04\/24.04 (Jammy\/Noble) and Debian 12 (Bookworm)<\/strong><\/h3>\n\n\n\n<p>Replace the codename with your distro if needed. The example uses MongoDB 7.0 (a widely deployed stable series). Always verify the latest supported series from the official docs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Ubuntu Jammy example (22.04). For Noble (24.04), replace 'jammy' with 'noble'\nsudo apt-get update\nsudo apt-get install -y ca-certificates curl gnupg\n\ncurl -fsSL https:\/\/pgp.mongodb.com\/server-7.0.asc | \\\nsudo gpg -o \/usr\/share\/keyrings\/mongodb-server-7.0.gpg --dearmor\n\necho \"deb &#91; arch=amd64,arm64 signed-by=\/usr\/share\/keyrings\/mongodb-server-7.0.gpg ] \\\nhttps:\/\/repo.mongodb.org\/apt\/ubuntu jammy\/mongodb-org\/7.0 multiverse\" | \\\nsudo tee \/etc\/apt\/sources.list.d\/mongodb-org-7.0.list\n\nsudo apt-get update<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Debian 12 (Bookworm) example\nsudo apt-get update\nsudo apt-get install -y ca-certificates curl gnupg\n\ncurl -fsSL https:\/\/pgp.mongodb.com\/server-7.0.asc | \\\nsudo gpg -o \/usr\/share\/keyrings\/mongodb-server-7.0.gpg --dearmor\n\necho \"deb &#91; arch=amd64,arm64 signed-by=\/usr\/share\/keyrings\/mongodb-server-7.0.gpg ] \\\nhttps:\/\/repo.mongodb.org\/apt\/debian bookworm\/mongodb-org\/7.0 main\" | \\\nsudo tee \/etc\/apt\/sources.list.d\/mongodb-org-7.0.list\n\nsudo apt-get update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"rhel-8-9-almalinux-rocky-linux\"><strong>RHEL 8\/9, AlmaLinux, Rocky Linux<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/etc\/yum.repos.d\/mongodb-org-7.0.repo &gt;\/dev\/null &lt;&lt;'EOF'\n&#91;mongodb-org-7.0]\nname=MongoDB Repository\nbaseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/7.0\/x86_64\/\ngpgcheck=1\nenabled=1\ngpgkey=https:\/\/pgp.mongodb.com\/server-7.0.asc\nEOF\n\nsudo dnf clean all<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-2-install-mongodb-server\"><strong>Step 2: Install MongoDB Server<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Ubuntu\/Debian\nsudo apt-get install -y mongodb-org\n\n# RHEL\/Alma\/Rocky\nsudo dnf install -y mongodb-org<\/code><\/pre>\n\n\n\n<p>This installs mongod, mongosh, and related tools. Keep your OS and MongoDB branch aligned with your support policy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-3-start-and-enable-the-service\"><strong>Step 3: Start and Enable the Service<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now mongod\nsudo systemctl status mongod --no-pager\njournalctl -u mongod -b --no-pager | tail -n 50<\/code><\/pre>\n\n\n\n<p>If mongod fails to start, check data path permissions, SELinux context, or port conflicts on 27017.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-4-base-configuration-mongod-conf\"><strong>Step 4: Base Configuration (mongod.conf)<\/strong><\/h2>\n\n\n\n<p>On most distributions, the config lives at \/etc\/mongod.conf. Set network binding, data\/log paths, and enable authorization. Always back up this file before editing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"recommended-production-defaults\"><strong>Recommended Production Defaults<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo cp \/etc\/mongod.conf \/etc\/mongod.conf.bak.$(date +%F)\n\nsudo tee \/etc\/mongod.conf &gt;\/dev\/null &lt;&lt;'EOF'\nstorage:\n  dbPath: \/var\/lib\/mongo\n  journal:\n    enabled: true\n  wiredTiger:\n    engineConfig:\n      # Set later based on RAM; omit to auto-calc\n      # cacheSizeGB: 8\nsystemLog:\n  destination: file\n  path: \/var\/log\/mongodb\/mongod.log\n  logAppend: true\nnet:\n  port: 27017\n  bindIp: 127.0.0.1,10.0.0.10   # replace 10.0.0.10 with your server's private IP\nprocessManagement:\n  timeZoneInfo: \/usr\/share\/zoneinfo\nsecurity:\n  authorization: enabled\n# replication:\n#   replSetName: rs0           # uncomment when configuring a replica set\n# net:\n#   tls:\n#     mode: requireTLS\n#     certificateKeyFile: \/etc\/ssl\/mongo\/mongo.pem\nEOF\n\nsudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<p>By default, bind to localhost and a private IP (never 0.0.0.0 in production). We\u2019ll enable TLS and replication later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-5-create-the-first-admin-user\"><strong>Step 5: Create the First Admin User<\/strong><\/h2>\n\n\n\n<p>With authorization enabled, create an admin <a href=\"https:\/\/www.youstable.com\/blog\/change-a-database-user-password-in-directadmin\/\">user in the admin database<\/a>. Use SCRAM-SHA-256 and a strong password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongosh --host 127.0.0.1 --port 27017\n\nuse admin\ndb.createUser({\n  user: \"siteAdmin\",\n  pwd: passwordPrompt(),\n  roles: &#91; { role: \"root\", db: \"admin\" } ]\n})\nexit<\/code><\/pre>\n\n\n\n<p>Reconnect using authentication:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongosh --username siteAdmin --authenticationDatabase admin --host 127.0.0.1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-6-open-firewall-ports-safely\"><strong>Step 6: Open Firewall Ports Safely<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"ubuntu-debian-ufw\"><strong>Ubuntu\/Debian (UFW)<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Allow only trusted subnets or peers (replace CIDR)\nsudo ufw allow from 10.0.0.0\/24 to any port 27017 proto tcp\nsudo ufw reload\nsudo ufw status<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"rhel-alma-rocky-firewalld\"><strong>RHEL\/Alma\/Rocky (firewalld)<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --permanent --add-rich-rule='rule family=\"ipv4\" source address=\"10.0.0.0\/24\" port protocol=\"tcp\" port=\"27017\" accept'\nsudo firewall-cmd --reload\nsudo firewall-cmd --list-all<\/code><\/pre>\n\n\n\n<p>Never expose 27017 to the public internet. Use private networks, VPN, or security groups.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-7-enable-tls-ssl-encryption\"><strong>Step 7: Enable TLS\/SSL Encryption<\/strong><\/h2>\n\n\n\n<p>Encrypt traffic in transit. Use an internal CA or Let\u2019s Encrypt certificate. Here\u2019s a quick self-signed example for lab use; for production, use a real CA-signed cert.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/etc\/ssl\/mongo\nsudo openssl req -newkey rsa:4096 -x509 -days 825 -nodes \\\n  -keyout \/etc\/ssl\/mongo\/mongo.key \\\n  -out \/etc\/ssl\/mongo\/mongo.crt \\\n  -subj \"\/CN=mongo.internal.example.com\"\n\nsudo sh -c 'cat \/etc\/ssl\/mongo\/mongo.key \/etc\/ssl\/mongo\/mongo.crt &gt; \/etc\/ssl\/mongo\/mongo.pem'\nsudo chmod 600 \/etc\/ssl\/mongo\/mongo.pem\nsudo chown mongod:mongod \/etc\/ssl\/mongo\/mongo.pem<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee -a \/etc\/mongod.conf &gt;\/dev\/null &lt;&lt;'EOF'\nnet:\n  tls:\n    mode: requireTLS\n    certificateKeyFile: \/etc\/ssl\/mongo\/mongo.pem\nEOF\n\nsudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<p>Connect with TLS from clients by <a href=\"https:\/\/www.youstable.com\/blog\/install-and-renew-ssl-certificates\/\">specifying SSL parameters<\/a> in drivers or mongosh (for self-signed certs, provide CA file or allow invalid certs only in test environments).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-8-linux-and-wiredtiger-performance-tuning\"><strong>Step 8: Linux and WiredTiger Performance Tuning<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"increase-file-descriptors-and-processes\"><strong>Increase File Descriptors and Processes<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/etc\/security\/limits.d\/mongodb.conf &gt;\/dev\/null &lt;&lt;'EOF'\nmongod soft nofile 64000\nmongod hard nofile 64000\nmongod soft nproc  32000\nmongod hard nproc  32000\nEOF<\/code><\/pre>\n\n\n\n<p>Reboot or ensure PAM limits are applied to the mongod service. Confirm via lsof and cat \/proc\/$(pidof mongod)\/limits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"disable-transparent-huge-pages-thp-and-tune-swappiness\"><strong>Disable Transparent Huge Pages (THP) and Tune Swappiness<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># THP often hurts latency-sensitive databases\nsudo tee \/etc\/systemd\/system\/disable-thp.service &gt;\/dev\/null &lt;&lt;'EOF'\n&#91;Unit]\nDescription=Disable Transparent Huge Pages (THP)\nAfter=network.target\n\n&#91;Service]\nType=simple\nExecStart=\/bin\/sh -c 'echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled; echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/defrag'\nRemainAfterExit=yes\n\n&#91;Install]\nWantedBy=multi-user.target\nEOF\n\nsudo systemctl daemon-reload\nsudo systemctl enable --now disable-thp\n\n# Lower swappiness\necho 'vm.swappiness=1' | sudo tee \/etc\/sysctl.d\/99-mongo.conf\nsudo sysctl --system<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"right-size-wiredtiger-cache\"><strong>Right-size WiredTiger Cache<\/strong><\/h3>\n\n\n\n<p>WiredTiger cache defaults to a fraction of RAM. In memory-constrained environments or when running on shared nodes, set cacheSizeGB in mongod.conf to avoid OS pressure. Example: 50%\u201360% of RAM on dedicated DB servers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-9-configure-a-replica-set-high-availability\"><strong>Step 9: Configure a Replica Set (High Availability)<\/strong><\/h2>\n\n\n\n<p>Replica sets provide redundancy and failover. Set a name and restart before initiating.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># In \/etc\/mongod.conf\nreplication:\n  replSetName: rs0\n\nsudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># On the primary node\nmongosh --username siteAdmin --authenticationDatabase admin\nrs.initiate({\n  _id: \"rs0\",\n  members: &#91;\n    { _id: 0, host: \"mongo1.internal:27017\" },\n    { _id: 1, host: \"mongo2.internal:27017\" },\n    { _id: 2, host: \"mongo3.internal:27017\", arbiterOnly: false }\n  ]\n})\nrs.status()<\/code><\/pre>\n\n\n\n<p>Ensure all members can resolve and reach each other on 27017. Use private DNS or \/etc\/hosts entries and consistent TLS settings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-10-backups-and-point-in-time-recovery\"><strong>Step 10: Backups and Point-in-Time Recovery<\/strong><\/h2>\n\n\n\n<p>Combine logical backups with filesystem snapshots or cloud-native snapshots for safety. For busy clusters, consider hot backups or backup agents.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Logical backup\nmongodump --authenticationDatabase admin -u siteAdmin -h 127.0.0.1 \\\n  --archive=\/backups\/mongo-$(date +%F).archive --gzip\n\n# Restore\nmongorestore --archive=\/backups\/mongo-YYYY-MM-DD.archive --gzip<\/code><\/pre>\n\n\n\n<p>For LVM or cloud volume snapshots, quiesce writes if possible or use replica secondaries for safer snapshots. Always test restores.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-11-monitoring-logs-and-maintenance\"><strong>Step 11: Monitoring, Logs, and Maintenance<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Real-time tools: mongostat, mongotop<\/li>\n\n\n\n<li>System metrics: node exporter, CloudWatch, or your monitoring stack<\/li>\n\n\n\n<li>MongoDB exporter for Prometheus, Grafana dashboards<\/li>\n\n\n\n<li>Log rotation: use logAppend true; trigger with sudo kill -SIGUSR1 $(pidof mongod)<\/li>\n\n\n\n<li>Alert on replication lag, cache pressure, slow queries, disk I\/O, and OOM events<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"selinux-and-data-directory-moves\"><strong>SELinux and Data Directory Moves<\/strong><\/h2>\n\n\n\n<p>If you change dbPath to a custom mount (e.g., \/data\/mongo) on RHEL-based systems with SELinux enforcing, set the correct contexts or mongod will fail to read\/write.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Example: moving data to \/data\/mongo\nsudo systemctl stop mongod\nsudo rsync -aHAX \/var\/lib\/mongo\/ \/data\/mongo\/\nsudo semanage fcontext -a -t mongod_var_lib_t \"\/data\/mongo(\/.*)?\"\nsudo restorecon -Rv \/data\/mongo\nsudo sed -i 's|dbPath: .*|dbPath: \/data\/mongo|' \/etc\/mongod.conf\nsudo systemctl start mongod<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"troubleshooting-quick-wins\"><strong>Troubleshooting Quick Wins<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Port already in use: <\/strong>sudo ss -lntp | grep 27017<\/li>\n\n\n\n<li>Permission denied on data path: check ownership (mongod:mongod) and SELinux contexts<\/li>\n\n\n\n<li><strong>Auth errors:<\/strong> confirm db, user, and role; check keyfile\/clusterAuthMode in replicas<\/li>\n\n\n\n<li>Connection refused from remote: verify bindIp, firewall, and TLS settings<\/li>\n\n\n\n<li><strong>High CPU or memory: <\/strong>review slow queries, add indexes, adjust WiredTiger cache, and verify THP is disabled<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"when-managed-hosting-makes-sense\"><strong>When Managed Hosting Makes Sense<\/strong><\/h2>\n\n\n\n<p>If you\u2019d rather focus on your app than kernel flags and backups, consider managed MongoDB on optimized VPS or cloud instances. At <a href=\"https:\/\/www.youstable.com\/\">YouStable<\/a>, we provide NVMe-backed servers, private networking, proactive monitoring, and optional managed database services\u2014ideal for teams that want performance, security, and predictable costs without the ops burden.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"summary-your-production-ready-mongodb-checklist\"><strong>Summary: Your Production-Ready MongoDB Checklist<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install from the official MongoDB repository<\/li>\n\n\n\n<li>Start and enable mongod via systemd<\/li>\n\n\n\n<li>Set bindIp, enable authorization, and create an admin user<\/li>\n\n\n\n<li>Lock down the firewall and require TLS<\/li>\n\n\n\n<li>Tune limits, THP, swappiness, and WiredTiger cache<\/li>\n\n\n\n<li>Use replica sets for HA and validated backups for DR<\/li>\n\n\n\n<li>Monitor health, capacity, and query performance<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"faqs-how-to-configure-mongodb-on-linux-server\"><strong>FAQs: How to Configure MongoDB on Linux Server<\/strong><\/h2>\n\n\n\t\t<section\t\thelp class=\"sc_fs_faq sc_card    \"\n\t\t\t\t>\n\t\t\t\t<h3 id=\"which-linux-distro-is-best-for-mongodb-in-2026\">Which Linux distro is best for MongoDB in 2026?<\/h3>\t\t\t\t<div>\n\t\t\t\t\t\t<div class=\"sc_fs_faq__content\">\n\t\t\t\t\n\n<p>Ubuntu LTS (22.04\/24.04) and RHEL-compatible distros (AlmaLinux\/Rocky 8\/9) are top choices due to stability, long-term updates, and first-class MongoDB repository support. Choose the one your team already manages well to simplify patching and automation.<\/p>\n\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section\t\thelp class=\"sc_fs_faq sc_card    \"\n\t\t\t\t>\n\t\t\t\t<h3 id=\"how-do-i-secure-mongodb-if-it-must-be-internet-accessible\">How do I secure MongoDB if it must be internet-accessible?<\/h3>\t\t\t\t<div>\n\t\t\t\t\t\t<div class=\"sc_fs_faq__content\">\n\t\t\t\t\n\n<p>Use a VPN or bastion first. If exposure is unavoidable, enforce TLS (requireTLS), strong auth, firewall allow-lists, rate limiting at a reverse proxy, and continuous monitoring. Never bind to 0.0.0.0 without strict network controls and alerts.<\/p>\n\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section\t\thelp class=\"sc_fs_faq sc_card    \"\n\t\t\t\t>\n\t\t\t\t<h3 id=\"what-port-does-mongodb-use-and-can-i-change-it\">What port does MongoDB use and can I change it?<\/h3>\t\t\t\t<div>\n\t\t\t\t\t\t<div class=\"sc_fs_faq__content\">\n\t\t\t\t\n\n<p>MongoDB listens on TCP 27017 by default. Change it in mongod.conf under net.port, adjust your firewall rules, and update client connection strings. Port changes add obscurity, not security; use TLS and proper authentication regardless.<\/p>\n\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section\t\thelp class=\"sc_fs_faq sc_card    \"\n\t\t\t\t>\n\t\t\t\t<h3 id=\"how-much-ram-should-i-allocate-to-mongodb\">How much RAM should I allocate to MongoDB?<\/h3>\t\t\t\t<div>\n\t\t\t\t\t\t<div class=\"sc_fs_faq__content\">\n\t\t\t\t\n\n<p>Start with at least 8 GB for production. Aim for RAM close to your working set. Set WiredTiger cache to ~50\u201360% of RAM on dedicated DB servers. Monitor page faults, cache pressure, and query latency to iterate safely.<\/p>\n\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section\t\thelp class=\"sc_fs_faq sc_card    \"\n\t\t\t\t>\n\t\t\t\t<h3 id=\"how-do-i-move-the-mongodb-data-directory-to-a-new-disk\">How do I move the MongoDB data directory to a new disk?<\/h3>\t\t\t\t<div>\n\t\t\t\t\t\t<div class=\"sc_fs_faq__content\">\n\t\t\t\t\n\n<p>Stop mongod, rsync data to the new path, update storage.dbPath in mongod.conf, fix ownership and SELinux contexts, then start mongod. Validate data, logs, and performance after the move. For replicas, move secondaries first to preserve availability.<\/p>\n\n\n\n<p>With these steps, you now know how to configure MongoDB on a Linux server\u2014from installation and security to tuning and HA. If you need a hardened, high-performance stack with expert support, YouStable can help you deploy MongoDB the right way.<\/p>\n\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t<\/section>\n\t\t\n<script type=\"application\/ld+json\">\n\t{\n\t\t\"@context\": \"https:\/\/schema.org\",\n\t\t\"@type\": \"FAQPage\",\n\t\t\"mainEntity\": [\n\t\t\t\t\t{\n\t\t\t\t\"@type\": \"Question\",\n\t\t\t\t\"name\": \"Which Linux distro is best for MongoDB in 2026?\",\n\t\t\t\t\"acceptedAnswer\": {\n\t\t\t\t\t\"@type\": \"Answer\",\n\t\t\t\t\t\"text\": \"<p>Ubuntu LTS (22.04\/24.04) and RHEL-compatible distros (AlmaLinux\/Rocky 8\/9) are top choices due to stability, long-term updates, and first-class MongoDB repository support. Choose the one your team already manages well to simplify patching and automation.<\/p>\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t,\t\t\t\t{\n\t\t\t\t\"@type\": \"Question\",\n\t\t\t\t\"name\": \"How do I secure MongoDB if it must be internet-accessible?\",\n\t\t\t\t\"acceptedAnswer\": {\n\t\t\t\t\t\"@type\": \"Answer\",\n\t\t\t\t\t\"text\": \"<p>Use a VPN or bastion first. If exposure is unavoidable, enforce TLS (requireTLS), strong auth, firewall allow-lists, rate limiting at a reverse proxy, and continuous monitoring. Never bind to 0.0.0.0 without strict network controls and alerts.<\/p>\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t,\t\t\t\t{\n\t\t\t\t\"@type\": \"Question\",\n\t\t\t\t\"name\": \"What port does MongoDB use and can I change it?\",\n\t\t\t\t\"acceptedAnswer\": {\n\t\t\t\t\t\"@type\": \"Answer\",\n\t\t\t\t\t\"text\": \"<p>MongoDB listens on TCP 27017 by default. Change it in mongod.conf under net.port, adjust your firewall rules, and update client connection strings. Port changes add obscurity, not security; use TLS and proper authentication regardless.<\/p>\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t,\t\t\t\t{\n\t\t\t\t\"@type\": \"Question\",\n\t\t\t\t\"name\": \"How much RAM should I allocate to MongoDB?\",\n\t\t\t\t\"acceptedAnswer\": {\n\t\t\t\t\t\"@type\": \"Answer\",\n\t\t\t\t\t\"text\": \"<p>Start with at least 8 GB for production. Aim for RAM close to your working set. Set WiredTiger cache to ~50\u201360% of RAM on dedicated DB servers. Monitor page faults, cache pressure, and query latency to iterate safely.<\/p>\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t,\t\t\t\t{\n\t\t\t\t\"@type\": \"Question\",\n\t\t\t\t\"name\": \"How do I move the MongoDB data directory to a new disk?\",\n\t\t\t\t\"acceptedAnswer\": {\n\t\t\t\t\t\"@type\": \"Answer\",\n\t\t\t\t\t\"text\": \"<p>Stop mongod, rsync data to the new path, update storage.dbPath in mongod.conf, fix ownership and SELinux contexts, then start mongod. Validate data, logs, and performance after the move. For replicas, move secondaries first to preserve availability.<\/p><p>With these steps, you now know how to configure MongoDB on a Linux server\u2014from installation and security to tuning and HA. If you need a hardened, high-performance stack with expert support, YouStable can help you deploy MongoDB the right way.<\/p>\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t\t\t\t]\n\t}\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>To configure MongoDB on a Linux server, install the official MongoDB repository, install mongod, start and enable the service, set [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":12977,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[350],"tags":[2142,2143],"class_list":["post-12811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase","tag-configure-mongodb-on-linux","tag-how-to-configure-mongodb-on-linux"],"acf":[],"featured_image_src":"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2025\/12\/How-to-Configure-MongoDB-on-Linux-Server.jpg","author_info":{"display_name":"Prahlad Prajapati","author_link":"https:\/\/www.youstable.com\/blog\/author\/prahladblog"},"_links":{"self":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/12811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/comments?post=12811"}],"version-history":[{"count":2,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/12811\/revisions"}],"predecessor-version":[{"id":12961,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/12811\/revisions\/12961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media\/12977"}],"wp:attachment":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media?parent=12811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/categories?post=12811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/tags?post=12811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}