The Log Agent requires MongoDB for its operations. This section explains the steps to create the necessary MongoDB databases that will be used while deploying the Log Agent Swarm service.
The initial setup of MongoDB requires a few credentials to be established as listed in the table below.
Label |
Purpose |
Value |
---|---|---|
_ROOT_PASS_ |
The MongoDB setup process creates a superuser called ‘root’ in the ‘admin’ database. This is the password for the ‘root’ user. |
|
_DB1_ |
The MongoDB database name that the Log Agent requires for normal operations. The default value for this database is ‘connectLogs’. |
connectLogs |
_DB1_USER_ |
The user name for the database DB1. The default value for the username is ‘ecuser’ |
ecuser |
_DB1_PASS_ |
The password for the user _DB1_USER_ |
|
_BACKUP_USER_ |
A user who can backup databases in MongoDB |
backup |
_BACKUP_PASS_ |
The password for the user _BACKUP_USER_ |
To configure MongoDB,
-
Edit the file $CONNECT/components/logAgent/swarm/rootPassword.txt. Replace its contents with the value chosen for _ROOT_PASS_
-
Edit the file $CONNECT/components/logAgent/swarm/config/setup/userSetup.js. Change the values of _DB1_, _DB1_USER_ and _DB1_PASS_ as necessary.
-
Open a shell and change the directory to $CONNECT/components/logAgent/swarm.
-
In the shell, issue the host command below,
docker secret create mongo-root ./rootPassword.txt
-
To create a Docker volume for managing data persistence, issue the host shell command below,
docker volume create mongo-data
-
To initialize data in this volume, issue the host shell command below,
docker run --rm -ti -v mongo-data:/tmp/mongo alpine /bin/sh -c "chown -R 999:999 /tmp/mongo; chmod -R 755 /tmp/mongo"
-
To create a Docker volume for managing log persistence, issue the host shell command below,
docker volume create mongo-log
-
To initialize data in this volume, issue the host shell command below,
docker run --rm -ti -v mongo-log:/tmp/mongo alpine /bin/sh -c "chown -R 999:999 /tmp/mongo; chmod -R 755 /tmp/mongo"
-
Create a temporary Docker volume for creating MongoDB configuration by issuing the host shell ,
docker volume create mongo-config
-
To initialize data in this volume, issue the host shell command
docker run --rm -ti -v mongo-config:/tmp/mongo-config -v $CONNECT/components/logAgent/swarm/config/setup:/tmp/src alpine /bin/sh -c "cp /tmp/src/*.js /tmp/mongo-config; chown -R 999:999 /tmp/mongo-config; chmod -R 777 /tmp/mongo-config"
-
If Docker Swarm is not active, enable it by using the host shell command below:
docker swarm init
-
To set up MongoDB, deploy a temporary stack using the host shell command:
docker stack deploy -c mongo-setup-stack.yaml --with-registry-auth mongo-setup
-
To verify that the service is provisioned, issue the host shell command below:
docker service ls
When the service has provisioned correctly, the count under ‘REPLICAS’ should read 1/1.
This can take several seconds.
-
Execute the host shell commands below:
-
On Linux, execute the command below,
docker exec -it $(docker ps -q -f name=mongo) mongo --authenticationDatabase "admin" -u "root" -p " _ROOT_PASS_" /tmp/mongo-config/userSetup.js
-
On Windows, you must execute the commands as two separate commands as follows,
docker ps -q -f name=mongo
docker exec -it <container ID> mongo --authenticationDatabase "admin" -u "root" -p "_ROOT_PASS_" /tmp/mongo-config/userSetup.js
This will generate the following output:
-
Cleanup files
Follow the steps below to complete Mongo DB setup,
-
To stop the temporary stack, issue the host shell command:
docker stack rm mongo-setup
-
Wait a few seconds and delete the Docker volume that was used to help with user provisioning by issuing the host shell command:
docker volume rm mongo-config
-
To delete the Docker secret created for the root user, issue the host shell command:
docker secret rm mongo-root
-
Delete $CONNECT/components/logAgent/swarm/rootPassword.txt
-
Delete $CONNECT/components/logAgent/swarm/config/setup/userSetup.js
This completes the MongoDB setup.