Introduction
One fairly common use of Linux VPS boxes is the running of Minecraft servers. In this tutorial, we will cover the basics of installing an optimised server, called Spigot, and getting automatic start-up on server boot.
Installing Java & Screen
The first step is to install Java. If you know you already have java installed, then you can skip this. Otherwise, run the following:
1 2 |
sudo apt-get update sudo apt-get install openjdk-7-jre |
The majority of server distributions come with screen installed by default, but if not, you can run the following to install it:
1 |
Sudo apt-get install screen |
Fetching Spigot
Then, navigate to the directory where you want your server to be. For the purposes of this, we will use /usr/local/minecraft_server
You first need to create the directory as below
1 2 |
mkdir /usr/local/minecraft_server cd /usr/local/minecraft_server |
Now it’s time to fetch the Spigot server file. You can find the different versions at http://ci.md-5.net/job/Spigot/ and you’ll need to find a stable build that corresponds to the minecraft version you want to use.
Once you’ve found this, copy the URL and run the following on the server:
1 |
wget -O /usr/local/minecraft_server/spigot.jar [URL here] |
This will save the file as spigot.jar.
Testing Server
Next, we need to decide how much RAM to allocate for the server. In general, 512MB is more than enough for a small server with few plugins. If you encounter issues with running out of memory, you can try running with more.
Hence to start the server, we would run:
1 |
java -jar -Xmx512M spigot.jar |
You can adjust the 512M value as you wish.
You can now type “stop” to stop the server. Doing this all the time would require manual starting and stopping of the server, which isn’t ideal. Hence, we will add a script to /etc/init.d/ to handle this.
Making the server run on startup and stop on shutdown
Run the following to create the script:
1 |
nano /etc/init.d/minecraft_server |
And paste in the following:
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 |
#!/bin/sh ### BEGIN INIT INFO # # Provides: minecraft_server # Required-Start: $remote_fs # Required-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Minecraft server # Description: Used to start minecraft server in screen session # ### END INIT INFO case "$1" in start) echo "Starting minecraft server" cd /usr/local/minecraft_server/ screen -dmS "minecraft_server" java -Xmx512M -jar spigot.jar ;; stop) echo "Stopping minecraft server" screen -S minecraft_server -p 0 -X stuff "`printf \"stop\r\"`" ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0 |
Then make the file executable by running:
1 |
chmod +x |
And finally add it to the startup and shutdown like so:
1 |
update-rc.d minecraft_server defaults |
Hence, to start your minecraft server you can now run
1 |
service minecraft_server start |
To stop the server, run
1 |
service minecraft_server stop |
It will also automatically shut down on server shutdown, but it’s better to do this yourself, as you can then be sure it has saved and that it will not hang, delaying the shutdown, which can cause problems with some hosts.
This script starts the server in a program called screen. This essentially creates another terminal window, so if you wish to check out the output from your server or enter a command, you need to type :
1 |
screen -r minecraft_server |
You can then disconnect from this by pressing Control-A then Control-D and safely log out – the server will continue running in the background.
If you can’t connect and you have iptables set up you may need to run the following:
1 |
iptables -I INPUT -p tcp -m tcp --dport 25565 -j ACCEPT |
3 comments for “Installing your own Minecraft server (Spigot)”