Giter Club home page Giter Club logo

mongodb's Introduction

Terraform Scripts for creating vms in Azure

Terraform script to create 4 vms, with one of them having Public IP for ssh Access

Deployment

Prereq for running this script is an azure account & we are signed into azure cli. Ensure Terraform is installed on the machines. Ensure that the keypair bearing the name: swarmvm & swarmvm.pub is created in the folder that will run the terraform script To deploy this project run

  git clone https://github.com/barishandcloud/mongodb.git  
  cd mongodb
  ssh-keygen -b 2048 -t rsa -f swarmvm
  chmod 400 swarmvm
  terraform init
  terraform plan
  terraform apply 

This provisions: one resource group 4 nic - one with public ip 1 security group with rules allowing ssh nic to security group association 4 Ubuntu 18.04-LTS servers with Standard_B1s sizing in eastasia Region. The region can be modified in the variables.tf file.

To change other parameters please alter main.tf accordingly. terraform output yields the public ip of the machine to ssh.

In order to ssh into vm1

  ssh -i swarmvm azureuser@<public_ip>

Although there are better/more secure alternatives for logging into the other vms, I use a rudimentary method in which I scp the private key into vm1 and from there I ssh into other nodes. This is not production grade and I desist others from using it for anything other than transient vms.

  scp -i swarmvm swarmvm azureuser@<public_ip>:~  

Start a tmux session and synchronize panes after sshing into the three vms: setw synchronize-panes Issue the following commands to initialize the docker swarm:

  1. note the ip of all vms: ip a
  2. Edit the /etc/hosts
sudo nano /etc/hosts #add the below entries
10.0.1.X swarmvm1 #ip of vm1
10.0.1.X swarmvm2 #ip of vm2
10.0.1.X swarmvm3 #ip of vm3
  1. sudo apt update
  2. sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
  3. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. sudo apt update
  6. sudo apt-get install -y docker-ce
  7. sudo systemctl start docker
  8. sudo systemctl enable docker
  9. sudo usermod -aG docker $USER
  10. newgrp docker
  11. Disable synchronize, as the sunsequent command will be issued on distinct vms rather than on collective: docker swarm init --advertise-addr 10.0.1.X #ip of vm1
  12. the above command yields a join token which needs to issued on vm2 an vm3
  13. A docker node ls should show the leader node and two worker nodes.
  14. The terraform script also deploys a storage account and a file share. Navigate to the file share in Azure GUI Console. Click on the connect icon and select Linux. Copy the bash commands and run them through all three vms. This mounts the file share in /mnt/fileshare . This will be the persistent store to be used for all containers.
  15. Create directories to be used by the MongoDB replicaset Volumes from any of the three vms: mkdir -p /mnt/fileshare/mongo/data1 /mnt/fileshare/mongo/data2 /mnt/fileshare/mongo/data3
  16. Create a dir on vm1 and copy the compose file to the dir: scp -i swarmvm docker-compose.yml azureuser@<public_ip>:~/temp
  17. Issue the command: docker stack deploy --compose-file docker-compose.yml mongo , after a wait window of a min or so, a docker ps should yield 3 containers on three vms.
  18. The containers will have a prefix of mongo_con*, make a note of all three container names.
  19. Exec into container running on leader node: docker exec -it mongo_con1.1.xxxxxx /bin/bash
  20. Issue the cluster initiate command from rs-init.sh (everything from 3 till end).

This should have bootstrapped a mongodb container replicaset.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.