Trouble Deploying Mongod on a Local Machine

Hello,
The first issue that I encountered deploying mongod on a local machine were permissions to files (code=exited, status=100 - no permissions) As I see in lab filesystem (Vagrant?) mongod.log and config files have permissions set to 755 (rxw, rx, rx), on a local linux machine these by default are 644, which of those are advised for default paths (/var/log/ and /etc/, also for db in /var/lib/) and which for custom (e.g. fast deploying at home/user path just for practice)?

The second one is deploying another service of mongod - with systemd. I could copy-paste to custom unit - named mongod1.service, mongod2.service or mongod3.service at /lib/systemd/system/ (according to discussion at github) and use separate mongod.conf files, therefore separate logs and dbs, for learning purposes. The main question is - should those mongod units (in systemd) run on a binary code of the same service (default: /usr/bin/mongod) or should they be deployed on separate located binaries? How does it look in virtual environments? Is the binary shared?

As a summary:

  • I’ve installed a package mongodb-org with MongoDB tutorial instructions, on Linux Mint 20.1 (ubuntu focal-based) It uses systemd init system
  • the error code comes from a systemtcl status mongod msg and requires chmod on mongod.log file
  • the compared “lab system” files’ permissions are MongoDB University courses’ lab IDE (with system V init)
  • the main point of creating other mongod units is to deliver other mongod instances (for deploying replica set) without getting bad habbits in the learning process (right file permissions, binary locations of the mongod in the file system)

Any tips are welcome! :wink:

seems solved:

  • I’ve made 2 copies of mongod.service in lib/systemd/system/ called mongod1.service, mongod2.service and changed mongod.conf in each, to have:
    ExecStart=/usr/bin/mongod --config /etc/mongod.conf
    ExecStart=/usr/bin/mongod --config /etc/mongod1.conf
    ExecStart=/usr/bin/mongod --config /etc/mongod2.conf
  • in the mongod.conf files in etc, changed the mongod.log and dbPath, that each instance could use own log files and database
  • created directories for the databases, but recieved permission error, since the owner was root

By default, MongoDB runs using the mongodb user account. If you change the user that runs the MongoDB process, you must also modify the permission to the data and log directories to give this user access to these directories (mongodb documentation)

  • changed the owner of a directory:
    chown mongodb:mongodb mongodb1
    where mongodb:mongodb are user:group and the last one is a name of a directory made for database (same as in mongod1.conf file); made the same for the mongodb2
    chmod 700 mongodb1
    chmod 700 mongodb2

It is also possible without changing owner, e.g. by giving all of the permissions to others (which opens also permissions to all of users from /etc/group “however entities should not be multiplied without necessity”)

  • and started all of the instances accordingly:
    systemctl start mongod
    systemctl start mongod1
    systemctl start mongod2

  • checked all with systemctl status mongod (1,2)

  • ps -ef to see whether they’re present in system process list.

  • as for binaries found some tips in mongodb manual

For production deployments, you should maintain as much separation between members as possible by hosting the mongod instances on separate machines. When using virtual machines for production deployments, you should place each mongod instance on a separate host server serviced by redundant power circuits and redundant network paths.

Thank you for your patience,
Regards.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.