Home / Community / Blog

Thin installation was tested on CentOS 7 nad CentOS 8

Prepare system

You will need java:

yum install java-1.8.0-openjdk-headless

Create dedicated user

useradd --system --create-home --user-group \
--home-dir /opt/minecraft --shell /bin/bash minecraft

or shorter

useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft

Configure firewall

Create new service mincecraft-server file:

cat << EOF > /etc/firewalld/services/minecraft-server.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Minecraft server</short>
  <port port="25565" protocol="tcp"/>
  <port port="25575" protocol="tcp"/>
</service>
EOF

Then reload to read new service, enable it and reload to apply changes.

firewall-cmd --reload
firewall-cmd --add-service=minecraft-server --permanent
firewall-cmd --reload

Prepare directories

su - minecraft
mkdir -p ~/{backups,tools}
mkdir server-1.12.2
mkdir server-1.15.2

Download JAR files

I'm preparing two versions: 1.12.2 and 1.15.2:

cd ~/server-1.15.2
wget "https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar" -O minecraft_server.1.15.2.jar
ln -s minecraft_server.1.15.2.jar server.jar
echo eula=true > eula.txt
cd ~/server-1.12.2
wget https://launcher.mojang.com/mc/game/1.12.2/server/886945bfb2b978778c3a0288fd7fab09d315b25f/server.jar -O minecraft_server-1.12.2.jar
ln -s minecraft_server-1.12.2.jar server.jar
echo eula=true > eula.txt

Now you have to chose one. In my example 1.12.2:

cd
ln -s server-1.12.2 server

later you can remove this link and create it to another version, ie:

cd
rm server
ln -s server-1.15.2 server

Configure RCON

Not necessary. Run all command as a "root" user.

Install packages
yum group install "Development Tools"
yum install kernel-debug
Download and compile
wget https://github.com/Tiiffi/mcrcon/archive/master.zip
cd /tmp/
unzip ~/master.zip
cd mcrcon-master/
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
cp ./mcrcon /opt/minecraft/tools/
chown minecraft.minecraft /opt/minecraft/tools/mcrcon

If you want to use RCON you have to adjust /opt/minecraft/server/server.properties file:

enable-rcon=true
rcon.password=strong-password

of course change strong-password to some strong password ;-)

Startup script

Create serivce file as root:

cat << EOF > /etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=minecraft
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
ExecStop=/opt/minecraft/tools/mcrcon -H 127.0.0.1 -P 25575 -p strong-password stop


[Install]
WantedBy=multi-user.target
EOF

Run

systemctl start minecraft

You can check /opt/minecraft/server/logs/latest.log to see what is happening.

You should see something like this:

[22:09:52] [Server thread/INFO]: Starting minecraft server version 1.12.2
[22:09:52] [Server thread/INFO]: Loading properties
[22:09:52] [Server thread/WARN]: server.properties does not exist
[22:09:52] [Server thread/INFO]: Generating new properties file
[22:09:52] [Server thread/INFO]: Default game type: SURVIVAL
[22:09:52] [Server thread/INFO]: Generating keypair
[22:09:53] [Server thread/INFO]: Starting Minecraft server on *:25565
[22:09:53] [Server thread/INFO]: Using epoll channel type
[22:09:53] [Server thread/INFO]: Preparing level "world"
[22:09:54] [Server thread/INFO]: Loaded 488 advancements
[22:09:55] [Server thread/INFO]: Preparing start region for level 0
[22:09:56] [Server thread/INFO]: Preparing spawn area: 5%
[22:09:57] [Server thread/INFO]: Preparing spawn area: 8%
[22:09:58] [Server thread/INFO]: Preparing spawn area: 13%
[22:09:59] [Server thread/INFO]: Preparing spawn area: 17%
[22:10:00] [Server thread/INFO]: Preparing spawn area: 22%
[22:10:01] [Server thread/INFO]: Preparing spawn area: 28%
[22:10:02] [Server thread/INFO]: Preparing spawn area: 32%
[22:10:03] [Server thread/INFO]: Preparing spawn area: 37%
[22:10:04] [Server thread/INFO]: Preparing spawn area: 42%
[22:10:05] [Server thread/INFO]: Preparing spawn area: 48%
[22:10:06] [Server thread/INFO]: Preparing spawn area: 53%
[22:10:07] [Server thread/INFO]: Preparing spawn area: 59%
[22:10:08] [Server thread/INFO]: Preparing spawn area: 65%
[22:10:09] [Server thread/INFO]: Preparing spawn area: 70%
[22:10:11] [Server thread/INFO]: Preparing spawn area: 75%
[22:10:12] [Server thread/INFO]: Preparing spawn area: 80%
[22:10:13] [Server thread/INFO]: Preparing spawn area: 86%
[22:10:14] [Server thread/INFO]: Preparing spawn area: 90%
[22:10:15] [Server thread/INFO]: Preparing spawn area: 96%
[22:10:15] [Server thread/INFO]: Done (22.459s)! For help, type "help" or "?"

As you can see first start took more than 22s (not to bad - it's Core 2 Duo and iSCSI disk on 1GB network card - CentOS 8 version of Diskless computer using PXE and iSCSI)

Configure autostart

If you want to start Minecraf server automatically when system starts, just enable this service:

systemctl enable minecraft

That's all.

Just my blog...

Mon Tue Wed Thu Fri Sat Sun
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31