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.
- Do I need to have the database on RDS where every instance simply points to it.
- 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.
- If I modify the site, let's say change the something in the CSS file, how do I sync the changes to all instances.
- How do EBS or S3 play a role in all of this.
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.
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.
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...
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.
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.
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.