Step by Step AWS EC2 Tutorial
Join the DZone community and get the full member experience.Join For Free
this has been roughly adapted from this serverfault question for the case when it gets removed/deleted/closed.
the question was about how to configure a flash game server on linux, but on ec2. i had a good look around, but didn't find any true step-by-step ec2 tutorials for proper beginners. so i made one. this one is fairly specific to smartfox server towards the end, but the first few bits about creating an instance, and adding stuff to the security group should be generic enough to be useful.
i have made a actionscript 3.0 flash game and implemented multiplayer functionality using smartfoxserver. now i want to put this game on my website which is hosted on 000webhost.
my game works absolutely fine on localhost. but i need to put my smartfox instance somewhere where it is publicly available. this is where i need you peoples help.
there is an article explaining what needs to be done - http://docs2x.smartfoxserver.com/gettingstarted/installation
i do not understand, do i have to put my game and my smartfox instance on a remote server, vps, dedicated server or what?
right. you'll need to get a vps, or at least an amazon ec2 cloud instance to run this on. i'm 99.99% certain that you can't use the free package at 000webhost to do this. they're a pure webhost, and you need somewhere you can configure and install java, and the smartfox server.
so.. go to aws.amazon.com and sign up for a free account.
you'll need to provide them with a credit/debit card number, but they won't charge you as long as you keep within the free tier resource limits.
once you've got an account, go here and start an ec2 instance.
this all assumes you know a bit about linux, but if you create your first instance using ubuntu linux 12.04 64-bit server, it'll make everything a bit easier!
when you click to create an instance you get this chooser:
select "classic wizard" and this ami to boot.
select the for this instance..
and the defaults on the next page too.
select the default storage options.
and then name it.
you now need to create a ssh key, and name that too. when you click "download keypair" your browser will save the private key. keep this safe, because if you lose it, you've effectively lost the master key to your new server.
now we need to create a security group. this is the firewall of amazon ec2.
add inbound rules for ssh, http and https. this'll be enough for now.
review the selections you've made.
hurrah! it should now be booting..
time to get into it. this is the control panel.
select your new server instance, and right click it and you get this menu.
then click connect .
to access your instance: open an ssh client. locate your private key file (smartfox.pem). the wizard automatically detects the key you used to launch the instance. your key file must not be publicly viewable for ssh to work. use this command if needed: chmod 400 smartfox.pem connect to your instance using its public dns. [ec2-xx-xx-xx-xx.compute-1.amazonaws.com]. example enter the following command line: ssh -i smartfox.pem firstname.lastname@example.org
which is nearly right, except as it's an ubuntu instance, you want to
ssh -i smartfox.pem email@example.com
so, let's do that.
and we're in.
gonna need the smartfox installer next ..
download with wget, then tar xzvf and extract it.
so, you can go ahead and start the damn thing now.
ubuntu@ip-10-243-117-245:~/smartfoxserver2x/sfs2x$ ./sfs2x-service start
interestingly enough, it looks like smartfox needs port 8080 opening up on the aws security group firewall.
ubuntu@ip-10-243-117-245:~/smartfoxserver2x/sfs2x$ sudo netstat -anp |grep java tcp6 0 0 127.0.0.1:9933 :::* listen 9142/java tcp6 0 0 :::8080 :::* listen 9142/java udp6 0 0 127.0.0.1:9933 :::* 9142/java
luckily, that's really easy.
on the sidebar of the control panel, there's a security groups link.
edit it, add a custom tcp rule and allow port 8080 to 0.0.0.0/0
add the rule, and **apply the changes**.
you should now be able to reach your smartfox game server on the dns name given to you by amazon ec2 in the control panel. it's the same bit you ssh'd to earlier.
that's all folks!
Published at DZone with permission of Tom O'connor, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.