Setup Minecraft Server (java edition) in AWS EC2

Setup Minecraft Server (java edition) in AWS EC2

My kids recently asked if they can start playing Minecraft with their friends. After a little discussion I discovered that they were all just playing single player and talking about it later. Well, we all know one of the joys of Minecraft is playing with your friends on a server - so I set about setting up a safe server space for them all.

I found a great tutorial (see link below) from Franck Schmidlin however it was after following this that I learned there are two different types of Minecraft:

  • Bedrock: this is the newer 'unified' version that allows cross platform play for every platform except Mac/Linux using the Bedrock Client.
  • Java Edition: this is the original version (kept up to date) that allows cross play for Windows, Mac and Linux provided you are using the Java Edition Client.

After realising that Franck's tutorial is for Bedrock, and my kids would need Java I tried finding and following various tutorials online. Very few of them would work, simply because Amazon moves so quickly with the EC2 Instances, it's hard for tutorials to stay relevant. I even spent a good hour on the phone to a geek mate Jack Skinner to pick his brains looking at ports and routing, tcp/udp - to no avail.

Eventually I managed to crack it - so here's how to get a Minecraft Java Edition Server up and running for the kids using an Amazon Linux 2 AMI EC2 Instance.

Step One: Setting up the instance

Log into your AWS account (Get a free one here - https://aws.amazon.com/free/) and head to your console.

No alt text provided for this image

Click the big orange "Launch Instances" button in the top right corner to kick off the wizard that will step you through creating an instance.

No alt text provided for this image

Select a 64-bit (x86) Amazon Linux 2 AMI instance from the Machine Image library.

No alt text provided for this image

You have a number of options for the type of instance you want. Franck managed to get Bedrock to run on a t2.micro, however the Java Edition is a bit more intense and so you will need a t2.small or a t2.medium to run, depending on how many connections you'll have. For 2 to 3 kids a t2.small will be fine. Once selected click Configure Instance Details.

You can leave the Instance Details screen and the Storage screen with their default settings and move onto the Tags screen.

No alt text provided for this image

Here you can enter a Name tag and a value for this. This will show up on the main instance screen and allows you to easily find it if you have lots of instances. You can also tag for a cost centre here too if you split/manage your billing with tags. The last screen is the Security Group screen.

No alt text provided for this image

This is the screen where we allow access to the server. I created a security group with the name MineCraft-Server (and a description for easy remembering later), and then added a rule for Custom TCP. Minecraft Java Edition communicates with TCP over port 25565. Set the source to Custom and 0.0.0.0/0 to allow access from anywhere and add a description.

Hit review and launch and fire up your instance. This will pop up a window for creation of a security key pair. Now if you are familiar with SSH and remote connecting to a server, feel free to do this (highly recommended), however if you don't want to faff around with SSH, then choose Proceed without a key pair. (note this means you will NOT be able to SSH to the instance)

No alt text provided for this image

What we'll use instead is Amazon's built in browser SSH-like console to connect and run our server. So with that click Launch Instances and AWS will go off and build and launch your server.

Step Two: getting java installed on the server

AWS removed Java from their Amazon Linux EC2 machines, so we'll have to install a version and this is where I ran into all sorts of issues. I used various tricks to install Java 1.8.0 and OpenJDK Java 11, making sure it was always up to date, but no matter what I did I always ran into an issue where the Minecraft Java Server edition was complied with a newer version. We have to use Amazon Corretto to get Java 16 installed, which will then run Minecraft.

No alt text provided for this image

With your instance now running, tick the box beside the name and then hit the Connect button at the top.

No alt text provided for this image

We'll use the EC2 Instance Connect to open up a new browser window with an SSH like terminal in it for working with our box. Check the details (record the Public IP Address - you'll need that for connecting Minecraft later) and click Connect.

No alt text provided for this image

This is your prompt and you want to type in (or copy and paste) this command and hit enter:

sudo rpm --import https://yum.corretto.aws/corretto.key 

Followed by:

sudo curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo
No alt text provided for this image

You should see it upate the repo and now you can run the command to install Amazon Corretto 16

sudo yum install -y java-16-amazon-corretto-devel

If that executed correctly you should now see

No alt text provided for this image

At this point you can check the java version by typing in java -version and you should see something like this.

No alt text provided for this image

Right your machine should now be running and ready for a Minecraft Server.

Step Three: Installing Minecraft

Let's setup a dedicate user to run the server. So enter:

sudo adduser minecraft

Now we want to setup some structure to put our files into, we'll create a minecraft folder and server folder.

sudo su
mkdir /opt/minecraft/
mkdir /opt/minecraft/server/
cd /opt/minecraft/server

At this stage your SSH client screen should look like this.

No alt text provided for this image

Now we need to download Minecraft which you can get from the Minecraft site.

Now given we are in a fake SSH client we can't just upload it from our local computer, we need to use wget to fetch it for us from the Minecraft server.

// Updated Mar 19th: Minecraft 1.18.2

wget https://launcher.mojang.com/v1/objects/c8f83c5655308435b3dcf03c06d9fe8740a77469/server.jar
No alt text provided for this image

This will go and get the file and download it to the folder you are in. Once complete if you simply type ls and hit enter you should see this:

No alt text provided for this image

Let's set the user for the folder by entering:

sudo chown -R minecraft:minecraft /opt/minecraft/

And now we are ready to run our server - yippee.

Step Four: running the Minecraft Server

Start by using the following command to get your server to fire up:

java -Xmx1024M -Xms1024M -jar server.jar nogui

But don't get too excited yet, it's about to fail for you. The first time you run this it looks to check if the eula file has been accepted. And because the file never existed it sets one up for you. Your SSH window should look like this.

No alt text provided for this image

To fix this we'll use vi editor to edit the file:

vi eula.txt

This will bring you into the file to edit it. Use the arrow keys to move the box cursor around to the end of line with eula=false. Now to edit it hit i on your keyboard and you should see the word -- INSERT -- at the bottom of the screen. You are now in edit mode. Change the false to true.

No alt text provided for this image

Once edited you hit the esc key and type :wq (w = write, and q = quit) and then hit enter.

No alt text provided for this image

That's it, now we can start our server - but before we get carried away, if we simply run the java command again now, as soon as we close the SSH window our server will stop running. We need a way to keep it running, so we'll use screen to do that.

yum install screen
No alt text provided for this image

And then we want to run a screen called mcserver by entering

screen -S mcserver

Type that in and hit enter - and you'll have a brand new prompt at the top of the screen. Now you can run your java command here and once you close the window - the server will keep running.

So now we are finally ready to run our Minecraft Server.

java -Xmx1024M -Xms1024M -jar server.jar nogui

It'll take a moment or two but your world will start coming to life.

No alt text provided for this image

Once complete, you should be able to connect to the Public IP address you recorded earlier via the Minecraft Multiplayer screen in the Minecraft Java Client on Mac, Windows or Linux.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step Five: changes and reconnecting to your server

Of course no server is ready to go as a default server, so you'll want to explore the server.properties using the vi editor to adjust and customise your server.

If you have closed your SSH window and need to get back to your server, it's as easy as opening up the EC2 Instance Connect (see above) and in the prompt typing:

sudo su
cd /opt/minecraft/server
screen -S mcserver
No alt text provided for this image

Summary

I hope that helps - given the speed at which AWS and the world of software moves this might well be out of date as soon as I post it. Maybe it'll help someone, I know it's meant my kids have a server to play on with their friends customised to their needs.

Enjoy.

Update: kids had a bit of a nasty surprise today when one of their friends' brother decided to share the server details with not so nice folks. So we very quickly explored creating a whitelist. This isn't hard, you simply create a .json file with the uuid and name of each person you want to allow access to the server, then in server properties you allow white_list to true. For more details check out this article

Sohail Shehzada

Etsy Expert | Graphic designer

11mo

Awesome

Like
Reply

Something fail to me, I can't connect with the instance public address

Like
Reply
Scott Sherman

Manufacturing and Information Systems Professional

1y

This was very easy and helpful. Thank you. One thing that I am trying to figure out is how to copy a current world that's already in progress to this server and running it.

Like
Reply
Caio Manoel Bezerra de Araujo

Pleno Software Developer | Proficient in .NET/C#, SQL Server/MySQL, and Python | Expertise in Database Management, API Integration, and Automation | Third-Year Computer Engineering Student

1y

This is just an amazing idea! I'll Try it in a docker version so i can start it/end it with a lambda function!

Like
Reply

This is great! Do you think the pricing is better than the current default service realms ($7.99/month)? Also, do you need to start /stop the server when nobody is using it? Or it somehow automatically starts or stop using resources?

Like
Reply

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics