Which boy doesn't want to have a Minecraft server?
System#
The Minecraft server is written in Java and can run on multiple platforms, so you can use various Linux distributions or even Windows to host the server. However, it is not recommended to use Windows for server hosting in order to ensure stable operation.
This article uses Debian 10 as the server system, but the methods for other systems are similar.
Install Java Runtime Environment#
Installing Java environment on Debian is very convenient, just use apt to install it.
apt install default-jre
Download Paper Server#
Minecraft has an official server, and of course, there are many third-party servers as well. Here, I chose the Paper server.
You can download the Paper server directly from their official website: papermc.io/downloads
After downloading, use scp to upload the jar file to the server.
Create a Running User#
For server security, you need to create a dedicated user for running the Paper server:
adduser minecraft
Move the Paper server to /opt/minecraft
and assign user permissions:
mv /path/to/paper.jar /opt/minecraft/paper.jar
chown -R minecraft:minecraft /opt/minecraft
Initial Run#
Use the following command to run the server:
java -Xmx4G -Xms2G -jar paper.jar nogui
The first time you run the server, you will be prompted to agree to the EULA. Open eula.txt
and change eula
to true
.
Create systemd Service#
As a Minecraft server, the Paper server needs to run 24 hours a day. To facilitate management, we will use systemd.
First, install the required software:
apt install screen
Create the /lib/systemd/system/minecraft.service
file with the following content. Note that you need to modify the corresponding directories, server files, and memory usage:
# From: https://minecraft.gamepedia.com/Tutorials/Server_startup_script
[Unit]
Description=Minecraft Server
After=network.target
[Service]
WorkingDirectory=/opt/minecraft
PrivateUsers=true
User=minecraft
Group=minecraft
ProtectSystem=full
ProtectHome=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
ExecStart=/bin/sh -c '/usr/bin/screen -DmS minecraft /usr/bin/java -server -XX:+UseCompressedOops -Xss256k -XX:ParallelGCThreads=16 -Xms3G -Xmx5G -jar paper.jar'
ExecReload=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "reload"\\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "save-all"\\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "stop"\\015'
ExecStop=/bin/sleep 10
Restart=on-failure
RestartSec=60s
[Install]
WantedBy=multi-user.target
Now you can use systemd to manage the Paper server:
systemctl enable minecraft.service
systemctl start minecraft.service