How do I get EC2 load balancing properly set up to allow for real time file syncing?

筅森魡賤 提交于 2020-01-21 00:42:54

问题


I'm new to EC2. I have read a lot about it, watched many videos and tutorial and pretty much familiar with how everything work. I still have few question that I can't seem to find direct answers to.

If I have 3 instances (linux) with load balancing all serving the same site and the site is a dynamic php/mysql driven where users post files forum threads every second, how is the database and files synced to all 3 instances in real time.

  1. Do I need to have the database on RDS where every instance simply points to it.
  2. How about user files. If a user uploaded a file to the site, then this file should be available immediately on all instances immediately, how is this possible. I don't think having 3 copies on 3 instances is very practical.
  3. If I modify the site, let's say change the something in the CSS file, how do I sync the changes to all instances.
  4. How do EBS or S3 play a role in all of this.

回答1:


Do I need to have the database on RDS where every instance simply points to it.

That is one option, or you can boot up another instance to sit behind the app servers, put MySQL on it and have them all connect to that instance. One thing to note, make sure to connect over the internal network using the private ip and make sure all your security is tight.

How about user files. If a user uploaded a file to the site, then this file should be available immediately on all instances immediately, how is this possible. I don't think having 3 copies on 3 instances is very practical.

No that is not practical. You could upload it to that backend db instance that they all have access to, but really you should probably upload it to S3 in a bucket that all your instances can use with s3tools or something.

If i modify the site, let's say change the something in the CSS file, how do i sync the changes to all instances.

Git. (or svn) But you could use cloudfront for your JS and CSS files.... not a bad idea. And use a S3 bucket as your source...

How do EBS or S3 play a role in all of this.

Your database should always be on ebs volumes so you dont lose it. S3 can be used to share and store files cheaply and easily across your entire environment.




回答2:


In most cases, you could have one RDS instance that all 3 ec2 instances connect to. If you have a very relational demanding database application, you can look into database replication.




回答3:


Using S3 is one way to sync your files. You got to write the codes that every photo upload (for example) will got to your S3 bucket. But of course the your 3 instance should be able to access it.

Another solution is to have a shared filesystem, where you share a directory to the 3 instances. Possible solution to this is NFS or GlusterFS.

For the RDS, I think that's no problem you can use a single DB for the 3 instances. Let me know if this helps.




回答4:


If anyone is reading this in 2019 I thought it would be good to chime in.

To completely leverage horizontal scaling you have to keep your EC2 instances stateless. More details can be found in this aws whitepaper under Stateless Architecture.

https://d1.awsstatic.com/whitepapers/AWS_Cloud_Best_Practices.pdf

Do I need to have the database on RDS where every instance simply points to it.

Yes! this is a pretty standard aws setup.

How about user files. If a user uploaded a file to the site, then this file should be available immediately on all instances immediately, how is this possible. I don't think having 3 copies on 3 instances is very practical.

This is part of the magic that comes with AWS and the cloud. This is can be done with S3. S3 implements something call read-after-write consistency which guarantees full consistency for all new put requests.

If I modify the site, let's say change the something in the CSS file, how do I sync the changes to all instances.

This depends on how your deployment process is like. For static content you can consider using CloudFront. This has versioning for static files. Another way to do this would be to use an autoscaling group. Swap out the launch config with a new ami containing the new version and start terminating the old instances one by one!

How do EBS or S3 play a role in all of this. EBS and S3 serve very different storage needs. This question is too broad to answer.

My two cents would be to read up on aws best practice and architecture to fully leverage the cloud. Dont try to reinvent the wheel. Things are actually simpler than they seem. Cheers. Why isit so hard to sync files across ec2 instance? maybe because you dont have to do it to begin with (yes there are in some cases where this is necessary however i dont think this is one of them). Question the question. Ask if there a way of building this out where I dont have to sync my files with git? Build cloud native architecture and programs to fully leverage the cloud and make your life easy.

However, if you still want to go down this road for whatever reason i would look into devops on aws to manage the resources. Cheers!



来源:https://stackoverflow.com/questions/9591657/how-do-i-get-ec2-load-balancing-properly-set-up-to-allow-for-real-time-file-sync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!