How to install Minecraft server in a jail!

cyberjock

Moderator
Moderator
Joined
Mar 25, 2012
Messages
19,156
Thanks
1,835
#1
As every single one of my guides has been, I'll be doing a dummy's guide to Minecraft in a jail. I do 1 jail per program that way if I trash that one program and have to destroy the jail only 1 program gets lost. Jails use very little RAM and almost no CPU on their own, so there's no reason not to have this level of separation unless you just want "one jail to rule them all".

DISCLAIMER: The default values I will use for Minecraft are 512MB of RAM minimum and 1GB maximum. So worst case you will need to factor in 1 GB of RAM for your minecraft server. Be mindful of how much RAM you allocate to Minecraft as assigning it too much will hurt your system performance and possibly cause out of memory conditions. In short, you should NOT be trying to run minecraft on a system with less than 8GB of RAM + the maximum value permitted for Minecraft(9GB of RAM with the default settings). Do not come crying to me if you cause a low RAM condition and corrupt your zpool. You have been warned.

This guide is written with the assumption that you can barely drink water or wipe your own butt. It's dead simple and should work for almost anyone. My base system is FreeNAS 9.2, but should work just about anywhere.

I put my jails in /mnt/tank/jails. Since I have shared out my CIFS shares to /mnt/tank I can access anything inside my jail from my CIFS share. For example, if a file is located in /usr/local/etc/rc.d in the jail I simply have to go to my network share drive and open up /jails/minecraftserver/usr/local/etc/rc.d. We will have to do a little permissions fixing, but I find this easier than editing files with nano or ftping files. You probably will too!

There are custom scripts that take care of things, so don't try to change anything or you might not have a working minecraft server!

WARNING: If you edit a file that is in-use you may cause problems with your jail. Consider shutting down your jail when you want to edit files unless you are sure the file isn't in-use.

1. Create the jail.

I will assume you've already created jails before and are familiar with the FreeNAS GUI.

Click the "jails" button in the FreeNAS WebGUI. Fill in the following(mine is included below):

Jail Name: minecraftserver
type: portjail
IPv4address: 192.168.2.128 (put in whatever address is applicable to you)
ipv4 netmask: /24 (255.255.255.0) (put in whatever is applicable to you)
MAC: leave it at whatever it is.
Autostart: checked
VIMAGE: not checked
NAT: not checked
vanilla: not checked

2. Install the necessary packages

Go into the jail using jls/jexec and as root and run the following command:

# pkg install openjdk screen

There will be extra dependencies that need to be installed. Accept them. Should take about 2 minutes to download and install everything.


Optional: (these might be nice to have if you want to edit files with nano and go back and forth from root and the minecraft user)

# pkg install nano sudo

3. Create the folder structure you need.

From inside the jail again and as root run the following commands:

# mkdir /srv
# mkdir /srv/minecraft

4. Create our minecraft user.

From inside the jail still, run the following command:

# adduser

Complete the fields as follows:

Username: minecraft
Full name: (Put whatever you want here)
Uid: (hit enter)
Login group: (hit enter)
Login group is minecraft. Invite minecraft into other groups?: (hit enter)
Login class: (hit enter)
Shell: csh (you can use whatever you want, I like csh)
Home directory: (hit enter)
Use password-based authentication? : yes
Use an empty password?: no
Use a random password?: no
Enter password: Put in a password you want to use. If you are going to let friends administer your server you might want something you can give them.
Enter password again: You know what to do here...
Lock out the account after creation?: no
OK? if everything is correct, type "yes". if not type "no" and redo it.
Add another user? (yes/no): no

You will probably want to set a password for your root user. If you do, then:

# passwd

5. Stop the jail.

Go into the FreeNAS WebGUI and stop the jail.

6. Installing Minecraft files

Download the attached file on this post from here to your desktop. Included is Minecraft Server 1.7.4. If it is not the latest version or you want to download it yourself feel free feel free to. You will still need the other files I included however, so download it anyway.

