IntroductionThis document guides you through setting up a Minecraft server on Centos 8. After installing Centos, get some basic packages:
sudo dnf -y install java-latest-openjdk.x86_64 wget vim nano screen
Add a minecraft user for the service to run as:
sudo useradd minecraft
Don't set a password - this user should not be able to log in
Change to the user:
sudo su - minecraft
Download the server from https://minecraft.net/en-us/download/server :
wget -c https://minecraft.net/en-us/download/server
This file will appear as minecraft_server.jar, so rename it (changing the version to the ACTUAL version):
mv server.jar minecraft_server_1.15.2.jar
Create a symbolic link. This will make the service easier to maintain when you up/downgrade Minecraft.
ln -s minecraft_server_1.15.2.jar minecraft_server.jar
Whitelist playersIf you want to restrict who can join your server, you will need their player IDs and their UUIDs. The UUID can be found here: https://mcuuid.net/
Create a file: whitelist.json. The contents should look like this:
OPsSimilarly, add a list of players that you want to be OPs on the server by creating ops.json.
Copy an old worldOptionally, and before starting your Minecraft server, you may wish to copy an old world to a world folder in the same directory.
Test you can run at the command lineRun the server using:
java -Xmx4096M -Xms2048M -XX:ParallelGCThreads=1 -jar minecraft_server.jar nogui
Ensure you have the settings right - correct any issues that you discover. One will probably be that you will need to edit eula.txt, changing false to true
Keep correcting any issues until you can run Minecraft.
To make sure that all is well with firewall rules etc, start the Minecraft game on your Laptop/desktop choose multiplayer and connect to the IP address of your server.
Now that the difficult bit is done, let's make sure the Minecraft server will start when the Linux server starts.
Add the Minecraft serviceCreate a new service unit file at /etc/systemd/system/sample.service with below content:
sudo vim /etc/systemd/system/minecraft.service
and paste the content:
ExecStart=/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
1. Reload the systemd process to consider newly created minecraft.service OR every time when minecraft.service gets modified.
sudo systemctl daemon-reload
2. Enable this service to start after reboot automatically.
sudo systemctl enable minecraft.service
3. Start the service.
sudo systemctl start minecraft.service
4. Reboot the host to verify whether the scripts are starting as expected during system boot.
sudo systemctl reboot
Test it's all working
After rebooting, you and your friends should be able to connect to the server.