[HowTo] Make your own Minecraft server pi2/3


#1

Start with downloading screen, which we will use later:

sudo apt-get update
sudo apt-get install screen

Now we download and install Oracle Java SDK

Download from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Copy(samba/ftp/scp) the file to osmc-user home folder, Go to console on your OSMC device(ssh), take note of the version number(folder name), it will come again later on.

sudo mkdir -p /usr/local/java
sudo cp ./jdk-8u111-linux-arm32-vfp-hflt.tar.gz /usr/local/java/
cd /usr/local/java/
tar xvzf jdk-8u111-linux-arm32-vfp-hflt.tar.gz
sudo nano /etc/profile

On line 9, before export path, insert these lines, the version number is in the folder name:

JAVA_HOME=/usr/local/java/jdk1.8.0_111
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME

Run these commands:

> sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_111/bin/java" 1
> sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_111/bin/javac" 1
> sudo update-alternatives --set java /usr/local/java/jdk1.8.0_111/bin/java
> sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_111/bin/javac
> source /etc/profile

Now you got Oracle JDK in your system, now onto the server building.

Next up is to download the buildtools for the minecrafts server

wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
mkdir minecraft
mv BuildTools.jar ./minecraft/
cd minecraft

Now comes the time consuming part, about 3 hours and 40 minutes on my pi3. In order to get enough memory to compile we need to lower gpu_mem to 16. Go into MyOSMC, chose Pi-config, GPU_mem and codec- tab lower gpu mem to 16 and reboot.

sudo systemctl stop mediacenter
java -Xms256M -Xmx640M -jar BuildTools.jar
sudo systemctl start mediacenter

After you ran BuildTools.jar you can restore gpu_mem to 256, and reboot.

So why does it take such time to install a minecraft server?
Well in our case we want a lightweight server that can load some plugins to lower server load even more and regulary free up memory, that’s why we are choseing Spigot plus a few plugins.

Spigot is a fork of Craftbukkit , wich is a fork of Bukkit, which is a spinnoff of Mojangs vanilla server. We could use the vanilla server, but it would lag terrible if we played 2-3 players and kodi playing something at the same time.

This BuildTool will download Bukkit, Craftbukkit and Spigot sources and Mojangs vanilla server. Then decompile Mojangs server, add the patches for each server. And compile them. Thats why it will take “forever”

Once the dust has settled we should move the server to a logical place:

sudo mkdir /opt/minecraft
sudo mv spigot*.jar /opt/minecraft/spigot.jar
cd /opt/minecraft
sudo java -Xms256M -Xmx320M -jar spigot.jar nogui

Once it stared it will stop again, urging you to read the eula.txt, So edit it and change the false to true

sudo nano eula.txt

We can also at the same time edit the server properties file

sudo nano server.properties

Paste all this text under the two top lines:

spawn-protection=16
generator-settings=
force-gamemode=false
allow-nether=false
gamemode=0
broadcast-console-to-ops=true
enable-query=false
player-idle-timeout=0
difficulty=1
spawn-monsters=true
op-permission-level=4
announce-player-achievements=true
pvp=true
snooper-enabled=true
level-type=DEFAULT
hardcore=false
enable-command-block=false
max-players=8
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
server-port=25565
debug=false
texture-pack=
server-ip=
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=5
resource-pack=
spawn-animals=true
white-list=false
generate-structures=true
online-mode=true
max-build-height=256
level-seed=
enable-rcon=false
motd=OSMC server, keep client renderview to 5

Now we can restart the server, and this time it will take a little bit of time since it’s creating the world. When it’s ”Done”, you should run this command:

op [your minecraft username] 

(without the [])

Stop the server again by writing stop in server console.

We don’t want to run the server as root user, so let’s change the file permissions on all files, recursively. I know this might be overkill but lets set it all to 777 (read, write and execute for everyone)

sudo chmod 777 * -R

Start the server again and enjoy.

java -Xms256M -Xmx320M -jar spigot.jar nogui

It’s hard to remember that long command line every time so we make a start script:

cd ~
nano startMC.sh

paste this into nano:

#!/bin/bash
cd /opt
cd minecraft
java -Xms256M -Xmx320M -jar spigot.jar nogui

Save the file. And make it executable

chmod +x startMC.sh

Finally you got a server running, but as soon as you try to close your terminal the server will die, lets make it run in the background insted. To do this I use a program called screen, which we installed earlier via apt-get.

It’s time to start minecraft server running in the background. If you want to acces the server console we will do that soon. Notice this command will just give you a blank prompt, but there is magic happening in the background.

screen -dmS Minecraft /home/osmc/startMC.sh

And to enter your server console you use this command:

screen -r Minecraft

Voila, there you have your running server, before you close your ssh client you must detach your ”minecraftserver screen”. Press CTRL+a then d, this will return you to a normal promp and the minecraft server is still running in the background and you can close your ssh session.

Here is how you make minecraft server start when your pi starts. First we make a scripts dir where we put out scripts and then a script that starts minecraft in the background…

sudo mkdir /opt/scripts
sudo mv /home/osmc/startMC.sh /opt/scripts/
sudo nano /opt/scripts/minecraftstarter.sh

#!/bin/bash
screen -dmS Minecraft /opt/scripts/startMC.sh
exit

Then we make a script to stop the the server and close the background screen.

sudo nano /opt/scripts/minecraftstopper.sh

#!/bin/bash
screen -S Minecraft -p 0 -X stuff "stop$(printf \\r)"
exit

Lets make sure all scripts are executable:

sudo chmod +x /opt/scripts/minecraftstarter.sh
sudo chmod +x /opt/scripts/minecraftstopper.sh
sudo chmod +x /opt/scripts/startMC.sh

Create a service file that calls on our minecraftstarter.sh and minecraftstopper.sh.

sudo nano /etc/systemd/system/minecraft.service

[Unit]
Description = Minecraftserver
After = remote-fs.target network-online.target mediacenter.service
[Service]
Type=oneshot
RemainAfterExit=yes
User=osmc
ExecStart = /opt/scripts/minecraftstarter.sh
ExecStop = /opt/scripts/minecraftstopper.sh
TimeoutStopSec=20

[Install]
WantedBy = multi-user.target

That should be it, now we just enable and start the server

sudo systemctl enable minecraft
sudo systemctl start minecraft

Worth reading: http://www.planetminecraft.com/blog/ultimate-guide-to-remove-server-lag/


How to create a service on OSMC
Instal java 8
#2

Not tried it but maybe MCServer (aka Cuberite) might be better as I believe it is lighter on resources (ie No Java needed) ??


#3

Going to try it further down the road, but i see two huge drawback directly.

  1. Only supports minecraft 1.8 (1.9 is in the works) and minecraft is at 1.10 now.

  2. Plugins are very few and not compatible with bukkit.

But I’m gonna have a good look at it.

Edit: After compiling it and had a few mins to play with it, it’s sure is faster and less resources hungry. It works well as a Vanilla minecraft server. But I will have a look at the plugins available and evaluate it. Just wish the had 1.10 support.


#4

I have a server running on a windows machine, and 2 RPs with osmc.

This weekend wanted to try the performance of a minecraft server on my RP3 that has osmc installed. I’ve been following the steps at the top of this thread, I’m on:

java -Xms256m -Xmx512m -jar BuildTools.jar

It’s doing it now for at least 7 hours… It’s still downloading and installing stuff (e.g. it’s not stuck) but that’s like double what OP mentioned… IS this normal? Will keep you posted.

Thanks.


#5

After about 7h15 minutes got this:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46:25 min
[INFO] Finished at: 2017-01-14T19:20:58+00:00
[INFO] Final Memory: 14M/54M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.15:check (default) on project bukkit: Failed to obtain signature: org.codehaus.mojo.signature:java16:1.1: Could not transfer artifact org.codehaus.mojo.signature:java16:signature:1.1 from/to central (https://repo.maven.apache.org/maven2): Connection reset
[ERROR] org.codehaus.mojo.signature:java16:signature:1.1
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots, releases=false, snapshots=true),
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Exception in thread "main" java.lang.RuntimeException: Error running command, return status !=0: [sh, /home/osmc/minecraft/apache-maven-3.2.5/bin/mvn, clean, install]
        at org.spigotmc.builder.Builder.runProcess(Builder.java:552)
        at org.spigotmc.builder.Builder.main(Builder.java:418)

Any suggestion?


#6

It seems like they bump the versions of spigot, and the buildtools it’s using too. I’m sorry to say i can not help you with this. You might wanna try the spigot forums, wiki and other resources. I just made this guide to simplyfy the steps.


#7

Ok, thanks @joakim_s.

Any idea if there’s any other tutorials on how to install a minecraft server on osmc?


#9

Thanks for the help @joakim_s. At the moment I’m following this tutorial: http://lemire.me/blog/2016/04/02/setting-up-a-robust-minecraft-server-on-a-raspberry-pi/

It’s now in the java -jar BuildTools.jar phase so, it will take a while… I will keep you posted. Assuming the issue is prevails, I will try your solution after. I assume it will be only tomorrow morning though.

Out of curiosity, how is your server performing? Do you still run it on a rp3 with osmc installed? Do you have anything else installed on that same machine? At the same time as the osmc I’ve got transmission for torrents, a mini dlna server, ftp and a shared external hard drive that is accessed by 2 other devices on the same network, so I’m not sure if it will perform very well, even with a RP3 overclocked.