Extract the minecraft jar file. This is a java file and basically is the minecraft server itself. The current version as of this writing is 1.7.4. Download the jar file and place it in your jail under /srv/minecraft. Also rename it from "minecraft_server.1.7.4.jar" to "minecraft_server.jar".

You will find an sshd_config file in the attached file also. This will need to be placed in /etc/ssh. Notice that if you have already setup sshd for the jail you won't want to overwrite your current build. If you are using a brand new jail like me, simply overwrite the file included with the one that the system has by default.

NOTE: If you are trying to use something like bukkit you will need to put the bukkit.jar in the /srv/minecraft folder as well. All Minecraft files will always be found in /srv/minecraft.

Protip: In the future, if a new version of minecraft comes out, all you will have to do is stop the jail and replace the current minecraft_server.jar with whatever the new version is. If you have an update for an addon such as bukkit, the same applies. Simply replace the old bukkit.jar with the new one.

Next you will need to install 2 files I've created with serious help of a friend(thanks dteske!). These are custom scripts created just for minecraft.

mcwatchdog is a script that checks to see if minecraft is running every 60 seconds. In the event that your server crashes, mcwatchdog will automatically restart the minecraft service within 60 seconds.

minecraft is the file that will actually starts the Minecraft server jar file in java. Place both mcwatchdog and minecraft(not the minecraft_server.jar file!) in your jail under /usr/local/etc/rc.d. They should not have a file extension on them, so don't add one.

7. Bootup the jail and do some setup.

Bootup the jail. Then using jls/jexec log back into your jail as the root user.

Now type all of the following commands:

# chmod +x /usr/local/etc/rc.d/mcwatchdog
# chmod +x /usr/local/etc/rc.d/minecraft
# chgrp -R wheel /usr/local/etc/rc.d
# chmod -R 777 /srv
# chown -R root /srv
# chgrp -R minecraft /srv
# sysrc mcwatchdog_enable=YES
# sysrc minecraft_enable=YES
# sysrc sshd_enable=YES

8. Now to see if all of this stuff works!

From inside your jail as root again, run the following.

# service sshd start
# service mcwatchdog start

And if everything is okay you should be able to log into your server now!

As a good measure to make sure you did everything right you should probably stop the jail, then start the jail again to see if the Minecraft server service starts up. It seems to take 5-10 seconds after you click the start button on the jail for you to be able to access the server.


9. How to admin the Minecraft server

If you are used to administrating your Minecraft server from the command line(/achievement, etc.) you are going to want access to it. Here's how you get access:

Using your favorite ssh program, go to the IP address of your Minecraft server. Login with your username "minecraft" and the applicable password. Now type:

# screen -x.

This will drop you directly into the Minecraft server. If you hit CTRL+C when you are done in the Minecraft server it will actually quit the Minecraft server. Have no fear as it will restart within 60 seconds! Your best bet though is to simply close your ssh program when you are done administering the server.

10. RAM settings

The server default is to use 512MB of RAM minimum and 1GB maximum. If you have a large number of users or a large server you may need more. Remember that any RAM you allocate to Minecraft will be taken from FreeNAS. So if you plan to run more than just a few users and a small server you will need to allocate more RAM. Again, read the disclaimer above and keep in mind you should have 8GB of RAM for FreeNAS minimum at all times + whatever maximum value you allocate to Minecraft.

Here's the various things you may need to change with the included defaults. Change these at your own risk!

minecraft_java_opts="-Xms512M -Xmx1024M" This sets the minimum RAM of 512MB and the maximum RAM of 1024MB. You must always include both a minimum and maximum with this parameter. For example, if you wanted to set the minimum RAM to 1GB and maximum to 2GB you would type:

# sysrc minecraft_java_opts="-Xms1G -Xmx2G"

You will to restart the server after making this change. To do that type:

# service minecraft stop

The server will automatically restart within 60 seconds.

NOTE: If you have other java arguments that you want to have passed along you would add them to the minecraft_java_opts parameter.


11. The fabled server.properties

