setting up ec2 minecraft server

November 25, 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):<br></br>ec2-authorize default -p 22<br></br>ec2-authorize default -p 80<br></br>ec2-authorize default -p 25565<br></br>
  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?