![]() Containers let you run your applications in resource-isolated processes. Great at handling big data through horizontal scalability.ĭocker is an application that simplifies the process of managing application processes in containers.The dynamic schema supports fluent polymorphism.Embedded documents and arrays reduce the need for expensive joins.objects) map to native data types in many programming languages. The following image illustrates a simple MongoDB document Structure: Developers can think of MongoDB as a persistent repository of Python dictionaries. This is different from the table-like relational database structure. It means that MongoDB is a document-oriented database that stores data in flexible BSON (similar to JSON format) documents. MongoDB is a popular open source database, but unlike other databases it’s classified as a NoSQL database. Cons are that sometimes you will have to do more work by yourself or increase the list of dependencies by adding plugins. Pros would be that the framework is light-there is little dependency to update and watch for security bugs. A micro-framework is a framework with little to no dependencies to external libraries. What is Flask?įlask is a Python web micro-framework that provides you with the tools, libraries and technologies you need to build a modern web application. Mongodump -port 27019 -db modelDb -archive=/data/db/backups/ $BACKUP_NAME -gzip > /data/db/backups/logsĮcho 'Backup completed successfully!' RunĬan be found on Github: /gwenu/blog-howto/tree/master/how.A lot of buzzwords mentioned may sound like the goal is quite complex but let’s break it down into simple steps and conquer them one by one. Mongo_backup.sh used in mongo_backup_scheduler.sh and runs mongodump command: #!/bin/bash set -eĮcho "Backing up MongoDB database" echo "Dumping MongoDB modelDb database to compressed archive: $BACKUP_NAME" Mongod -port 27017 -bind_ip_all -replSet mongo-replica Mongo -host mongodb1:27017 /data/db/backups/logs"Ĭrontab -l | grep -F -q " $CRON_COMMAND" & echo 'Backup has already been scheduled.' || echo 'Scheduling new backup cron job for mongodb.' & crontab -l | | crontab -Įcho "Joining mongodb replica set: mongo-replica" Mongo_setup.sh script runs in mongosetup container as entrypoint to initiate replica set: #!/bin/bash mongodb-secondary- 2 restart: "no" networks:Įntrypoint: Image: mongo: 5.0 container_name: mongodb3 Image: mongo: 5.0 container_name: mongodb2 Image: mongo: 5.0 container_name: mongodb1Ĭommand: -bind_ip_all -replSet mongo-replica ![]() Alternatively this can be achieved by leveraging docker container healthcheck but I’d rather use healthcheck as it designed to be used.ĭocker-compose.yml to setup mongoDB replica set and backups: version: "3.9" services: Mongodb-setup container is started for a short period of time to initialise mongoDB replica set. port 27017 -bind_ip_all -replSet mongo-replica, where -replSet defines replica set name. ![]() mongo_backup.sh - runs mongodump command (used in mongo_backup_scheduler.sh)įor each member inside the docker container a mongod instance started with the following settings:. ![]() mongo_backup_scheduler.sh - using cron schedules mongo backups (used in mongodb-secondary-2 container).mongo_setup.sh - initialise mongodb replica set (used in mongodb-setup container).mongodb-setup (temporary docker container responsible for initiation of the replica set)īash scripts used to setup mongodb replica and backups:.mongodb-secondary-2 (secondary, used for backups).mongodb-primary (accepting writes from the application).MongoDB replica set in docker-compose.yml consists of: The higher the number, the higher the priority (please see below mongo_setup.sh script). Note: The value of the member's priority setting determines the member's priority in elections. Secondaries may have additional configurations for special usage profiles (like backups, non-voting member, arbiter). Secondary - replicate operations from the primary to maintain an identical data set.Primary - accepting writes from the application.Prerequisitesĭocker 19.03.0+ installed and docker-compose that supports 3.9 version MongoDB replica set members In this blog post we will create a setup for a 3-member mongoDB replica set with regular backups using docker-compose. The standard replica set deployment for a production system is a three-member replica set. Production deployment of mongoDB is usually done as a replica set to provide redundancy and fault tolerance. As mongoDB stores data in documents (opposite to a RDBMS schema consisting of tables, rows, and relations) it scales well and allows easier sharding of the large collections across multiple machines/clusters. MongoDB is an open source NoSQL database, popular for ‘cloud native’ applications that don’t require strict consistency guarantees.
0 Comments
Leave a Reply. |