The fabled server.properties file can be found in /srv/minecraft inside your jail. To change/add/delete settings you should stop your jail, make your changes, then start the jail. Optionally you can choose to stop and start the mcwatchdog and minecraft services(in that order!). But stopping the jail is safer, easier, and faster, so do that unless you can't stop the jail for some other reason.

12. Addons

(I have edited this section since first writing it. It should be better written, and accurate!)

If you are a die hard Minecrafter you'll probably want to use things like bukkit. To install them you will need to stop the Minecraft server, install bukkit, make a settings change, then start your Minecraft server. Here's what you need to do:

Stop your jail.

Delete your current minecraft_server.jar file.

Rename your bukkit jar to minecraft_server.jar.

Copy your new minecraft_server.jar file to /srv/minecraft.

Start your jail.

13. Network access

How you choose to setup your server is totally up to you, and it is far beyond the scope of this forum and this guide to provide instructions on how you can accomplish this task over the internet. Do not ask how to do this as I will delete any and all posts asking about it.


14. Updating

Minecraft will have updates that you will want to install from time to time. To install them you simply stop the jail, overwrite the /srv/minecraft/minecraft_server.jar with whatever the new version is(remember to rename the new version appropriately!) and then start the jail again.

If you want to update packages you've installed in this jail, you simply need to do:

# service mcwatchdog stop
# service minecraft stop
# pkg update
# pkg upgrade
# service mcwatchdog start


Thanks go out to Matt Olander (iXsystems guy) for the free copy of Minecraft so I could bring you this great guide and thanks to dteske for help with the scripts!
 

Attachments

cyberjock

Moderator
Moderator
Joined
Mar 25, 2012
Messages
19,156
Thanks
1,835
#2
Reserved.
 

cyberjock

Moderator
Moderator
Joined
Mar 25, 2012
Messages
19,156
Thanks
1,835
#3
Reserved.
 
Joined
Dec 11, 2013
Messages
21
Thanks
1
#5
Thank you!!! I have minecraft server on ubuntu jail, but only 1.6.4 version because of java netty problems. Thank you for your guide. I'll try it.
 
Joined
Dec 9, 2013
Messages
51
Thanks
0
#6
Just went through the guide and got a server up and running! :) I actually managed to get my 17 year old brother to do most of it, so it's pretty foolproof.

We did run into a bit of trouble with the jls/jexec parts however, having never used these commands, but found my way thought it. the 'jls' command will list your installed jails, and puts a number prefix next to them. I got the jexec command to work by typing 'jexec 4 su' where 4 is the minecraftserver jid, and su to log in as root. My prompt then looked like this: root@minecraftserver:/ #

We also had a trouble with the sysrc command, which I apparently didn't have installed, but that was easily solved with this command: pkg install sysrc

Me and my brothers can't wait to start messing around with it! ty cyberjock for this excellent guide.
 
Joined
Dec 27, 2013
Messages
92
Thanks
2
#7
Thanks for sharing this cyberdog! My son has been asking me to set a minecraft server... but first I must figure out how to set up basic shares....it is giving me a hard time between windos and mac units!! arrg
 
Joined
Oct 8, 2013
Messages
51
Thanks
6
#8
I haven't tried this yet, but I'm getting there. Thanks a lot for this as this is the last key in retiring my Win8 based server for my FreeNAS one!

Fish
 
Joined
Oct 8, 2013
Messages
51
Thanks
6
#9
Not working for me (but not for a lack of a great step-by-step). Think it may be a permission thing, but I get a java connection exception that it is refused. That tells me that the server is running (if I type in some random IP address is just sits there) but that I can't access it. I didn't get any obvious errors when in the cli, so not sure. Any ideas?
Thanks,
Fish
 
Joined
Dec 27, 2013
Messages
92
Thanks
2
#10
Good stuff! Let us know if you get it to work. I am going to try this once I get my CIFs shares under control. I see them but I can't write to them!
 
Joined
Dec 9, 2013
Messages
51
Thanks
0
#11
I have managed to murder the server a few times (including what sounds like the same issue as cmfisher4) by tampering with it, and I find that the best policy is to delete the jail and start from scratch to get it working again, as the guide only takes 5-10 minutes to run through, particularly when copy/pasting the commands. Just remember to backup your worlds!
 
Joined
Dec 27, 2013
Messages
92
Thanks
2
#12
Thanks for sharing that tip!!
 
Joined
Feb 10, 2014
Messages
7
Thanks
4
#13
# service mcwatchdog stop
# service minecraft stop
# sysrc minecraft_path="/srv/minecraft/bukkit.jar"
# service mcwatchdog start

That part had me a bit confused. I actually did it a different way. I downloaded the CraftBukkit server:
http://dl.bukkit.org/

I had to get the beta build because newer clients are incompatible with the recommended build... so it looked something like this...
# cd /srv/minecraft
#wget http://dl.bukkit.org/latest-beta/craftbukkit-beta.jar
# nano /usr/local/etc/rc.d/minecraft

then I changed
: ${minecraft_path="/srv/minecraft/minecraft_server.jar"}

to
: ${minecraft_path="/srv/minecraft/craftbukkit-beta.jar"}

Restarted the jail and Craftbukkit was running.

Awesome tutorial. Really helped a ton. Although, I don't see the need to stop the jail in the section where you stopped it. I simply did all the work then started the service. After I confirmed it worked I restarted the jail to make sure it automatically started. Worked like a charm.
 
Joined
Feb 15, 2014
Messages
12
Thanks
0
#14
Thanks for the tutorial! It was really easy to follow and help me out a lot.
At least until the part when you install the minecraft server files. I don't have access to put anything in /srv/minecraft. Please help, I am new to freeNAS and jails aren't my strongest point. Otherwise thanks for this.
 

cyberjock

Moderator
Moderator
Joined
Mar 25, 2012
Messages
19,156
Thanks
1,835
#15
I'd recommend you either setup FTP, CIFS, NFS or even do it via the CLI. The choice is yours. How you choose to do it is beyond the scope of this guide as setting up shares should be second nature since anyone setting up FreeNAS is doing it solely for sharing files.
 
Joined
Feb 15, 2014
Messages
12
Thanks
0
#16
Thanks, I'm using an AFP share and i just don't have permission to put anything in there. Ill try with a CIFS share on windows and see how it goes.
 
Joined
Apr 3, 2013
Messages
11
Thanks
0
#17
I'm getting an error when I'm in the jail and run any of the pkg commands. I get "updating repository catalogue. No valid repository found."
 

cyberjock

Moderator
Moderator
Joined
Mar 25, 2012
Messages
19,156
Thanks
1,835
#18
I'm getting an error when I'm in the jail and run any of the pkg commands. I get "updating repository catalogue. No valid repository found."
What FreeNAS version are you using?
 
Joined
Apr 3, 2013
Messages
11
Thanks
0
#19
9.2.1. As soon as I run the pkg install openjdk screen:
The package management tool is not yet installed on your system. Do you want to fetch and install it now? [y/N]:
Then when I hit yes. I tried to run that same command again, but all i get is that the there is no valid repository found. Does this have to do with pkgng? Im not really familiar with it.
 

cyberjock

Moderator
Moderator
Joined
Mar 25, 2012
Messages
19,156
Thanks
1,835
#20
9.2.1. As soon as I run the pkg install openjdk screen:
The package management tool is not yet installed on your system. Do you want to fetch and install it now? [y/N]:
Then when I hit yes. I tried to run that same command again, but all i get is that the there is no valid repository found. Does this have to do with pkgng? Im not really familiar with it.
That's a well known problem with 9.2.1. There's a bug ticket in for it. My advice is to wait for a fix to come or go back to 9.2.0. 9.2.1 is a total mess, which is why I never ever upgrade to the "latest" version until a month or so has passed. Let the other suckers deal with the problems. Sorry, but today you are the sucker. ;)
 
Top