Skip to content

Instantly share code, notes, and snippets.

@AI-nsley69
Last active September 18, 2023 01:50
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AI-nsley69/e87714265a36a4662cfeeaacba312be0 to your computer and use it in GitHub Desktop.
Save AI-nsley69/e87714265a36a4662cfeeaacba312be0 to your computer and use it in GitHub Desktop.
Setting up a free fabric server (with recommendations)

Questions?

If you have read the entirety of this guide or you're confused about any part, feel free to ask in my discord server. Please check the troubleshooting & faq section before asking. Your issue or question might've already been covered here. I try my best to keep this guide up to date, but I do forget about it at times and I could also miss anything in the guide when updating it to a new version. Please do your own research (for mods in particular) and try using newer versions of the mods/software available if it breaks!

Used commands

This is a small list to explain the linux commands being used in this guide.

cd - This allows us to change our working directory (also known as ./) into another directory, by default, you will be in your home directory (/home/user/ also known as ~). If you wish to go to a parent directory (the directory which your current directory is in), then you can simply use .. as the destination.

mkdir - This lets us create a directory, we use this to make one for housing our minecraft related files and we'll be relying on cd to get into it. This is all for making it cleaner instead of having all of your files in one place.

curl - This is a tool to transfer data from a server, we use it to grab files such as the fabric installer and fabric mods.

sudo - This stands for superuser do. It is used to execute commands as root (basically administrator) in this guide.

dnf - This is what handles the packages on Oracle Linux, we use it to install various programs we'll utilize in this guide.

nano - A terminal text editor to edit files.

screen - A screen manager, this will manage a session for us that would otherwise not exist when we disconnect from ssh, therefore not having the Minecraft server stay up 24/7

man - This command is not used in the guide, but I highly recommend learning it, as you can read manual pages from commands with it, always look at this if you're stuck first! (Example usage: man cd).

firewall-cmd - Firewall running on the server (yes, you have a software firewall managed by the vm and another one managed by Oracle Cloud, both will need to be configured.), we can use this to open ports for the firewall to let through.

Downloaded software

In this guide, we will download various software (with the Oracle Linux OS provided by Oracle Cloud). Screen is used to handle a session to keep the server running, zip is a dependency for sdkman, sdkman is a package manager for SDK (software development kit) which (in my opinion) makes it easy to install jre (java runtime environment). You will also need a method to ssh into the machine, make sure you know how to use ssh keys (public and private) to connect to the machine with whatever software you're running. It is more safe than using a password!

Recommended software

If you're on Linux, I simply recommend using the terminal emulator of your choice to ssh and transfer files with, or transfer files with your file manager if you're more comfortable with that.

For Windows users, I recommend using PuTTy to access the terminal through ssh, if you wish to transfer files, I recommend WinSCP. With WinSCP, You'll most likely get dropped into the root directory, but you can simply just go to the home directory and then the one with the name of your user.

Signup to claim the always free tier

I'm not going to explain this step, it should be straightforward.

Make your Always Free ARM Core VM

Begin by navigating to "Create a VM instance" Image pointing to create virtual machine

Give the instance a name of your choice, such as minecraft-server Image showing first part of creating a virtual instance

Scroll down to Image and Shape and Change the Shape to VM.Standard.A1.Flex. For maximum performance, please change the shape to 4 cores instead of 1, however you should be fine to run it on 2 cores instead, it is up to your liking and how you wish to spend your resources. I also highly recommend you stick with Oracle Linux as that seems to be performing best on their hardware. Image showing the Image & Shape section Image showing the configuration for A1 flex shape

Afterwards, double check that the Always Free Eligible label persists next to the name. Image showing Always Free Eligible label

Next up is making sure that it has a virtual cloud network with ipv4 address assigned and a subnet. You could create this with the setup shown in the image. Image showing network configuration

