Introduction
This 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 players
If 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:
[
{
"uuid": "abcdef12-3456-7891-2345-67890abcdef1",
"name": "Player1Name"
},
{
"uuid": "abcdef12-3456-7891-2345-67890abcdef2",
"name": "Player2Name"
},
{
"uuid": "abcdef12-3456-7891-2345-67890abcdef3",
"name": "Player3Name"
},
{
"uuid": "abcdef12-3456-7891-2345-67890abcdef4",
"name": "Player4Name"
}
]
OPs
Similarly, add a list of players that you want to be OPs on the server by creating ops.json.[
{
"uuid": "abcdef12-3456-7891-2345-67890abcdef1",
"name": "Player1Name",
"level": 4,
"bypassesPlayerLimit": false
},
{
"uuid": "abcdef12-3456-7891-2345-67890abcdef2",
"name": "Player2Name",
"level": 4,
"bypassesPlayerLimit": false
}
]
Copy an old world
Optionally, 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 line
Run 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
vim eula.txt
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 service
Create 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:
[Unit]
Description=Minecraft Server
After=syslog.target network.target
[Service]
Type=simple
User=minecraft
Group=minecraft
WorkingDirectory=/home/minecraft
ExecStart=/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Restart=on-failure
[Install]
WantedBy=multi-user.target
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.
Happy Crafting!