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!
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!