Next up, you will need some sort of ssh access, choose one of the options for ssh and handle it how you feel is best suited, you will need some sort of method to ssh into the machine in the end. After this, leave the boot volume defaults and create your virtual machine.

Open port 25565

This is vital for anyone to be able to connect to your virtual machine, you will need to open port 25565 as UDP and TDP, to do this navigate to the control panel of your virtual machine and press on the subnet. Don't forget to write down your ip from the machine, this is to connect through it via ssh and minecraft later on. Image showing subnet

Press on the default security list to change firewall rules. Image showing default security list

Press the button to add an ingress rule

Image showing button to add ingress rule

Add an ingress rules, only one for Ip Protocol TDP (UDP is unneccesary) with this configuration:

  • Source Type = CIDR
  • Source CIDR = 0.0.0.0/0
  • Destination Port Range = 25565 Example image below Image showing ingress rules to add

Now, ssh into your virtual machine and run these 3 commands to open them on the firewall on the machine:

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

If you're not sure how to ssh into your machine, try ssh opc@ip.to.your.vm

Install fabric and java

We are going to install Java through dnf, if you plan on running a server before 1.16 (especially forge) you will need to use java 8. Any other server software will work with java 17 all the way back to 1.7.2

sudo dnf install java-17-openjdk

If you wish to install java 11 or 8 instead, that is doable by replacing the 17 with those 2 numbers. Other versions are not available through the official repository (the source from which dnf uses to install software).

Next up, we create a directory and download fabric.

mkdir minecraft
cd minecraft
curl https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar -o fabric-installer.jar

If you wish to create a minecraft server on the latest version of Minecraft, simply run this command below

java -jar fabric-installer.jar server -downloadMinecraft

