This one is for all the kids (and geek dads & moms) out there. I'm surprised I didn't get to write this sooner :)
Running your own Minecraft server in AWS is pretty straightforward, so here goes!
1) Create an EC2 instance
I've picked a t2.small instance (2 GB RAM) running the Amazon Linux AMI and costing $0.028 per hour at the time of writing. Anything smaller feels... small for a complex Java app, but you're welcome to try. Details and pricing for EC2 instances may be found here.
Only the security group needs to be tweaked: on top of SSH access, you also need to open a port for the server (default port is 25565). If you want to play with friends (which is kind of the point), allow access from anywhere.
Your inbound rules should look like this:
Select a key pair and launch your instance.
2) Install the Minecraft server
Once you ssh'ed into your instance, it's time to select a Minecraft version. Let's retrieve the list (conveniently hosted in S3) :
$ wget https://s3.amazonaws.com/Minecraft.Download/versions/versions.json
My customer (ok, my son) wants to run 1.8.9, so let's download and extract this version:
$ mkdir minecraft
$ cd minecraft
$ wget http://s3.amazonaws.com/Minecraft.Download/versions/1.8.9/minecraft_server.1.8.9.jar
3) Configure the Minecraft server
Start it once:
$ java -jar minecraft_server.1.8.9.jar
It will fail and complain about approving the user agreement (bleh). All you need to do is to edit the eula.txt file:
eula=true
Feel free to edit the server.properties file to add your favorite settings.
4) Start the Minecraft server
The best way to start a long-running server without losing access to the console is to use screen. Here is a simple tutorial.
$ sudo yum install screen -y
$ screen java -jar minecraft_server.1.8.9.jar
Your server is running, congratulations. You should be able to connect to it using the Minecraft client.
In the console, you will see players joining and leaving the game, as well as their UUID, e.g.:
[17:08:11] [User Authenticator #1/INFO]: UUID of player _____Dante_____ is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
This UUID is useful to declare players as operators in ops.json:
$ cat ops.json
[
{
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "_____Dante_____",
"level": 4
}
]
That's it. Don't forget to detach from your server before ending your SSH session, or it will be killed (hint: CTRL-A D). And don't forget to stop the instance when you're not playing, it will save you money :)
Have a nice game and happy New Year!
Would use tmux instead of screen, or better still: install supervisord and setup a startup to put in /etc/supervisor/conf.d:
ReplyDelete[program:minecraft-server]
command=java -jar minecraft_server.1.8.9.jar
directory= /home/ec2-user
autostart=true
autorestart=true
startretries=5
stderr_logfile=/home/ec2-user/mincraft.out.log
stdout_logfile=/home/ec2-user/mincraft.err.log
user=ec2-user