Higher performance crafting: Using dedicated servers

Still using a shared hosting for 20+ players and stable income? Switch to dedicated.
You’re not sharing your underwear, so why share a server?


Disclaimer: I am in no way, shape, or form responsible for your actions.
If you empty your already empty wallet or hurt your feelings, don’t blame me. But anyway, happy tweaking.

I’m looking for feedback on my posts, you can contact me on Discord or via email.


What do you need?

    • A dedicated machine,
    • Basic Linux command line knowledge and SSH/Terminal access.
    • Latest Debian stable or Ubuntu stable (could be any Linux OS, till you know what to do. I’m using Ubuntu in this case, as I got a request to setup this machine for someone),
    • Cows.

Step by Step:

  • 0. Install an OS.

As this is meant for a server, install some LTS build of your favorite Linux OS. Don’t run outdated OS installs like Ubuntu 16.04!
I personally recommend Debian, it’s a bit harder to automagically break, but lacks some features Ubuntu provides by default.
  • 1. Install the basics

I’m going to use APT in all of the examples, but you can also use apt-get or aptitude.
First we will install nano, as it’s simple enough for new users, you can also use vi/vim or emacs.

Run the following commands:

apt update
apt install nano
While running the last command, apt might prompt you to confirm the install, you can just click enter as it defaults to yes.
Explanation of the commands:
apt update – Updates repository lists.

apt install nano – Installs package called nano.

Now let’s enable all repository pools in /etc/apt/sources.list.

On Debian we have to add contrib non-free, on Ubuntu multiverse restricted universe (some packages in the restricted pool might be illegal in your country due to licencing).

Open the sources list using nano: nano /etc/apt/sources.list
Right now your sources.list should look something like this (don’t just copy my list!):

deb http://mirror.hetzner.de/ubuntu/packages bionic main
deb http://mirror.hetzner.de/ubuntu/packages bionic-backports main
deb http://mirror.hetzner.de/ubuntu/packages bionic-security main
deb http://mirror.hetzner.de/ubuntu/packages bionic-updates main

Now we have will add multiverse restricted universe after main.

deb http://mirror.hetzner.de/ubuntu/packages bionic main multiverse restricted universe
deb http://mirror.hetzner.de/ubuntu/packages bionic-backports main restricted universe multiverse
deb http://mirror.hetzner.de/ubuntu/packages bionic-security main restricted universe multiverse
deb http://mirror.hetzner.de/ubuntu/packages bionic-updates main multiverse restricted universe

To save and exit we have to click CTRL + X, confirm using Y, and hit enter again.
Now let’s run apt update again, this time it will fetch package lists from all the pools.
Upgrade all current packages using apt upgrade.

Time to install some tools:
htop – an interactive process viewer for Unix,
nload – Network traffic monitor tool,
iotop – Storage IO monitor tool,
screen – Screen manager (I’m going to use screen for this guide, you can also use tmux),
ufw – Uncomplicated firewall,
zstd – real-time compression algorithm, useful for backups,
software-properties-common – Adds add repository commands,
neofetch – Tool most commonly used to flex on other users.

Let’s install the tools we need using the following command: apt install htop nload iotop screen ufw zstd software-properties-common neofetch.

  • 2. Configure UFW

Due to DigitalOcean already having an excellent guide, I’m not going to write my own: Please follow their guide.
Quick notes:
To allow yourself to fully access any port use: ufw allow from (IP).
To allow Bungee/Proxy to access a specific port use: ufw allow from (IP) to any port (PORT).
DO NOT ALLOW SSH TO THE PUBLIC!
Only forward what you need in most cases that would be the server or proxy port.
If you forward backend servers to the public, I want you to learn something about Darwinism.

  • 2.5. Configure SSH keys (optional)

Due to DigitalOcean already having an excellent guide, I’m not going to write my own: Please follow their guide.

  • 3. Install Java 11+

On almost any platform, AdoptJDK will get you up to date with the latest JDK, just follow their instructions (scroll down to the installer section): https://adoptopenjdk.net/installation.html

For Debian and Ubuntu the guide is as follows:

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add -
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
apt-get install adoptopenjdk-11-hotspot

Follow the official guide from Adoptioum: https://blog.adoptium.net/2021/12/eclipse-temurin-linux-installers-available/

  • 4. Add a user

As it’s not recommended to run any kind of servers as root, we will create a user for our servers.
The command is pretty simple: adduser (username).
Upon execution it will prompt us to set a password, so make sure to choose a good one. The rest of the values can be ignored (Full Name, Room Number, …), just make sure to confirm the information.
Now that we have the new user created we can switch to it, by reconnecting as the new using using SSH or using the command su (username).

  • 4.5. Copy your old files to the new user

