Ubuntu Linux - Minecraft Server Installation

Aus Laub-Home Wiki

Hier ein kleines HowTo um Minecraft Server auf einem Ubuntu Linux 11.04 Server zum laufen zu bringen.

Vorbereitungen

Zuerst muss Java Runtime Environment installiert werden. Dazu muss als erstes in der Datei /etc/apt/sources.list Das Partner Repository aktiviert werden:

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
deb http://archive.canonical.com/ubuntu natty partner
deb-src http://archive.canonical.com/ubuntu natty partner

nun kann es installiert werden

aptitude update
aptitude install sun-java6-jre

nun sollte für Minecraft ein eigener unprivilegierter User angelegt werden:

useradd -d /srv/minecraft -m -s /bin/bash minecraft
passwd -l minecraft

Installation Minecraft Server

Einfach die Minecraft Jar Datei in das Homeverzeichnis laden,

su - minecraft
wget -q -c http://ci.bukkit.org/job/dev-CraftBukkit/promotion/latest/Recommended/artifact/target/craftbukkit-0.0.1-SNAPSHOT.jar

dann den aktuellen Download auf die Standarddatei verlinken:

ln -s craftbukkit-0.0.1-SNAPSHOT.jar craftbukkit.jar

und zum schluss die Jar Datei einmal starten, damit alles angelegt und generiert wird:

java -Xmx1536M -jar craftbukkit.jar

Update Minecraft Server

/etc/init.d/minecraft stop
  • neues bukkit Paket korrekt nach craftbukkit.jar verlinken:
ln -s craftbukkit-<VERSION>-SNAPSHOT.jar craftbukkit.jar
  • Minecraft Server starten:
/etc/init.d/minecraft start
  • Im server.log überprüfen ob der Server wieder normal startet und keine Plugin-Konflikte vorliegen

Init Startup Skript

Nun kann der Server noch mittels INIT Skript gestartet werden. Dafür folgendes Skript als root user ablegen und ihm das Ausführrecht geben:

chmod +x /etc/init.d/minecraft

/etc/init.d/minecraft

#!/bin/bash
# /etc/init.d/minecraft

### BEGIN INIT INFO
# Provides: minecraft
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Minecraft server
# Description: Init script for minecraft/bukkit server, with rolling logs and use of ramdisk for less lag.
### END INIT INFO

### Based on http://www.minecraftwiki.net/wiki/Server_startup_script


# Name of server.jar file
SERVICE='craftbukkit.jar'
# User that should run the server
USERNAME="minecraft"
# Path to minecraft directory
MCPATH='/srv/minecraft'
CPU_COUNT=2
# Change the values of -Xmx###M and -Xms###M to how mutch ram you want to give to the
# server, remember to make room for the ramdisk
INVOCATION="java -Xmx1536M -Xms1536M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE nogui"
# Where the world backups should go
BACKUPPATH='/backup/minecraft/worlds'
# Where the logs are copied when running log-roll
LOGPATH="${MCPATH}/logs"
# Where the whole minecraft directory is copied when whole-backup is runned
WHOLEBACKUP='/backup/minecraft/whole'
# Where the world is located on the disk
WORLDSTORAGE='/srv/minecraft/world/'
#Path to the the mounted ramdisk default in ubuntu: /dev/shm
RAMDISK='/dev/shm'


ME=`whoami`
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
datepath() {
# datepath path filending-to-check returned-filending
if [ -e $1`date +%x`$2 ]
then
echo $1`date +%FT%T`$3
else
echo $1`date +%F`$3
fi
}
mc_start() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "Tried to start but $SERVICE was already running!"
else
echo "$SERVICE was not running... starting."
# rsync -tr $MCPATH/world-disc /dev/shm/
cd $MCPATH
as_user "cd $MCPATH && screen -dmS minecraft $INVOCATION"
sleep 7
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is now running."
else
echo "Could not start $SERVICE."
fi
fi
}

mc_saveoff() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is running... suspending saves"
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-off\"\015'"
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
sync
sleep 10
else
echo "$SERVICE was not running. Not suspending saves."
fi
}