However, if you wish to specify your minecraft version you need to pass the -mcversion flag and specify the version after it, i.e for 1.16.5 you would add -mcversion 1.16.5. Please do note that different versions need different java (1.17 needs java 16 and anove, whereas 1.18 needs java 17 and above. Most cases you can use java 17 for older versions too, but it doesn't go as well for older versions like 1.7) to the end of the command above. To get all availabe flags you can set, run java -jar fabric-installer.jar help

Run your Minecraft server.

For running the minecraft server, we will use a systemd service. Which allows it to run in the background of the server and not depend on your session (the thing you're connecting to, as running it normally would be connected to it) to be active.

Controlling the server after this will be quite simple:

sudo systemctl <start/stop/restart> minecraft # Replace the brackets with either of the commands, does as described
sudo journalctl -fu minecraft # This will get the latest logs, run with -u instead of -fu to get the full logs

First of all, we need to accept the eula, this can be done easily with the command below, however, I recommend making yourself familiar with the EULA before agreeing to it.

echo "eula=true" > eula.txt

If you wish to skip the explanation for how to setup the systemd service file, simply run the following commands

sudo curl https://gist.githubusercontent.com/AI-nsley69/ba4050b9bc3584b59d0424f25fda99a2/raw/e2d151f355dbd6488ae80a04a548dc233753343a/minecraft.service -Lo /etc/systemd/system/minecraft.service
sudo curl https://gist.githubusercontent.com/AI-nsley69/ba4050b9bc3584b59d0424f25fda99a2/raw/e2d151f355dbd6488ae80a04a548dc233753343a/minecraft.socket -Lo /etc/systemd/system/minecraft.socket
sudo systemctl enable --now minecraft

TODO: Write an explanation of the systemd service file and how to configure it

And you're done! Now you should be able to connect to your Minecraft server by entering the ip. If you have any questions or issues, feel free to ask in my discord server.

Credits

Images from Oracle Cloud guide.

DO NOT USE THIS! It breaks with the systemd service file due to SELinux!

I personally prefer installing Java through sdkman, which is a package manager for Software Development Kits (SDK) such as Java. I will also be using screen to handle the session for the minecraft server and curl to download mods from github. First up, install screen and zip through yum (which is our package manager on Oracle Linux), zip is needed for sdkman.

sudo dnf install -y screen zip

If screen can't be found, run the following (or use tmux):

curl -LO https://download-ib01.fedoraproject.org/pub/epel/8/Everything/aarch64/Packages/s/screen-4.6.2-12.el8.aarch64.rpm
sudo dnf install ./screen-4.6.2-12.el8.aarch64.rpm

When that has finished installing, we can download sdkman

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

Now we can run a command to check all available java installations with

sdk list java

My personal go to is zulu, preferrably latest version. To install a java version, simply run

sdk install java <Identifier>

At the time of writing this, the latest available zulu build has the identifier 17.0.1-zulu. To install that version, simply replace the <Identifier> part with it.

Run your Minecraft server.

THIS METHOD IS NOT RECOMMENDED. PLEASE REFER TO THE NEWER ONE!

The most basic command would be

java -jar -Xmx2G -Xms2G fabric-server-launch.jar

If you wish to change the memory used by the server, change the 2G in both -Xmx and -Xms. Please change memory according to your needs, but do so safely. You do not need to allocate a lot for a small server. I rarely recommend modifying jvm args unless you know what you are doing, in that case I doubt the majority of this guide is useful to you in the first place. I recommend putting this into a file named start.sh:

tee start.sh << EOF
#!/bin/bash
java -jar -Xmx2G -Xms2G fabric-server-launch.jar
EOF

The final step is to use the chmod command to make the file executable, like so:

chmod +x start.sh

Your server should be almost done now. It's a matter of launching it and installing any mods you need. We now need to start a screen session called "minecraft". This is so we have a session that is not managed by your computer, else the server would instantly die once you terminate the session.

screen -S minecraft

To exit this session, use the following keybind ctrl + A + D. The good part about a session is that the Minecraft server will not stop due to us closing down our ssh session or exiting it. You can rejoin the session later (in a new ssh session i.e) by running screen -r minecraft.

If you need to kill a screen session, you can see the available screens with screen -ls. It will be displayed in the format of pid.name where process id (pid for short) is an integer. We can kill the screen session with kill (pid of your screen session). This will forcefully shutdown the server with no autosave, thread careful with it. If you're curious to more things you can do with screen, you can run man screen to get the manual for it. However, knowing that the -S flag is to create a new session, attach to it and that -r will reattach to a session (-R will try to reattach, but create a new one if it's not found, not recommended) and how to kill a screen session is enough for basic usage.

Now that you've created the session, while inside of it, you can start your Minecraft server with

./start.sh

When launching your minecraft server, you will need to agree on EULA. Simply run it through your favourite text editor (nano is preinstalled).

nano eula.txt

and change eula=false to eula=true. Now press ctrl + x and when you're prompted about saving it press y and then enter. Afterwards, start your minecraft server again and it should be working.

Recommendations

How much memory should I allocate?

Please refer to Jellysquid's gist. It is written for people asking this question regarding client-side, but it translates quite well for servers. I wouldn't allocate more than you need, but I also wouldn't allocate less than needed. For example, a server with half a dozen of players would run very well on 2-4gb, even for more modded fabric environments. Ultimately, test it yourself and tune to your own situation, I find 2-4gb for the capacity this server could have to be decent.

Change the following settings in server.properties

broadcast-console-to-ops=false
sync-chunk-writes=false

Sync chunk writes has been personally causing issues when loading/unloading chunks, turning it off solved it for me. Broadcast console to ops can affect ops on the server with bad internet, as it's taking up more bandwidth

Installing mods (1.18.1)

This here will install lithium and carpet for you, you could either use curl -LO https://website.com/download/link with the direct download link (doesn't work with curseforge from my experience) or upload through WinSCP.

cd ~/minecraft/mods
curl -LO https://github.com/CaffeineMC/lithium-fabric/releases/download/mc1.18.1-0.7.6/lithium-fabric-mc1.18.1-0.7.6.jar
curl -LO https://github.com/gnembon/fabric-carpet/releases/download/1.4.56/fabric-carpet-1.18-1.4.56+v211130.jar

If you wish to install more mods, you could begin by looking into this section of alkyaly's list of performance mods. I highly recommend you look into these mods before install them on anything you care about, however, the author has done a decent job of marking potentially dangerous mods that are not yet quite ready.

Start minecraft on reboot

This is assuming your launch script is in /home/$USER/minecraft and that you have crontab installed. We will also start it in a screen session called minecraft.

First step is to open up crontab

crontab -e

Now we simply just add this in there (press a for insert mode if vim) and save it (esc :wq enter to save)

@reboot screen -dm minecraft && screen -S minecraft -X stuff 'cd minecraft && ./start.sh\n'

After this, your server should be launching everytime the machine reboots!

Install a ramdisk (⚠️ A bit risky! ⚠️)

A ramdisk is a disk that runs entirely in your ram, I do recommend this if you wish to have very smooth loading, however there are a few disadvantages such as corruption if your ramdisk runs out of space or data loss/corruption on a sudden shutdown of the system. However, if you wish to proceed, do so at your own risk. Bare in mind, this will create a 8gb big tmpfs, I do recommend running this if you have 8gb of memory to spare for the server.

Add tmpfs /home/opc/minecraft/world tmpfs defaults,size=8000m 0 0 to /etc/fstab with

sudo nano /etc/fstab

Now we need to copy over our world folder

cd ~/minecraft
cp -r world world_storage
rm -r world
mkdir world

This will copy the world directory to one called world_storage, which will be the place where we store the world on a harddrive incase the computer dies or anything. Next step is to add a few things to crontab

crontab -e

This will open crontab for us, simply press a to start insertion mode

@reboot cp -r /home/opc/minecraft/world_storage/* /home/opc/minecraft/world
*/5 * * * * rsync -r -t -v /home/opc/minecraft/world/* /home/opc/minecraft/world_storage

Paste this in and press esc + : + w + q and press enter. This will tell it to write and quit the editor. Now we need to sync the world everytime we close the server

echo 'rsync -r -t -v /home/opc/minecraft/world /home/opc/minecraft/world_storage' >> ~/minecraft/start.sh

After this, start the session for the server again and start up your server, chunkloading shoud now be smooth!

Automatic restart

Simply change your script to this:

#!/bin/sh
while true; do
  java -jar -Xmx1G -Xms1G fabric-server-launch.jar
  
  echo "Restarting server.."
  sleep 5
done

If you have configured anything else, or added more commands to your script, simply put those between the java and echo command. The sleep command is just to easily exit the server between restart (i.e if you wish to stop it for a while etc, you can simply do it while the Restarting server.. text is occuring without any issues).

Setup a free DNS

This is mainly to have a cleaner address and reduce the hassle of sending ips all the time. If you cannot afford an ip, fear not! I have a solution, you can use noip to get a subdomain on some of there domains, however, you will need to refresh it once a month, but it's free. Alternatively, you can use duckdns, great service that I have personally used before and loved it.

Graalvm is a vm that is meant for high optimization, combined with graal jit compiler you may see a performance improvement. However, I have personally seen a much greater warmup time with graalvm and graal jit compiler compared to something like adoptopenjdk, but after 20-30 minutes that has stabilized and the idle mspt is lower.

To install graalvm, you follow the similar process for what we did before, but using a graalvm build (like 21.3.0.r17-grl). Then, to enable the jit compiler, add these jvm arguments to your startup command:

-XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -XX:+EagerJVMCI -Djvmci.Compiler=graal

As I said though, this might improve performance, this is only if you find this interesting or wish for a small edge in performance, but make proper tests and check whatever works best for you in your situation!

My instances was shutdown, whys that?

Do not fear, after your free trial, your instance will need to be remade. I had some issue like:

Unable to start instance: Instance (instance id) is disabled and will not accept any action requests. Please contact customer support to reenable

However, you simply just need to terminate the instance, make sure to not delete the attached boot volume, then simply browse to your boot volumes, select the detached one and remake your instance from that boot volume (you will not need to put in ssh keys again, but will need to change shape). Other than that, it should be back to normal once you start it up and connect to it etc.

Troubleshooting

Providing necessary information

Before you asking for help, please make sure you've read everything carefully, including the FAQ below to prevent any repetitive issues that have been explained. Thank you!

If you are asking me (or anyone else) with help regarding these servers, you would need to provide necessary information. This includes (but is not limited to) logs/latest.log or the appropiate crash report file, mods installed and other diagnostics information you can provide.

mclo.gs (for sharing logs)

I've provided a script below to upload your logs to mclo.gs. I recommend this method over the one below (with netcat) since it'll censor data you may not wish or intend to share. It depends on curl & jq which can be installed via yum:

sudo dnf install jq curl

Then we can get the script, make it an executable and add it to path:

sudo curl https://raw.githubusercontent.com/KhaosMC/khaos-scripts/main/log -Lo /usr/local/bin/mclogs
sudo chmod +x /usr/local/bin/mclogs

Now we can upload with:

mclogs path/to/latest.log

Usually, the logs will be in a directory inside ~/opc/minecraft/logs, unless you used other paths than the examples in this guide.

termbin.com (for sharing logs)

A simple way to upload logs is to use netcat with termbin, to install it with yum, run the command below:

sudo yum install npm-ncat

Here's some examples of using netcat to upload information to termbin. If you have been following this guide, these commands will assume that you are in the ~/minecraft directory, which would be the root directory of our minecraft server.

ls mods | nc termbin.com 9999 - This will upload the contents in your mods directory.

cat logs/latest.log | nc termbin.com 9999 - This will upload the latest log produced by Minecraft.

java -version | nc termbin.com 9999 - This will upload the version of your Java installation.

Please do remember to copy the link and send it for others to assist with debugging.

FAQ

I can't connect to my vm!

Make sure you've properly setup ssh keys, whether you've downloaded them through oracle cloud or generated your own and uploaded the public key. A public key is used by the server to encrypt the information sent to you, then, your client decrypts it with the private key. Never ever give out your private key! I also do not recommend enabling password login, it's a lot less safe than ssh keys.

How do I transfer files?

You can use your ssh keys to transfer with sftp (file transfer protocol over ssh). For example, you can use WinSCP or Filezilla, you simply need to figure out where to put your keys for authentication, then you can connect to the vm with the host ip and port 22. Alternatively, you could use scp or sftp command from a terminal on your computer.

Why are you not responding?

I have class, I'm sleeping or busy with other things. You're free to join my discord and ask for help in the #hosting channel under the Minecraft category. I have other friends who may be willing to assist you with this :)

I am getting errors from fabric about the wrong minecraft version for some mods!

This is due to me not frequently updating the commands used to install the mods, and as such they can be a bit outdated. If this occurs, please refer to the upstream url (the github link for said mod) and install the latest compatible version that you are aware of.

I can't register an account!

This is out of my reach, but from my personal experience, make sure the majority of your information is correct, it otherwise failed for me.

My region is out of capacity!

You're out of luck. You might use one of the AMD vm's (1/8th of cpu time on 1 core), however, they are very slow and might need a lot of tuning to work properly, or wait until they increase the capacity.

My instances was shutdown, whys that?

Do not fear, after your free trial, your instance will need to be remade. I had some issue like:

Unable to start instance: Instance (instance id) is disabled and will not accept any action requests. Please contact customer support to reenable

However, you simply just need to terminate the instance, make sure to not delete the attached boot volume, then simply browse to your boot volumes, select the detached one and remake your instance from that boot volume (you will not need to put in ssh keys again, but will need to change shape). Other than that, it should be back to normal once you start it up and connect to it etc.

@Chevronie
Copy link

none of the pictures load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment