• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Sunday, May 11, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Arch

How to Install MongoDB 4.0 on Arch Linux

How VPS by How VPS
August 8, 2019
in Arch, Uncategorized
0
0
SHARES
50
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Prerequisites
  2. Install MongoDB 4.0 Database
  3. Test Connection
  4. Firewall Consideration
  5. Require Authentication
  6. Important: Upgrades
  7. Unclean Shutdown
  8. Want to contribute?


Prerequisites

  • A Vultr server running up to date Arch Linux (see this article)
  • Sudo access:
    • Commands required to be ran as root are prefixed by #, and ones that can be ran as a regular user by $. The recommended way to run commands as root is to, as a regular user, prefix each of them with sudo.

Install MongoDB 4.0 Database

MongoDB is in the AUR (Arch User Repository). There are 2 sets of packages you can use. See Building Packages on Arch Linux (Including the AUR) to compile and install either set of packages:

  1. Compile from source. Use AUR packages mongodb and possibly mongodb-tools‘. Note this takes about 180GB, and this is a long compilation. With 4 cores, it takes about 7 hours. This is the recommended method, because it uses Arch’s compilation flags.
  2. Use MongoDB’s pre-built binary. Use AUR package mongodb-bin and possibly mongodb-tools-bin. This skips the entire compilation stage, downloading a pre-built binary from mongodb.org, and packaging it with the necessary configuration files.

After installing the package, start MongoDB, and make it start after every boot. During this first start, it will pre-allocate files for its journal and other data, which may take a while before the database finishes coming up:

# systemctl enable --now mongodb

Test Connection

Connect to MongoDB:

$ mongo

To quit:

> exit

Firewall Consideration

Although configuring a firewall is always a good idea, by default, MongoDB only listens on port 27017 on localhost, so it will receive no external traffic.

Require Authentication

By default, MongoDB allows anyone to connect to it without any type of authentication, which is obviously a security risk.

Create a root database user:

$ mongo
> use admin
> db.createUser(
... {
... user: "root",
... pwd: "YOUR-NEW-PASSWORD",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
... }
... )
> exit

Edit /etc/mongodb.conf, and if using package mongodb add:

security:
  authorization: "enabled"

If using package mongodb-bin add:

auth = true

Restart MongoDB:

# systemctl restart mongodb

Now, although you can still connect to MongoDB without authentication, it will not perform anything without it:

$ mongodb
> db.getUsers()
... Error: command usersInfo requires authentication :

Connect to MongoDB as root:

$ mongodb -u root

Alternatively, connect to MongoDB, then authenticate within it:

$ mongodb
> use admin
> db.auth("root", "<YOUR-DATABASE-ROOT-PASSWORD>")

Important: Upgrades

Because MongoDB is now part of the AUR, pacman will not automatically compile and upgrade it to new versions, when you upgrade your entire Arch system. You will need to manually re-compile a new version and install the new package. Before doing so, it is important to look at MongoDB’s release notes, to see if there are any extra steps you need to take. It’s a good idea to backup your database before upgrading, as well.

Unclean Shutdown

If MongoDB does not cleanly shutdown, and does not automatically recover using its journal on the next boot, you may need to run the following:

sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/

Depending on the size of your database and indexes used, this process can range from seconds to hours.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

How to Install MariaDB 10.3 or MySQL 8.0 on Arch Linux

Next Post

Setup OpenBSD 5.5 64-bit

Next Post

Setup OpenBSD 5.5 64-bit

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet