Thursday 27 August 2020

How to run a free Minecraft Server in the Oracle Cloud (3rd. Update)

This is an update to my older posts on how to run a Minecraft Server in the Oracle Cloud. As the OCI is constantly enhancing, I try to keep up describing the easiest way to run your Minecraft server.
Best things in life are free and so could be your Minecraft server. Just get an Always Free subsciption on the Oracle Cloud Infrastructure (OCI) and follow the steps below.
Start at the OCI console startpage. As you can see from the small badges, a VM instance is Always Free Eligible. Choose 'Create a VM instance'.
Give it a name and stick with the defaults. When using an Always Free machine, pick an image and machine combination that is eligible for Free Tier.
Scroll down and adjust the shape, if needed. If this is your first project on OCI, you probably don't have a Virtual Cloud Network. The VM wizard will notice this and offers you, to create such. Give it a name and make sure that 'assign a public IP address' is checked.
Do not forget to upload your ssh public key. For the rest, leave the defaults and click 'Create'
You will get a long list of what OCI will do for you. Wait until it shows 'Running' and copy your public IP address.
The next steps are the same as in OCI-C. Set up a ssh connection with your favorite ssh client. I use PuTTY on Windows. Paste the IP adress and save the session.
Enter the Auto-login username 'opc'.
Under Connection/SSH/Auth choose your private key file. Then save again and open your session.
And here we are, hello OCI. Pull the Minecraft server directly from its publisher via (check for the version you prefer)

wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar

Install the Java version you want to use, e.g.

sudo dnf install java-11-openjdk

Probably this will pull some other updates. Then start the server:

java -jar server.jar

After the first start, the server terminates immediately, because you have to accept the EULA first.
It created a new file eula.txt. Open it in vi and change the content to eula=true.
Before we start the server again, lets open the port in the Linux firewall.

sudo firewall-cmd --permanent --zone=public --add-port=25565/tcp
sudo firewall-cmd --reload

As the Minecraft server has an interactive console, it should be accessible even when the SSH console has been closed in between. I prefer to the screen command for that, which can be installed by.

sudo yum install screen.x86_64

Then open a new screen and start the server with

screen -S minecraft
java -jar server.jar

With the server running, we are done with SSH. Close the screen session via CRTL-A D or just close your PuTTY window. If you want to reconnect to your Minecraft server from a new SSH session, just type

screen -d -r minecraft

Now our Minecraft server is up and running and the Linux firewall is open, so it could serve requests. But we first need to open the Minecraft port on OCI too, because by default on OCI all ports except for ssh are closed for security reasons.
Back to the OCI console, open the Hamburger menu and to to Networking/Virtual Cloud Networks.
There you shoud find a VCN with the name you gave it when creating the instance. Click on the name to open the settings.
Click on Security Lists on the left under Resources.
Click on the Default Security List to open the settings.
From the Ingress Rules you can see, that any incoming TCP traffic, except for ssh, is blocked. So we need to add a rule for our minecraft server here.
By clicking on 'Add Ingress Rule' we can define our rule for CIDR 0.0.0.0/0 (all internet) and the Minecraft server port 25565.
The rule should be listed under Ingress Rules. Now we are done with the OCI setup.
Start Minecraft and configure a new Server. Give it a name and enter the public IP address of your instance.
Your Oracle Cloud instance will be listed in Minecrafts server list, notice the good ping. Double click to start your game.
Have fun with the Oracle Cloud and Minecraft!

BTW: this tutorial is meant to demonstrate the usage of OCI, not to do a perfect Minecraft setup. There are many tutorials to do this, like this one.