17 mongodb debian
rainbow napkin edited this page 2025-05-21 02:53:36 +00:00
title
Prepping MongoDB for use with Canopy

Step-by-step procedure for prepping MongoDB for use with Canopy:

MongoDB, while gratis and open-source, is not entirely FLOSS. If you're hell bent on using software with a hard FLOSS license, you're probably better off FerretDB

Install MongoDB

  1. Install curl, assuming you haven't already sudo apt install curl
  2. Import public key for mongo repo curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
  3. Add mongodb sources to apt sources.list.d echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
  4. Tell apt to update repo's and install mongosh other preq-reqs sudo apt update && sudo apt install mongodb-org

Hardening MongoDB

This section is incomplete, I'd like to go over this with more security-related documentation for MongoDB. I'm not a professional DBA XP

  1. Start mongod without authentication and drop into a shell sudo systemctl start mongod & mongosh
  2. Switch over to the admin database use admin
  3. Create the administrative user:
db.createUser(
  {
    user: "admin",
    pwd: passwordPrompt(),
    roles: [
      { role: "userAdminAnyDatabase", db: "admin" },
      { role: "readWriteAnyDatabase", db: "admin" }
    ]
  }
)
  1. Add the following to /etc/mongod.conf to enable authentication:
security:
  authorization: enabled

Setting up the Canopy User/DB

  1. Restart mongod with sudo systemctl restart mongod
  2. Drop back into mongosh with authentication mongosh -u 'admin', entering the password on prompt
  3. Switch over to the canopy database use canopy
  4. Create the canopy user:
db.createUser(
  {
    user: "canopy",
    pwd: passwordPrompt(),
    roles: ["readWrite"]
  }
)

The database is now prepared to serve an instance of canopy! Feel free to continue with the setup.