Homemade Minecraft server ;)

As my two sons are fans of Minecraft we finally decided to install our own Minecraft server for them.

Here is a short instruction how to do it on Ubuntu server:

Before starting the installation of the Minecraft Server, we recommend first to ensure that your Ubuntu is up-to-date using the following commands:

sudo apt update 
sudo apt upgrade

Now create minecraft user

sudo adduser minecraft

Now, let’s switch to the newly created “minecraftuser” using the subsequent command.

su - minecraftuser

Make sure that you have the wget package installed, if not you can install it using the following command.
sudo apt install wget

Install the java package that will be used on the Minecraft Server.

sudo apt install openjdk-8-jdk -y

 In case you need the Minecraft server to run in the background, download the “screen” package using the following command.
sudo apt install screen

Next, we are going to download the Minecraft Server. But be careful to replace the following URL with the latest release of Minecraft website (Click here!!)
sudo wget -O minecraft_server.jar https://s3.amazonaws.com/Minecraft.Download/versions/1.11.2/minecraft_server.1.11.2.jar

You need to create the eula.txt file and agree to the license agreement conditions.
sudo vi eula.txt

Add the following line “eula=true” to the created “eula.txt” file. 

Now you can start the Minecraft Server using the subsequent command.

sudo java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

This command will allow you to start the Minecraft Server with an allocated memory 1024MB. In case you need to increase this allocated memory, you can change the “-Xmx” parameter with your desired value.

Create start script by :

echo „sudo java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui” >start.sh

Create stop script:

echo „stop” > stop.sh

Change permissions of both of the files to:

chmod 755 start.sh

chmod 755 stop.sh

Now open port of Minecraftserver in order to enable other gamers to use your server:

ufw allow 25565/tcp
ufw disable

ufw enable

And the last step – add your server to init.d in order it starts just after starting the computer.

As root go to:

cd /etc/init.d

and create file minecraftSErver_start with following content.

As command provide your start.sh script. As stop – provide your stop.sh script with proper path.

Default user should be minecraft.

#!/bin/sh

### BEGIN INIT INFO

# Provides: <NAME>

# Required-Start: $local_fs $network $named $time $syslog

# Required-Stop: $local_fs $network $named $time $syslog

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Description: <DESCRIPTION>

### END INIT INFO



SCRIPT=<COMMAND>

RUNAS=<USERNAME>



PIDFILE=/var/run/<NAME>.pid

LOGFILE=/var/log/<NAME>.log



start() {

if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then

echo 'Service already running' >&2

return 1

fi

echo 'Starting service…' >&2

local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"

su -c "$CMD" $RUNAS > "$PIDFILE"

echo 'Service started' >&2

}



stop() {

if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then

echo 'Service not running' >&2

return 1

fi

echo 'Stopping service…' >&2

kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"

echo 'Service stopped' >&2

}



uninstall() {

echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "

local SURE

read SURE

if [ "$SURE" = "yes" ]; then

stop

rm -f "$PIDFILE"

echo "Notice: log file is not be removed: '$LOGFILE'" >&2

update-rc.d -f <NAME> remove

rm -fv "$0"

fi

}



case "$1" in

start)

start

;;

stop)

stop

;;

uninstall)

uninstall

;;

retart)

stop

start

;;

*)

echo "Usage: $0 {start|stop|restart|uninstall}"

esac

Start and test your service:

service $YOUR_SERVICE_NAME start
service $YOUR_SERVICE_NAME stop

Install service to be run at boot-time:

update-rc.d $YOUR_SERVICE_NAME defaults

Enjoy!

2 myśli na “Homemade Minecraft server ;)

Skomentuj minecraft servers Anuluj pisanie odpowiedzi

Twój adres e-mail nie zostanie opublikowany.