mc_saveon() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is running... re-enabling saves"
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-on\"\015'"
else
echo "$SERVICE was not running. Not resuming saves."
fi
}

mc_stop() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is running... stopping."
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
sleep 10
as_user "screen -p 0 -S minecraft -X eval 'stuff \"stop\"\015'"
sleep 7
else
echo "$SERVICE was not running."
fi
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE could not be shut down... still running."
else
echo "$SERVICE is shut down."
fi
}
log_roll() {
path=`datepath $MCPATH/logs/server_ .log.gz .log`
as_user "mv $MCPATH/server.log $path && gzip $path"
}
mc_whole_backup() {
path=`datepath $WHOLEBACKUP/mine_`
as_user "cp -r $MCPATH $path"
}
mc_world_backup() {
echo "Backing up minecraft world"
path=`datepath $BACKUPPATH/world_ .tar.bz2 .tar.bz2`
as_user "tar -hcjf $path $MCPATH/world"
}
to_ram() {
if [ -L $MCPATH/world ]
then
as_user "rsync -rt $WORLDSTORAGE/ $RAMDISK/world"
echo "World copied to ram"
fi
}
to_disk() {
as_user "rsync -rt $MCPATH/world/ $WORLDSTORAGE"
echo "World copied to disk"
}

case "$1" in
start)
# Starts the server
to_ram
mc_start
;;
stop)
# Stops the server
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER SHUTTING DOWN!\"\015'"
mc_stop
to_disk
;;
restart)
# Restarts the server
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER REBOOT IN 10 SECONDS.\"\015'"
mc_stop
mc_start
;;
backup)
# Backups world
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say Backing up world.\"\015'"
mc_saveoff
mc_world_backup
mc_saveon
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say Backup complete.\"\015'"
;;
whole-backup)
# Backups everything
mc_whole_backup
;;
to-disk)
# Writes from the ramdisk to disk, in case the server crashes.
# Using ramdisk speeds things up alot, especially if you allow
# teleportation on the server.
mc_saveoff
to_disk
mc_saveon
;;
connected)
# Lists connected users
as_user "screen -p 0 -S minecraft -X eval 'stuff list\015'"
sleep 3s
tac $MCPATH/server.log | grep -m 1 "Connected"
;;
log-roll)
# Moves and Gzips the logfile, a big log file slows down the
# server ALOT (what was notch thinking?)
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say ROUTINE REBOOT IN 10 SECONDS.\"\015'"
mc_stop
log_roll
mc_start
;;
status)
# Shows server status
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
;;

*)
echo "Usage: /etc/init.d/minecraft {start|stop|backup|whole-backup|log-roll|to-disk|connected|status|restart}"
exit 1
;;
esac

exit 0

nun noch den autostart und starten:

update-rc.d minecraft defaults 99
/etc/init.d/minecraft start

Das Init Skript hat folgende Startparameter:

/etc/init.d/minecraft {start|stop|backup|whole-backup|log-roll|to-disk|connected|status|restart}

Map-Renderer Minecraft Overviewer

=> http://overviewer.org/

1. In /etc/apt/sources.list eintragen:

deb http://overviewer.org/debian ./

2. Dann APT updaten und Paket installieren

apt-get update && apt-get install minecraft-overviewer

3. terrain.png (oder anderes Theme) in selbes Verzeichnis wie overviewer.py kopieren

4. ... und rendern lassen:

overviewer.py /home/username/mcserver /home/username/mcmap

Server Konfiguration (server.properties)

Minecraft Server Konfiguration

Minecraft Item Data Values

http://www.minecraftwiki.net/wiki/Data_values

Minecraft mcMMO Plugin PHP StatViewer

Minecraft Plugin mcMMO PHP StatViewer

Nagios Überwachung

/etc/nagios-plugins/config/tcp_udp.cfg

# 'check_tcp' command definition
define command{
        command_name    check_tcp
        command_line    /usr/lib/nagios/plugins/check_tcp -H '$HOSTADDRESS$' -p '$ARG1$' -w 5 -c 10
        }

Änderungen an der Nagios Host Konfig nagios3.cfg

define service {
        host_name                       hostname
        service_description             Minecraft Port
        check_command                   check_tcp!25565
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}

Quellen