Saturday, July 6, 2013

aws ec2 webhosting


  1. Create a AWS account.
  2. Decided what region you want to be in. Lots of things go into this decision, but worry about it later and just do a cheap one like Oregon or East.
  3. Make sure you are in the correct region at the top left.
  4. Then click launch server.
  5. At this point you have to pick a AMI. An AMI is basically the template you want to use when you boot your server. Amazon gives you some, but there are a ton in the community section. I am a CentOS guy so I usually search for a CentOS AMI. RightScale makes some good ones so you can search for one of those. Make sure you pick i386 or x64 depending on the size of server you want. There are two distinct types of AMI's, EBS backed and S3 backed. Really you should stick with EBS because you have some more freedoms, but there are reasons to use both that are beyond the scope of this answer. Look for EBS and you probably will be good. EBS is the block storage. Basically it is attachable harddrives for your instances. Since everything in the cloud is "virtual" and nothing is thought of in a physical sense, you have to think that way too. So if you want more storage, you can attach some EBS volumes later. One thing though, S3 backed instances go bye bye when you shut them down. The EBS ones will too if you have the delete on termination flag set, but with EBS ones you can "Stop" them as well as "Terminate" them.
  6. Select the size and availability zone. The zone is important if you are going to be setting up some kind of redundancy. Like if I have a master slave setup with MySQL I would put the master in one zone and the slave in another in case Amazon was having troubles that were isolated to one zone. But for this general purpose, don't worry about it.
  7. Advanced Instance Options. Just leave all this alone most likely it is fine. Some of the small things here you can set later like termination protection.
  8. Name it. Whatever.
  9. Make a SSH key. Striaght forward. The only way to login to an Amazon server will be with the SSH key you assign it. There are no user names or passwords.
  10. Security Groups. This is where you could get tripped up, well here and #5. But you should start off with creating a general security group call foo or whatever then adding the ports you want open on it. So if you want to ssh into it, which I assume you do, then open 22. If you want to use it for web then open 80 and 8080 or whatever. But be careful. I usually change my SSH port later to something random. And instead of putting 0.0.0.0/0 on it, I put my personal ip. But if you don't care that much just put 0.0.0.0/0 and open that bad boy to the world.
Then it will boot. As long as it all went as it was supposed to.
Now you can login. Just ssh -i thekey.pem thenwholehostname
Hope that helps.
There is this whole free tier you can use. http://aws.amazon.com/free/
Check that out. I would use that while you play with it.
I did all that from memory so I could have been off. ;)

Now to see your webpage - Make sure you stop iptables in your instance 

Yes it is completely possible to host websites on AWS in 2 ways:
1.) Easy - S3 (Simple Storage Solution) is a bucket storage solution that lets you serve static content e.g. images but has recently been upgraded so you can use it to host flat .html files and your site will get served by a default Apache installation with very little configuration on your part (but also little control).
2.) Trickier - You can use EC2 (Elastic Compute Cloud) and create a virtual Linux instance then install Apache/NGinx (or whatever) on that to give you complete control over serving whatever/however you want. You use SecurityGroups to enable/disable ports for individual machines or groups of them.
@danben your EC2 instance does not have a constant public IP by default. Amazon makes you use a CNAME - not an A record as your IP may change under load. You have to pay for an ElasticIP to get a consistent public IP for your setup (or use some sort of DynDNS)

rsync with delete option and different ssh port

How to rsync e.g PIPELINE dir from Source to Destination? #rsync -avzr   --delete-before  -e "ssh -p $portNumber"  /local...