johnniexo88
johnniexo88

Reputation: 313

How to setup another instance for load balancing in EC2?

Right now we have one instance. How do we create another instance with the content and files as the first server? Do we just create an instance?

Also if we make a change to a file on server one, do we have to make the same changes on server two? thanks

Upvotes: 1

Views: 327

Answers (3)

naren
naren

Reputation: 46

Best thing to do will be:

  • create an AMI will all the necessary configuration and software installed. Always try to use a golden AMI where possible. (explore something like packer.io)
  • If you cant use a golden AMI use a custom script as part of the user data when launching the EC2 to complete the configuration
  • Create an Auto Scaling Group using the baked AMI
  • In the console under Auto Scaling choose Auto Scaling Groups
  • On the Details tab, choose Edit
  • For Load Balancers, select your load balancer and save.

This way just by changing the number of instances in the auto scaling group will add (using the baked AMI) or remove instances. Better still, adding thresholds to increase or decrease instances automatically can be achieved. As the entire auto scaling group is associated with the ELB any new instances will be automatically configured with the ELB.

Note: Your ELB and the ASG should be in the same region

Please check the amazon docs link: Attaching a Load Balancer to Your Auto Scaling Group

Upvotes: 0

Piyush Patil
Piyush Patil

Reputation: 14523

The best way to achieve your use case is.

  1. Install AWS CLI on your instance.

  2. Create a S3 bucket and add all your application files to that S3 bucket.

  3. Add a Cron Job on your instance that will run a S3 sync command some thing like this

    aws s3 sync s3://mybucket /<path to your application root>

  4. Now take a AMI of your instance.

  5. Attach your instance to load balancer, if you want to add another instance create another instance from the same AMI.

  6. And any file change you want to apply apply it in the S3 bucket so what will happen is no matter how many instance you add to your load balancer they all will be synced with the S3 bucket, so if you change a file add a new file to S3 bucket that file will be changed and added to all the instances that are running behind the load balancer and are in sync with the S3 bucket.

Upvotes: 2

K patel
K patel

Reputation: 54

Suppose you have an application which you need to load balance in VM1 then you would require to follow given step

1.Take the snapshot of the VM1 and also of EBS if one is attached 2.Now create VM2 from this snapshot (this ensure you have same to same content of VM2 just different MAC and IP configuration rest data remains same) 3. Add VM1 and VM2 to load balancer which ever application you would like to load balance 4.If want any changes made to the VM1 data be reflected in VM2 as well without requiring a need to do it manually use rsync(remote sync) utility which takes directory and machine name/ip as input you wish to keep in sync between machine(changes to directory (provided to rsync) made in one machine are automatically updated to other machine)

Upvotes: 1

Related Questions