I can able to run single instance on Mongo using the following Docker command
docker run -it --rm -d -p 27017:27017 --user mongodb mongo:3.4
But I can't find out how to configure Config Server and Query Router and also how add shards with Replication
Thanks in Advance
I used this tutorial myself: https://medium.com/@gargar454/deploy-a-mongodb-cluster-in-steps-9-using-docker-49205e231319#.mle6a8wmg
create folders (local on all nodes):
sudo mkdir -p /dockerlocalstorage/data/mongodb
sudo mkdir -p /dockerlocalstorage/backup/mongodb
sudo mkdir -p /dockersharedstorage/config/mongodb/
create keyfile as root user and give correct permissions:
sudo su
cd /dockersharedstorage/config/mongodb/
openssl rand -base64 741 > mongodb-keyfile
chmod 600 mongodb-keyfile
sudo chown 999 mongodb-keyfile
Depending on the mount type you might need to use /dockerlocalstorage/ to keep the certs. Mongodb will complain if the permissions are not set correctly (which could be harder to achieve on lets say a cifs mount)
create mongodb container without auth/keyfile:
docker run --name mongodb \
-v /dockerlocalstorage/data/mongodb:/data/db \
-v /dockersharedstorage/config/mongodb:/opt/keyfile \
--hostname="dock01" \
-p 27017:27017 \
-d mongo
log in to container:
docker exec -it mongodb mongo
create root users, dont forget to change the passwords
use admin
db.createUser( {
user: "admin",
pwd: "PASSWORD",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
});
db.createUser( {
user: "root",
pwd: "PASSWORD",
roles: [ { role: "root", db: "admin" } ]
});
exit and remove the container
exit
docker stop mongodb
docker rm mongodb
change NODE_NR:
docker run \
-d \
--name mongodb \
-v /dockerlocalstorage/data/mongodb:/data/db \
-v /dockerlocalstorage/backup/mongodb:/data/backup \
-v /dockersharedstore/config/mongodb:/opt/keyfile \
--restart=always \
--hostname="dock01" \
-p 27017:27017 mongo \
--keyFile /opt/keyfile/mongodb-keyfile \
--replSet "SET_NAME"
connect to node 1:
docker exec -it mongodb mongo
use admin
db.auth("root", "PASSWORD");
initialize the replication set:
rs.initiate()
Check the replica set with: rs.conf()
or rs.status()
add others:
rs.add("dock02:27017")
rs.add("dock03:27017")
edit crontab:
sudo su
crontab -l > tempcron
echo new cron into cron file
echo "0 4 * * * docker exec -it mongodb mongodump -u root -p PASSWORD -o /data/backup/daily" >> tempcron
echo "30 4 * * 5 docker exec -it mongodb mongodump -u root -p PASSWORD -o /data/backup/weekly" >> tempcron
install new cron file
crontab tempcron
rm tempcron
exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With