Thursday 6 June 2019

How to run a Minecraft Server in the Oracle Cloud (OCI Update)


Update: I made a newer and shorter version of this tutorial utilizing new OCI UI features. So please read no further and go to my updated posting under: https://arnes-stuff.blogspot.com/2020/08/run-free-minecraft-server-in-oracle.html

---8<-----------------------------------------------------------------------------

This is an update to my older post 'How to run a Minecraft Server in the Oracle Cloud' covering the older Oracle Cloud Infrastructure Classic (OCI-C). This posting describes how to do the same on the newer Oracle Cloud Infrastructure (OCI).
This time start at the OCI startpage and choose 'Create a virtual cloud network', because we need a VCN first.
For an easy start, select 'Create a virtual cloud network plus related resources', which will give you a complete starter virtual cloud network. Just give it a name, scroll down and confirm.
This will give us a VCN with three subnets in three different availability domains (three physical data centers). This is more than what we need, but as subnets are not charged, it does not hurt either.
Now that we have our networking up and ready, let us move to the compute menu. Click on the hamburger menu and choose Compute|Instances.
There click on 'Create Instance'
You can leave all the defaults. Your VCN should be chosen automatically.
But do not forget to upload your ssh public key.
Wait for your machine to be running, then copy the 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 you private key file. Then save again and open your session.

Pull the Minecraft server directly from its publisher via

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

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

sudo yum install java-1.8.0-openjdk.x86_64

Then start the server:

java -jar minecraft_server.1.9.2.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

Back in the OCI web UI, we also need to configure the firewall rules. From the Server VM page, click on the subnet.
On the subnet page, click on the security lists.
Here, click on the default security list
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.