Tutorials

Setup Minecraft Servers on CentOS

1) Create your host machine and provision the setup with required RAM and CPU resources.

2) Once your server is updated and configured the way you like, there will be the need to install java and screen so that we can run the minecraft server.

$ sudo yum install screen java -y

3) Download the latest version (or your desired version) of the Minecraft server. The download page is located here: https://minecraft.net/download

$ wget https://s3.amazonaws.com/Minecraft.Download/versions/*****/minecraft_server.******.jar

4) Run the server for the first time so that it creates the eula.txt. You can use CTRL+C to close out of it.

$ java minecraft_server.*********.jar

5) Accept the EULA agreement by editing the eula.txt file and changing the false to true on Line 3 of the eula.txt file.

6) Run the server a second time and let it generate some default terrain and spawn areas. This will also create the server.properties file as well as the whitelist.json, ops.json, and default banned-players.json.

7) Once the set up is completed, close the server out by simultaneously pressing CTRL+C on your keyboard or typing stop into the console of the Minecraft server.

8) Edit the server.properties and other configuration files to your liking.

9) Create a startup script.

$ touch startserver.sh

Contents of startserver.sh:

#!/bin/bash
clear
echo -e "Starting Minecraft Server in 3 seconds.."
sleep 3
screen -A -m -d -S minecraftserver java -Xmx1024M -Xms1024M -jar /path/to/minecraft_server.1.8.1.jar nogui

Do not forget that you can edit the 1024M to account for how much RAM you want to provide to the Minecraft server.

  • 1024M for 1G of RAM
  • 2048M for 2G of RAM
  • 4096M for 4G of RAM
  • etc..

10) Make the start script executable:

$ chmod +x startserver.sh

11) If you are using IPTables firewall, do not forget to add the Minecraft server's port to the firewall to allow connections. The default port for Minecraft is 25565:

$ sudo iptables -I INPUT -p tcp --dport 25565 -j ACCEPT
$ sudo service iptables save

12) Now you can start your server by running the start script. This will run the Minecraft server in a screen session in the background.

It is advisable to run the Minecraft server as a different user and not the root user.

 
  • I like how you used screen to run minecraft. I have done something similar except I didn't want it to run under root so I created a new user mcuser, and used this command to run minecraft as that user: sudo -u mcuser screen -mdS minecraftserver java -Xmx1024M -Xms1024M -jar /etc/minecraft/minecraft_server.1.8.9.jar nogui

    Now that starts the process in a detached screen. So to get to view the screen and keep your shell open and open another screen attached under the mcuser screen, here's how:

    screen

    ctrl+a - c <--- create new screen

    sudo -u mcuser screen -r <---connect the newly created screen to screen running under mcuser

    ctrl+a - n <---- switch between root and minecraft screens

    Took a bit to figure out as I had never used screen before but it works nicely. Now I'm trying this script to make minecraft run at boot: http://minecraft.gamepedia.com/Tutorials/Server_startup_script

Log In, Add a Comment