You can copy files using sftp or any client that implements sftp for example FileZilla.
For other methods you can always consult a search engine.

  • 5. Prepare your servers

I will use my startup script for this example as it’s ready to be used with screen and automatic startups.

Copy my script to your server directory, name is something like start.sh, now add execute permissions using chmod +x start.sh.
Edit the script to fit your needs (Disable GONE, enable ZGC), under the #!/bin/bash line add the following line: cd /home/(user)/(serverdirectory), make sure to replace the user and server directory with the correct path, you can use pwd inside the server directory to get the full path, we add this line to enable auto startup on reboot.

Now start the server inside a screen.
First we will start a named screen session screen -S (name),
now we can start the server using ./start.sh,
after the server starts we can detach from the screen by pressing: CTRL + a and then d.

Now you can go and check if the server is still up.
To reattach to the screen you can use screen -R (name), if someone already took your screen, you can do screen -x (name) to join the screen, if you want to kick them out screen -D -RR (name).

Other useful shortcuts screen include (you have to click CTRL + a before using any of these):
k – Kills the screen,
c – Creates a new screen inside a screen,
n – Switches to the next screen,
ESC – allows you to navigate the onscreen text.

  • 5.5. Automatic startup and restarts.

To add automatic starts and restart we can use cron*.
* Using something else would be recommended, as cron can run before the networking starts, you can modify that behavior or use something like systemd directly.
To edit the cron use the following command crontab -e.
Now let’s add the following lines (make sure to fill them with your info):

#Auto restart at midnight.
@midnight screen -S (name) -X stuff "stop^M"
#Auto startup on machine restart.
@reboot /usr/bin/screen -dmS (name) /home/(user)/(server)/start.sh

The line that starts with @midnight will send the stop command to the server at midnight, for Bungee replace stop with end.
The line starting with @reboot will be called when the server reboots, starting a detached screen running the start.sh script.

  • 6. Automatic remote backups

To add remote backups implement a script that will compress and upload files that are worth backing up.
I’m purposefully not going to go into too much detail, but you can look at my Google Drive backup script if you are interested.
Just like above, we can run the script using cron.


And now the adventure begins!
Only for advanced users.


  • 7. Update everything

Update to the latest builds/version of software you are already using:
MariaDB,
Ubuntu: Apache2 and PHP,
Debian: Apache2 and PHP,
for other packages consult a search engine, but don’t install shady trash.

  • 8. Install a custom kernel

I’m personally using XanMod, the full installation guide is on the projects homepage.

  • 8.3. Disable Intel mitigation

Is this safe? No.
Should you do it? Yeah… perhaps, maybe.
How? Edit /etc/default/grub add the following to the GRUB_CMDLINE_LINUX_DEFAULT linemitigations=off.
After that make sure to run update-grub and reboot.

  • 8.6. Undervolt

Is this safe? No.
Should you do it? Yeah… perhaps, maybe.
How? Follow the guide here.
This is only really needed on Intel SkyLake+++++++++++++ CPUs.

  • 9. Tweak sysctl

Is this safe? Yes.
Should you do it? Yes.
If you followed the full guide on installing the kernel you should already have net.core.default_qdisc = cake set.
I also use the following settings:

#No IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
#Huge Pages (transparent)
kernel.mm.transparent_hugepage.enabled = always
kernel.mm.transparent_hugepage.defrag = always
#TCP tunning
net.ipv4.tcp_fastopen=3
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=1200
net.ipv4.tcp_mtu_probing=1
net.ipv4.tcp_low_latency=1
net.ipv4.tcp_no_metrics_save=1
net.ipv4.tcp_moderate_rcvbuf=1
net.ipv4.tcp_window_scaling=1
net.ipv4.tcp_reordering=3
net.ipv4.tcp_low_latency=1
net.ipv4.tcp_sack=1
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_adv_win_scale=1
#Memory/SWAP
vm.swappiness=10
#CPU Stuff
kernel.sched_migration_cost_ns = 5000000
kernel.sched_autogroup_enabled = 0

You can skip the huge pages part if you dislike using them.

  • 10. Use HugePages/TransparentHugePages

Is this safe? Yes.
Should you use them? Yes.
Look above. Make sure to update your startup script accordingly (look at my script for examples). You might also find other applications starting to use HugePages without you telling them, that’s normal.

  • 11. Enable SSD trimming

Is this safe? Yes.
Should you enable it? Yes.
Some Linux distribution already enable SSD trimming. But for best performance and disk longevity you should verify that it’s enabled and working.
Debian has a short guide on SSD optimizations that can be found here.


That’s It, You’re Done!