Setting up CentOS for Minecraft

Working on updating this post.
Get CentOS here.
Install CentOS, I usually do the basic server install and add packages from there. Once the install is done run yum update to make sure all packages are up to date.

RPMforge setup

Optional packages to add
If you want plugins to store info in a database.
mysql mysql-server mysqlclient
Security related

Add users

Add a user to run minecraft:
    useradd -c "Minecraft" -s/bin/bash -d /home/minecraft -m -g users     minecraft
Add a user for yourself:
    useradd -c "Your name" -s/bin/bash -d /home/username -m -g users username
Set the password for each user added. passwd username

Secure things
Some stuff I do here is actually making the server less secure. I run mine behind a firewall on a trusted network. If you aren’t behind a firewall or your network isn’t trusted do not disable selinux or iptables.
Changes to make:(some of these may already be in place)
Protocol 2
PermitRootLogin no
Banner /etc/banners/sshd
Optional change:
This change will make it so only the listed users can login using ssh.
AllowUsers username1 username2 username3 …
Add a message here telling people to go away.
Restart ssh /etc/init.d/sshd restart
Changes to make:
Disable iptables if you know you don’t need a firewall. If you need iptables make sure you know how to configure it. You will need to open a port for the server.
chkconfig –levels 2345 iptables off
chkconfig –levels 2345 ip6tables off

Install java
From what I have read online java 7 is recommended for the server. I believe Oracle recommends using openjdk on linux. So my choice can be debated. I haven’t had any problems yet. Make sure you keep up to date with the current release though.
Download java 7 here.
Download the JRE most people don’t need the JDK. Make sure you select the correct version for your system. You should be using 64bit. Select the rpm version.

rpm -ivh jre-7u3-linux-x64.rpm

To update java:
yum list |grep jre
should list something like this
jre.x86_64 1.7.0_03-fcs installed
yum remove jre.x86_64
Then run the rpm install command again for the new version.

Setup minecraft startup script and ramdisk
My script.

Controlling the server
startup server
/etc/init.d/minecraft start

stop server
You can set a delay for this so users have time to logout.
/etc/init.d/minecraft stop

restart server
/etc/init.d/minecraft restart

backup server
/etc/init.d/minecraft backup

send a message to the console
The message will appear to all users in game. Useful for messages you repeat throughout the day.
/etc/init.d/minecraft sndmsg ‘Your message here.’

Maintenance tasks
Configure server backups. I have two cronjobs setup to run backups.
The first runs every 5 minutes and syncs the ramdisk copy with the disk copy. The second runs 4 times a day and creates an archive from the disk backup. I also have a shell script to clean out backup copies. I will update this once I post that script.
20 */6 * * * /etc/init.d/minecraft backup >/dev/null 2>&1
*/5 * * * * /etc/init.d/minecraft disksaverun >/dev/null 2>&1

Optional stuff

Leave a Reply