setting up ec2 minecraft server

November 24, 2011

Goal: set up a minecraft server using free EC2 account from OSX
[update: FAIL — game play doesn’t work on a micro instance, if we want to use EC2 it looks like we need to use at least a small one. so be careful to adjust the steps below to pick a small instance if you want to play.]

I learned that there are a lot of minecraft server implementations. I decided to use Craftbukkit server largely because I saw it referenced from a RubyConf talk by Tom Enebo — might be fun to mod it someday :)

I pieced together information from some helpful tutorials from Ubuntu and Robert Sosinski.

  1. Sign-up for an AWS account (1 year free for new AWS accounts, but you need a credit card)
  2. Go to AWS Management Console
  3. Create a Private Key
  1. Create a Certificate
  1. Make your credential files private. In your local terminal, type:
  1. Download EC2 API Tools
  1. Your ~/.ec2 directory should have:
  1. Set up EC2 Command-line Tools
  1. Startup a server
ec2-###-##-##-##.compute-1.amazonaws.com
  1. Open relevant ports (22 for ssh, 80 for http, 25565 for minecraft):
    ec2-authorize default -p 22
    ec2-authorize default -p 80
    ec2-authorize default -p 25565
    
  2. ssh into your new instance
    ssh -i ec2.pem ubuntu@ec2-###-##-##-##.compute-1.amazonaws.com
  3. Install Java (nice Ubuntu instructions)
    Note: to accept the license, use tab to get to the OK “button” then hit return, then arrow to get to “Yes” and hit return again.
    To verify installation:
    $ java -version
    java version “1.6.0_26”
    Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
    Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
  4. See this tutorial for setting up minecraft, but if you are playing with the Minecraft 1.0 client (at least of today) you’ll need to install a dev build which you can find on the ci server. I found that I needed to run the server, stop it and run it again to get it to start without errors.

[Update] By tweaking the memory allocation, we can get it to work (most of the time) with a single player. I found that I can raise the memory allocation for java and use virtual memory, but that it sometimes maxes out the CPU.

Here’s the setting where the game couldn’t be failed (couldn’t fight monsters or build things):

#!/bin/sh
java -Xmx613M -Xincgc -jar craftbukkit-1.0.0-SNAPSHOT.jar

$top
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                 
 1642 ubuntu    20   0  978m 300m  10m S 12.3 50.7 100:44.96 java                                                                     

Note:
VIRT – 978M of virtual memory
RES – 300m resident (physical) memory


With this it sometimes works:


#!/bin/sh
java -Xmx1024M -Xincgc -jar craftbukkit-1.0.0-SNAPSHOT.jar

 2829 ubuntu    20   0 1336m 271m  10m S 14.0 45.8   0:18.76 java                                                                     

With this works almost all the time (but we’ve only tested one player):


#!/bin/sh
java -Xmx2048M -Xincgc -jar craftbukkit-1.0.0-SNAPSHOT.jar

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                 
 2893 ubuntu    20   0 2499m 341m  10m S 99.8 57.6   0:27.68 java                                                                     

 2893 ubuntu    20   0 2499m 341m  10m S 18.2 57.7   1:27.30 java                     

when the CPU maxes out, I see this in the game console:
22:39:19 [WARNING] Can't keep up! Did the system time change, or is the server overloaded?


Comments

Gary November 25, 2011

Isn't an EC2 micro instance free for a year, not a small instance?
Make sure you're not getting charged more than you think!
Micro probably doesn't have consistent enough CPU for gaming, unfortunately.

Sarah November 25, 2011

Wow -- nice catch, Gary!

Oddly Amazon shows no charges for this billing period, but I don't trust their reporting: https://skitch.com/ultrasaurus/gmcrh/amazon-web-services

I'm going to run thru the steps again for a micro instance -- we're only planning on hosting a few players, so I figured it was worth a try.

Grigory V. November 27, 2011

Hmm. Micro instances automatically scale to 2 “elastic CPU units” or whatever they call them when the load is high. I wonder if using Java 7 and a different server would help.

“ssh -i ubuntu@ec2.pem ec2-” wait, what. Do you mean “ssh -i ec2.pem ubuntu@ec2-”?

> Ubuntu takes up too much disk space by default to fit into a micro instance
Micro instances only work with EBS, 8 GB one is free. Ubuntu Server doesn't take that much space.

Also, you don't *have* to install Amazon's command line tools, you can use the web interface to control instances. And screen isn't cool, tmux is :-)

Steven Soroka January 3, 2012

Any feedback on small instance costs and ec2 performance?