Skip to content

Simple tool for create hardened(+Full TLS communication) MongoDB replication with extra tools

License

Notifications You must be signed in to change notification settings

aasaam/mongodb-replica

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB replica

Simple tool for create hardened(+Full TLS communication) MongoDB replication with extra tools

License

Usage

sudo ./prepare.sh (name space) (domain) [number of nodes] [initialize port]
  • option (name space) required, consider variable as subdomain, like app0
  • option (domain) required, it's actually your domain name, cluster-domain.tld or mongo.cluster-domain.tld
  • option [number of nodes] is optional and supported following props: 3, 5 and 7
  • option [initialize port] is optional and default is 27000 and must be >= 1300 and <= 48000
sudo ./prepare.sh app0 cluster-domain.tld
# sudo ./prepare.sh [name space] [domain] [number of nodes] [initialize port]
# other examples
# sudo ./prepare.sh app0 cluster-domain.tld 3 28000
# sudo ./prepare.sh app0 cluster-domain.tld 5 12000
# sudo ./prepare.sh app0 cluster-domain.tld 7

# then your files are in deploy/app0
# scp to your servers deploy/app0/node0 -> node0
# scp to your servers deploy/app0/node0 -> node1
# scp to your servers deploy/app0/node0 -> node2

DNS

Set your dns for following servers, for example:

app0-mongo-0.cluster-domain.tld A record 192.168.0.100
app0-mongo-1.cluster-domain.tld A record 192.168.0.101
app0-mongo-2.cluster-domain.tld A record 192.168.0.102

Initialize

For first initialize you must follow these steps:

For all nodes

  1. Allow list of ips or subnet want to access cluster via nginx acl, server ips and application ips

    nano nginx/acl.conf
    
  2. Set data path variables

    mv .env.sample .env
    nano .env
    
  3. Then up the container

    docker-compose up -d
  4. Then go to first node for first initialize

    # create replica wait about 30 seconds to replica start
    ./init-replica.sh
    # you have to see: { ok: 1 }
    
    # then enable auth
    ./init-auth.sh
    # you have to see: { ok: 1 }

Create db and user

On any node

# create data name space you can use it in every data domain like other databases:
python3 ./namespace.py --url="https://www.example.com"
# example-com-d-8h0en49h9rs63etk # for development environment
# example-com-t-8h0en49h9rs63etk # for testing environment
# example-com-s-8h0en49h9rs63etk # for production staging environment
# example-com-p-8h0en49h9rs63etk # for production environment

# create app0 with random user and db suffix with generated password
# also guide for set replica connection string
./create-db-user.sh example-com-d-8h0en49h9rs63etk

Backup

For create backup on any node:

# daily backup if exist will be skipped
./backup.create.sh db-example-com-d-8h0en49h9rs63etk

# now backup
./backup.create.sh db-example-com-d-8h0en49h9rs63etk now

For restore backup on any node

# will be drop old database and restore from file
./backup.restore.sh db-example-com-d-8h0en49h9rs63etk mongo-replication.app0.db.db-vod-promizer-ir-p-av5vwu335w9f.2023-05-22.tgz

On production

You can easily add cron job and run:

* * * * * /path/to/deployment/cron-all-db-daily.sh '10,15,20'

first argument is load average for start creating backup if system is no under pressure then daily backup for all databases will start.

aasaam software development group
aasaam software development group

About

Simple tool for create hardened(+Full TLS communication) MongoDB replication with extra tools

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published