#10

i had it running with kodi, transmission and vncserver on a pi2 with 3 persons, but on the pi2 you noticed some lag from time to time. But it was playable. The pi3 just ran the server for a while then i did a fresh install and never got minecraft up again, a few weeks with minecraft server made the kids “full” of minecrafty again. I’m trying installing my self now on the pi2, with oracle jdk.
Will keep you posted aswell.


#11

That’s reassuring. I’m using a rp3 and have a similar amount of users. Just ordered a U3 micro SD card with the expectation of improving the performance a little bit.


#12

Got over the first hurdle, had to set gpumem to 16, stop mediacenter too and run

java -Xms256m -Xmx640m -jar BuildTools.jar

to start the build long enough to start decompileing


#13

You can enable a swap which is probably a better option for those that want to continue using Kodi.

sudo touch /enable_swap
sudo reboot

#14

@joakim_s your system is way faster than mine, you’ve started after and are already done with it… My system started the decompiling about 5 minutes ago only…

When I tried it earlier today I did stop the mediacenter and changed the gpumem to 16. During that try, it did start decompiling, I could see that a lot in the logs, but then got the errors in the log I reported.

Anyway, tomorrow morning will confirm what’s the state of this try and probably start a new one.

Thanks.


#15

Well the speed is due to the official OSMC sd card, made a huge differans for my compiling times. Btw it’s finnished now and worked well with the oracle jdk, just needed abit more memory to compile


#16

@sam_nazarko and what would be the effect of enabling swap? Actually, in other works, why is that something that is not done often?

If I remember correctly, the swap would act as memory ram using the micro sd memory, expanding that way the memory ram. Is that correct? If so, what are the disadvantages of that approach (apart from the obvious loss of some GB on the micro sd card) and why is that not widely used?

Thanks.


#17

I didn’t know there is an official osmc sd card.

Just googled o check the specs. The card I’m using atm is U1 which I believe is at least the same speed as C10 (which is the speed for the osmc official card). I might have more services using the machine resources that I’m not considering. I have probably installed/setup stuff that are unnecessarily consuming resources.


#18

Just started to prepare spawn point, should be in bed by now but i thought i’d see this through


#19

Our users don’t require swap with typical OSMC workload. Using Kodi won’t require swap. This might change for some Pi 1 devices as Kodi becomes more complex in the future, but I doubt it. GPU, not ARM memory, seems to be the problem here.

We do enable swap under certain conditions, but your scenario will not trigger it. Compiling is a rare exception, and we expect that if people are happy to compile things, they will adjust some tunables themselves. We also don’t want to preemptively set a large swap size and waste SD card space (linkers are dumb, even with GOLD) when very few of our users will ever need it. Swapping also reduces performance.

C10 etc are just boxes for manufacturers to tick. Most of these cards are used in digital cameras for continuous writes, i.e. snapping photos quickly. This means they can sometimes fall short when they’re running an OS.

The OSMC SD card is the fastest SD card (for running OSMC) that you will buy in that price range. This isn’t hyperbole – it’s now stocked by partners (including Element14) as it has been recognised as a very performant card. It’s designed and tested to run OSMC, not as a storage device for a camera. I was chuffed that we came up best against other well established brands when evaluated on price to performance.

Sam


#20

@joakim_s woke up to a successful build this time around! Building the server for the first time now, need to change the configurations and stuff, will keep you posted.

My build started at around 22:45h yesterday and finished at 02:11, so just under 4h - that’s more in line with the time your takes. But the interesting bit is that for this build I didn’t pass any start or max memory (used just java -jar BuildTools.jar), didn’t stop kodi (actually used it to watch stuff while it was building it) or reduced the gpu memory.

One final question now actually: when you run your minecraft server, considering you still want to get kodi and everything else to work fine, how much memory do you give it (start and max)?

@sam_nazarko thanks for your explanation on swap. As per my previous message, I was lucky enough to get it build without requiring that.

On the micro sd cards that’s impressive - I would like to read more on what makes it better than well established brads like sandisk or samsung. I have to admit that I didn’t search on this particular forum - or even sd cards particularly to osmc - but I did search micro sd cards for rps and I don’t think yours came in any of the compilations (here or here), so I ended up recently buying a SanDisk Extreme which is supposed to be Class 10, U3 and V30 - 2x price of the osmc…


#21

@ertosp I’ve used the standard i posted in the beginning of the thread,

java -Xms256M -Xmx320M -jar spigot.jar nogui

Had no real problems with that, but i guess thats because i’m not playing alot of players at the same time, 2-3 usually.