Creating a MongoDB Instance
Creation of a MongoDB instance.
MongoDB instances are created through the dmk_db_create.py script. All commands are executed as the mongodb user.
Using DMK templates
Instances are created using templates, which you can copy and modify from the $DMK_HOME/templates/dbcreate directory.
Let's go through an example with the template dbcreate_template_basic.yaml.
mongo_cfg:
instance_name: mdb01
home_path: /u01/app/mongodb/product/8.0.16
data_path: ${MONGO_DATA}
bindIp: 0.0.0.0
port: 27017
template: ${DMK_HOME}/templates/dbcreate/mongo_conf_basic.yamlThis DMK template contains the following arguments :
instance_name: Name of the instance, which must comply with theINSTANCE_NAMING_CONVENTIONdefined in the DMK configuration file. By default, it is set to^mdb([a-zA-Z]{0,4})(\d+)$, but you can customize it in your local configuration file.home_path: Path to the MongoDB binaries associated with the instance. This path is stored in the$DMK_HOME/etc/mongodb.lstfile and used when loading the environment for the instance.data_path: Directory where the data files will be stored. Defaults to$MONGO_DATA_ROOT.bindIp: MongoDB configuration parameter. See the official documentation for details.port: MongoDB listening port number.template: MongoDB configuration template file to be used.
Here is the content of the template used in the example. You can of course change this as needed.
Warning If you want to modify DMK templates, variables must be written as ${VARIABLE} to ensure proper substitution.
Other templates are available, for installation with TLS communication enabled, or for a replica set.
Creating the instance
After verifying that all templates are correct, run dmk_dbcreate.py. This script will create:
The MongoDB instance directory structure.
A systemd file named
mongod_<instance_name>.service, which has to be copied to/etc/systemd/system.The MongoDB configuration file named
<instance_name>.conf.
As instructed, copy the service file to /etc/systemd/system as the root user:
If this is the first MongoDB instance on the server, configure logrotate as instructed, again as root:
You can now reload DMK by running dmk or re-login as mongodb, and load the environment associated with the new instance.
Securing the MongoDB instance
You must always secure the MongoDB instances right after their creation !
Connect to the MongoDB instance with ms, and run the following commands :
Example:
In the $MONGO_BASE/admin/$MONGO_INSTANCE/secret directory, create a cred.yaml file where the credentials will be stored.
Change the permissions with chmod 400 cred.yaml. You can now test the credentials with the msp alias.
Update MongoDB configuration file
Modify the configuration file with vic to include the security.authorization parameter:
Restart the MongoDB instance
To complete the process of securing your MongoDB instance, restart the instance with mgrestart.
You have successfully created and secured a MongoDB instance using DMK.
Last updated