RS Setup Automation using Python

RS Setup Automation using Python

- RS Setup Automation using Python

48fdf38336211f8dbf454afcc6575806?s=128

Aniket Maithani

November 20, 2020
Tweet

Transcript

  1. Creating Replica Set (automation) using Python

  2. Replica Set • A replica set in MongoDB is a

    group of mongod processes that maintain the same data set.
  3. Why do we need Replica Set? • High Availability •

    Better Performance Image ref: https://docs.mongodb.com/manu al/_images/replica-set-read- write-operations- primary.bakedsvg.svg
  4. PyMongo + Python • Used the following libraries along with

    Python- 3.7 • PyMongo – Native Python Driver for MongDB • SSH2-Python – Substitute for Paramiko and faster compared to other libraries • Terraform – Infrastructure
  5. Server Spawning • Using simple terraform script spawned 4 servers.

    • Marked them as Primary, S2, S3 and Arbiter
  6. Steps Involved • Setup IP of machines in /etc/hosts file

    in each machine. 10.2.2.1 mongo1 10.2.2.2 mongo2 10.2.2.3 mongo3
  7. Create RBAC in primary

  8. Python script to generate X.509 based certificates.

  9. Screenshots

  10. Copy certificate in each of the machines Copy config file

    (mongo.conf) update in each machine and restart the machine
  11. Finally!!

  12. Summary • Took me about 2 days to test this

    up and run it on production. • Challenges : – Ensuring no downtime – Implementation – Security Check list • Use of TF and making collection read only • Easy flow control of the Python script • Documentation for further improvements