Always wanted to host your own Minecraft server but don't know how? In this tutorial, we'll go through the steps necessary to install and configure Minecraft Server on a CentOS 9 headless server. We're going to use systemd to run the Minecraft server and the mcrcon utility for server maintenance. We'll also set up automated server backups using a cron job.
Prerequisites
First you obviously need a CentOS server. My preferred provider is Hetzner due to them being based in Europe and offering competitive prices. For my small server I chose a 3 vcore 4gb Ram machine.
We'll also need EPEL to install the latest version of java on CentOS.
Since the Minecraft Server doesn't need a graphical user interface, we can install the headless version of the openjdk.
For editing the config files I like to use vim, but you can substitute that with your favourite text editor such as nano.
Create the minecraft user
We don't want to run the minecraft server as root for security reasons. Let's create a new user and group minecraft
with home directory /opt/minecraft
:
We are not going to set a password for this user. This is good security practice because this user will not be able to login via SSH. To change to the minecraft user you'll need to be logged in to the server as root or user with sudo privileges.
Switch to the minecraft user:
First we're going to make some folders. Make sure you're in the home folder (/opt/minecraft
in our case).
Download the server.jar
Vanilla minecraft versions can be found here. Browse to your preferred version and right click the Download Server Jar
button. Choose to copy the link.
For this tutorial I'm going to use Minecraft 1.18.2
If you want to run a modded server, you're going to need the Forge version of the server. Find your preferred version of Forge here and copy the download link.
Remove the leading https://adfoc.us/serve/sitelinks/?id=271228&url=
ad tracker from the link.
For this tutorial I'm going to use Forge 1.18.2
Configure the server
First try starting the server. Modify the Xmx and Xms flags according to your server resources. The Xmx flag defines the maximum memory allocation pool for a Java virtual machine (JVM), while Xms defines the initial memory allocation pool.
If using forge, the memory configuration is done by editing the user_jvm_args.txt
file.
You will not get far before the server asks you to accept the EULA. Shut it down and go edit eula.txt
change eula=false
to eula=true
.
Next we're going to edit the server.properties
file. Locate and edit the following lines. This is for mcrcon to work properly. You should also change the password to something stronger. While you're here, you can set whatever server properties you would like your server to have.
Running through systemd
First switch back to your root user by typing exit
.
Create a new service file:
Paste this configuration in, changing the mcrcon password to whatever you set it to be earlier:
Edit the ExecStart
to your preferred memory configuration. If running forge, change it to /opt/minecraft/server/run.sh nogui
Start the service and enable it to start on boot.
You can see the status of your server by typing:
Or if you want to follow the logs:
mcrcon
mcrcon is console based Minecraft rcon client for remote administration and server maintenance scripts. We're going to install it system wide.
Install the building tools:
Compile and install mcrcon:
Test that everything works. This should output the mcrcon help.
Configuring daily backups
Start by switching to the minecraft user:
Create a backup script in the scripts folder we created.
Paste the following configuration, and change the rcon password to whatever you set it to earlier:
Make the script executable:
Edit your crontab:
Paste in the following. We'll run the backup every day at 6am.
Using mcrcon manually
To issue commands to the minecraft console:
You should see the following:
Instead of typing this manually, you should create an alias:
To make this persist, add it to the end of your .bashrc
.
Adding mods and resource packs
If you want to add mods to your forge server, you can download the mod .jar
files and add them to the ~/server/mods
folder.
If you want your players to be prompted for a resource pack, add the direct download link to server.properties