This article shows how to run a Minecraft server on CentOS or Redhat 7. We’re going to download Minecraft, put it in the right place, open the right firewall ports, start Minecraft with sensible settings and run it in a state that we can change things later without having to restart the Minecraft server.
Start out as the “root” user. Don’t worry, we’ll be running Minecraft as a non-root user for security reasons.
Create the directory to place the Minecraft java program:
mkdir /opt/minecraft cd /opt/minecraft
Download the Minecraft and put it in the right location. Note that your version might be different to mine:
wget -O minecraft_server.jar https://s3.amazonaws.com/Minecraft.Download/versions/1.7.4/minecraft_server.1.7.4.jar
Start the Minecraft server just to test that everything is working:
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Just “Control+C” to cancel the java program. Now let’s set the ownership of the Minecraft files:
chown games.games -R /opt/minecraft
Configure the firewall to permit port “” by editing the “/etc/sysconfig/iptables” file. Add the following line to the appropriate place. If you’re using Firewalld, you have to do this differently.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25565 -j ACCEPT
Note: You can specify the “-s” option in the above IPTables command to restrict from where clients can connect. For example, suppose you only wanted kids at a school to access “this” minecraft server and your schools public IP address is “188.8.131.52”:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25565 -s 184.108.40.206 -j ACCEPT
systemctl restart iptables
Now edit the “server.properties” file in the “/opt/minecraft” directory. This is the properties that the Minecraft server uses.
See "http://minecraft.gamepedia.com/Server.properties" for details.
Finally start Minecraft. You can do this using the following command:
cd /opt/minecraft nohup sudo -H -u games java -Xmx1024M -Xms1024M -jar minecraft_server.1.11.2.jar nogui &
But the above is not cool for two reasons. a) it’s running as the root user, and b) once it’s running, you can change settings for the server without restarting it. Side note: This is a silly thing about Minecraft. If you want to make changes to the running server, you need to have access to the command line on which you executed the command. It would have been nicer to allow an administrative network port. Never mind.
This is how to start it in a “screen” and run it as the “games” user:
screen [enter] sudo -H -u games java -Xmx1024M -Xms1024M -jar minecraft_server.1.11.2.jar nogui [enter] Control+a [enter] d [enter] exit [enter]
At this point you have a running Minecraft server and you can close down your SSH session to the Linux server. You can get back to the Minecraft terminal (where you can run commands that change the way the Minecraft server runs) using the following:
Learn more about “screen” here “https://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/”.
The image used in this article is from “https://mojang.com/category/minecraft/”.