Set-up your own MineCraft server on FreeBSD 10.1

My daughter (Ruby) has been bugging me to get her MineCraft and so I thought I’d set her up with her own server that we could both play on together so I thought I’d compile this blog post as a quick tutorial on how to set up a MineCraft server on FreeBSD 10.1, hopefully others will find this tutorial will useful and easy to follow!

If you don’t already have a server, you can go rent one from DigitalOcean, they’re $5 a month and I could not recommend them enough, the server’s from DigitalOcean all come with SSD’s as standard and run Minecraft servers perfectly! If you need one, go get one now and then carry on with this tutorial!

Installing the server

Firstly ensure that you have a FreeBSD 10.1 server setup and ready to go, lets
first setup a couple of packages that we will need:

pkg install screen nano wget

Next we’ll install the OpenJDK, you may wish to use the Oracle JDK but I’m not
covering that in this post, so lets install the OpenJDK like so:

pkg install java/openjdk7

Fantastic! – Lets just check that it is installed correctly by checking the version
number like so:

java -version

As long as you see some OpenJDK Runtime information then it’s looking good, we can move on!

Lets now download MineCraft to our server and put it into a seperate directory
in case we wish to run more than one game server on our server 🙂

cd ~
mkdir minecraft_server_1
cd minecraft_server_1
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.8.4/minecraft_server.1.8.4.jar --no-check-certificate

So now we have a folder in our home directory called ‘minecraft_server_1’ and in their we have the main Minecraft server application.

Now we have to accept the EULA, simply run this command to ‘accept’ it

echo "eula=true" > eula.txt

Now we create the main start-up script for this server, run this:

echo "java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.4.jar nogui" > startup.sh

Now we’ll create a new user on the server named ‘minecraft’ this user will be used for running all our Minecraft server instances, create the new user using this command:

adduser minecraft

Then lets update the file ownership like so:

chown -R minecraft:minecraft .

You can now start your server by running:

screen su -m minecraft -c "sh startup.sh"

If you wish to run multiple servers, you can add a server-port=XXXX setting to the server.properties file to enable you to run multiple game servers on the save physical server.

Congratulation, you should now be able to access your new Minecraft server running on the awesomely stable FreeBSD OS!

Using Supervisor to automatically start and keep your MineCraft server running

I noticed after a couple of days that every now and again the MineCraft server was crashing whilst no one was connected to it and mean’t that I had to log into the server via. SSH and re-start it.

I’ve used Supervisord in the past and seems like a good idea in this sitaution also, the result will be that if the server reboots or the game server crashes Supervisor will restart the Minecraft server for us automatically…

So lets install it now:

sudo pkg install py27-supervisor

Now we need to enable it by adding it to the rc.conf file, do it using the following command:

sudo sh -c 'echo supervisord_enable=\"YES\" >> /etc/rc.conf'

Now we have to add our Minecraft server configuration to the supervisor.conf file so that Supervisor knows what it needs to execute and handle the task etc.

So, edit /usr/local/etc/supervisord.conf and add the following content (obviously make path changes as required):

[program:minecraft_server_1]
command=/usr/local/openjdk7/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.4.jar nogui
directory=/root/minecraft_server_1
user=minecraft
autostart=true
autorestart=true
stdout_logfile=/root/supervisor_logs/minecraft_server_1/stdout.log
stderr_logfile=/root/supervisor_logs/minecraft_server_1/stderr.log

Now lets just create our supervisor logs directory like so:

mkdir -p /root/supervisor_logs/minecraft_server_1/

Excellent, now lets start the service like so:

service supervisord start

That’s great, your Minecraft server should now be running and is managed via. Supervisor!

So in future you can check the status of your Minecraft server(s) using supervisorctl tool like so:

supervisorctl

You can start, stop and restart your Minecraft servers using:

stop minecraft_server_1
start minecraft_server_1
restart minecraft_server_1

Have fun and hope this was helpful!

Share