Minecraft on an OpenVZ Container

My kids have recently gotten into Minecraft, which is a terrific game. However their experience with “griefers” on public servers was less than desireable. So I decided to put a private server (Minecraft world) that’s limited to a few friends.

Here my little buddies and their friends can build, ride pigs, and mine without having their stuff wrecked. I put the Minecraft server in an OpenVZ container (virtual environment) running Ubuntu-12.04. These notes assume that you’ve already got OpenVZ up and running and have Ubuntu-12.04 container up and configured.

Minecraft Server on Ubuntu-12.04 OpenVZ VE
Feb 01 2013
Specs for the OpenVZ container:
RAM: 512-MB
DiskSpace: 2G
Ideally you should have 1 to 2 Gb of RAM but 512-Mb is fine for a server that will only handle 6-7 players
Permissioning: We’ll use whitelist to limit players Install Java JRE (Java 7) You need to install Oracle Java(7). Unfortunately Java is not included in Ubuntu because of licensing issues. The easiest way to install Java and keep it updated is via a ppa: Log into your Ubuntu-12.04 container, and:

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer  

Install Minecraft Go into your VE Create directory for Minecraft server

$ sudo mkdir -p /home/mine/minecraft-server

Download the Minecraft server jar

$ cd /home/mine/minecraft_server

$ sudo wget https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar

Minecraft will not run as a daemon, so we’ll lauch it using Screen:

$ cd /home/mine/minecraft_server

$ sudo screen -dmS minecraft java -Xmx512M -Xms256M -jar minecraft_server.jar nogui  

To enter Screen: “screen -r” To detatch from Screen virtual console: CTRL+A d This OpenVZ container will only be running Minecraft, so I want to make sure that it starts when the container is started or rebooted. So we’ll create a start-up script and stick it in

/etc/rc.local. The start-up script (start-minecraft.sh):

$ sudo nano /etc/rc.local
$ cd /root
$ sudo nano start-minecraft.sh

Here’s the script:

#!/bin/sh
# # start minecraft server using Screen
cd /home/mine/minecraft-server
screen -dmS minecraft java -Xmx512M -Xms256M -jar minecraft_server.jar nogui

Save it in /root and place this script to execute in

/etc/rc.local Place this in /etc/rc.local:

/root/start-minecraft.sh
exit 0

 Done. Now we'll configure the Minecraft-server Next need to make sure that the Minecraft server can accept players from outside the LAN. So we need to open up port 25565 (default port for Minecraft) and forward it to our Ubuntu-12.04 container running Minecraft-server. Go into your router and forward port 25565 to the internal (LAN) IP address of the system (container) running Minecraft-server. To limit the server to "invite only", we'll enter the Minecraft ID of everyone who's allowed on in the 

white-list=true
white-list.txt

ops.txt

Port forward port 25565

Minecraft server properties
generator-settings=
allow-nether=true
level-name=world
enable-query=false
allow-flight=false
server-port=25565
level-type=DEFAULT
enable-rcon=false
level-seed=
server-ip=192.168.1.25
max-build-height=256
spawn-npcs=true
white-list=true
spawn-animals=true
snooper-enabled=true
hardcore=false
texture-pack=
online-mode=true
pvp=true
difficulty=1
gamemode=0
max-players=10
spawn-monsters=true
generate-structures=true
view-distance=10
spawn-protection=16
motd=Our Minecraft Server - Greetings

Check to status of Minecraft

$ ps aux
root 537 0.0 0.1 3444 880 ? Ss Feb23 0:00 SCREEN -dmS minecraft java -Xmx512M -Xms256M -jar minecraft_server.jar nogui
root 539 3.9 61.0 689596 320032 pts/0 Ssl+ Feb23 226:44 java -Xmx512M -Xms256M -jar minecraft_server.jar nogui

References: http://openvz.org/Quick_installation http://www.minecraftwiki.net/wiki/Tutorials/Setting_up_a_server http://www.minecraftforum.net/topic/420-tutorial-on-running-minecraft-on-a-dedicated-server/ http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html