Previous Page

nothing@nowhere - 2021-11-16

Minecraft Server Setup

In this tutorial we're going to setup a minecraft server:

Initial Setup

First install the required dependencies:


root@minecraft:~# apt update -y ; apt upgrade -y ; apt install default-jdk -y
root@minecraft:~# apt update -y ; apt install default-jre   software-properties-common python3-launchpadlib -y 
root@minecraft:~# add-apt-repository ppa:webupd8team/java

root@minecraft:~#  java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

root@minecraft:~# adduser mcuser
Adding user `mcuser' ...
Adding new group `mcuser' (1000) ...
Adding new user `mcuser' (1000) with group `mcuser' ...
Creating home directory `/home/mcuser' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for mcuser
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

root@minecraft:~# usermod -aG sudo mcuser

root@minecraft:~# su - mcuser
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.

mcuser@minecraft:~$ pwd
/home/mcuser
mcuser@minecraft:~$ mkdir minecraft
mcuser@minecraft:~$ cd minecraft/


mcuser@minecraft:~/minecraft$ wget https://maven.minecraftforge.net/net/minecraftforge/forge/1.12.2-14.23.5.2855/forge-1.12.2-14.23.5.2855-installer.jar
--2021-11-16 16:26:29--  https://maven.minecraftforge.net/net/minecraftforge/forge/1.12.2-14.23.5.2855/forge-1.12.2-14.23.5.2855-installer.jar
Resolving maven.minecraftforge.net (maven.minecraftforge.net)... 51.79.83.165, 2607:5300:203:65a5::
Connecting to maven.minecraftforge.net (maven.minecraftforge.net)|51.79.83.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4583673 (4.4M) [application/java-archive]
Saving to: 'forge-1.12.2-14.23.5.2855-installer.jar'

forge-1.12.2-14.23.5.2855-installer.jar              100%[======================================================================================================================>]   4.37M  2.84MB/s    in 1.5s

2021-11-16 16:26:31 (2.84 MB/s) - 'forge-1.12.2-14.23.5.2855-installer.jar' saved [4583673/4583673]


mcuser@minecraft:~/minecraft$ java -jar forge-1.12.2-14.23.5.2855-installer.jar --installServer
JVM info: Ubuntu - 11.0.11 - 11.0.11+9-Ubuntu-0ubuntu2.20.04
java.net.preferIPv4Stack=true
Found java version 11.0.11
Target Directory: .
Data kindly mirrored by CreeperHost at https://www.creeperhost.net/
Extracting main jar:
  Extracted successfully
Considering minecraft server jar
  Downloading library from https://launcher.mojang.com/v1/objects/886945bfb2b978778c3a0288fd7fab09d315b25f/server.jar

[...]

Building Processors
The server installed successfully
You can delete this installer file now if you wish
mcuser@minecraft:~/minecraft$ ls -l
total 38368
-rw-rw-r-- 1 mcuser mcuser  4583673 Nov 16 16:26 forge-1.12.2-14.23.5.2855-installer.jar
-rw-rw-r-- 1 mcuser mcuser     5054 Nov 16 16:28 forge-1.12.2-14.23.5.2855-installer.jar.log
-rw-rw-r-- 1 mcuser mcuser  4464387 Nov 16 16:28 forge-1.12.2-14.23.5.2855.jar
drwxrwxr-x 7 mcuser mcuser     4096 Nov 16 16:28 libraries
-rw-rw-r-- 1 mcuser mcuser 30222121 Nov 16 16:28 minecraft_server.1.12.2.jar
	

Now let's test if it works:


mcuser@minecraft:~/minecraft$ java -Xmx2048M -Xms2048M -jar minecraft_server.1.12.2.jar nogui
[16:31:36] [Server thread/INFO]: Starting minecraft server version 1.12.2
[16:31:36] [Server thread/INFO]: Loading properties
[16:31:36] [Server thread/WARN]: server.properties does not exist
[16:31:36] [Server thread/INFO]: Generating new properties file
[16:31:36] [Server thread/WARN]: Failed to load eula.txt
[16:31:36] [Server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
[16:31:36] [Server thread/INFO]: Stopping server
[16:31:36] [Server Shutdown Thread/INFO]: Stopping server

mcuser@minecraft:~/minecraft$ ls -lash
total 38M
4.0K drwxrwxr-x 4 mcuser mcuser 4.0K Nov 16 16:31 .
4.0K drwxr-xr-x 5 mcuser mcuser 4.0K Nov 16 16:27 ..
4.0K -rw-rw-r-- 1 mcuser mcuser  181 Nov 16 16:31 eula.txt
4.4M -rw-rw-r-- 1 mcuser mcuser 4.4M Nov 16 16:26 forge-1.12.2-14.23.5.2855-installer.jar
8.0K -rw-rw-r-- 1 mcuser mcuser 5.0K Nov 16 16:28 forge-1.12.2-14.23.5.2855-installer.jar.log
4.3M -rw-rw-r-- 1 mcuser mcuser 4.3M Nov 16 16:28 forge-1.12.2-14.23.5.2855.jar
4.0K drwxrwxr-x 7 mcuser mcuser 4.0K Nov 16 16:28 libraries
4.0K drwxrwxr-x 2 mcuser mcuser 4.0K Nov 16 16:31 logs
 29M -rw-rw-r-- 1 mcuser mcuser  29M Nov 16 16:28 minecraft_server.1.12.2.jar
4.0K -rw-rw-r-- 1 mcuser mcuser   59 Nov 16 16:31 server.properties
	
mcuser@minecraft:~/minecraft$ cat eula.txt
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Tue Nov 16 16:31:36 UTC 2021
eula=true

mcuser@minecraft:~/minecraft$ java -Xmx2048M -Xms2048M -jar minecraft_server.1.12.2.jar nogui
[16:34:00] [Server thread/INFO]: Starting minecraft server version 1.12.2
[16:34:00] [Server thread/INFO]: Loading properties
[16:34:00] [Server thread/INFO]: Default game type: SURVIVAL
[16:34:00] [Server thread/INFO]: Generating keypair
[16:34:00] [Server thread/INFO]: Starting Minecraft server on *:25565
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/home/mcuser/minecraft/minecraft_server.1.12.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[16:34:00] [Server thread/INFO]: Using epoll channel type
[16:34:00] [Server thread/INFO]: Preparing level "world"
[16:34:01] [Server thread/INFO]: Loaded 488 advancements
[16:34:02] [Server thread/INFO]: Preparing start region for level 0
[16:34:03] [Server thread/INFO]: Preparing spawn area: 5%
[16:34:04] [Server thread/INFO]: Preparing spawn area: 8%
[16:34:05] [Server thread/INFO]: Preparing spawn area: 13%
[16:34:06] [Server thread/INFO]: Preparing spawn area: 16%
[16:34:07] [Server thread/INFO]: Preparing spawn area: 21%
[16:34:08] [Server thread/INFO]: Preparing spawn area: 27%
[16:34:09] [Server thread/INFO]: Preparing spawn area: 35%
[16:34:10] [Server thread/INFO]: Preparing spawn area: 41%
[16:34:11] [Server thread/INFO]: Preparing spawn area: 48%
[16:34:12] [Server thread/INFO]: Preparing spawn area: 55%
[16:34:13] [Server thread/INFO]: Preparing spawn area: 62%
[16:34:14] [Server thread/INFO]: Preparing spawn area: 70%
[16:34:15] [Server thread/INFO]: Preparing spawn area: 78%
[16:34:16] [Server thread/INFO]: Preparing spawn area: 86%
[16:34:17] [Server thread/INFO]: Preparing spawn area: 94%
[16:34:18] [Server thread/INFO]: Done (17.633s)! For help, type "help" or "?"

Now the minecraft server is up, let's check if it works, first install minecraft on your client::


[ 10.66.66.2/32 ] [ /dev/pts/135 ] [~]
→ yay -S minecraft-launcher

[ 10.66.66.2/32 ] [ /dev/pts/135 ] [~]
→ which minecraft-launcher
/usr/bin/minecraft-launcher
	

Next if you need to port forward the mc server to the public, it will be on port 25565.


	

Setup



Now if you want to make a modded server, you will need a few things, first you will need minecraft forge install:


[ 10.66.66.2/32 ] [ /dev/pts/138 ] [~]
→ cd Downloads

[ 10.66.66.2/32 ] [ /dev/pts/138 ] [~/Downloads]
→ java -jar forge-1.12.2-14.23.5.2855-installer.jar

This will open the forge installer, select client this time:

And then we can login once again into the server:

Now let's add a mod into the minecraft server:


mcuser@minecraft:~$ ls -l
total 4
drwxrwxr-x 5 mcuser mcuser 4096 Nov 16 16:34 minecraft
mcuser@minecraft:~$ cd minecraft/
mcuser@minecraft:~/minecraft$ ls -l
total 38404
-rw-rw-r-- 1 mcuser mcuser        2 Nov 16 16:34 banned-ips.json
-rw-rw-r-- 1 mcuser mcuser        2 Nov 16 16:34 banned-players.json
-rw-rw-r-- 1 mcuser mcuser      180 Nov 16 16:33 eula.txt
-rw-rw-r-- 1 mcuser mcuser  4583673 Nov 16 16:26 forge-1.12.2-14.23.5.2855-installer.jar
-rw-rw-r-- 1 mcuser mcuser     5054 Nov 16 16:28 forge-1.12.2-14.23.5.2855-installer.jar.log
-rw-rw-r-- 1 mcuser mcuser  4464387 Nov 16 16:28 forge-1.12.2-14.23.5.2855.jar
drwxrwxr-x 7 mcuser mcuser     4096 Nov 16 16:28 libraries
drwxrwxr-x 2 mcuser mcuser     4096 Nov 16 16:33 logs
-rw-rw-r-- 1 mcuser mcuser 30222121 Nov 16 16:28 minecraft_server.1.12.2.jar
-rw-rw-r-- 1 mcuser mcuser        2 Nov 16 16:34 ops.json
-rw-rw-r-- 1 mcuser mcuser      753 Nov 16 16:34 server.properties
-rw-rw-r-- 1 mcuser mcuser      109 Nov 16 16:44 usercache.json
-rw-rw-r-- 1 mcuser mcuser        2 Nov 16 16:34 whitelist.json
drwxrwxr-x 9 mcuser mcuser     4096 Nov 16 16:49 world
mcuser@minecraft:~/minecraft$ mkdir mods

mcuser@minecraft:~/minecraft$ cd mods
mcuser@minecraft:~/minecraft/mods$ wget https://media.forgecdn.net/files/2835/318/defiledlands-1.12.2-1.4.3.jar
--2021-11-16 17:10:34--  https://media.forgecdn.net/files/2835/318/defiledlands-1.12.2-1.4.3.jar
Resolving media.forgecdn.net (media.forgecdn.net)... 13.224.226.86, 13.224.226.118, 13.224.226.83, ...
Connecting to media.forgecdn.net (media.forgecdn.net)|13.224.226.86|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 780421 (762K) [application/x-amz-json-1.0]
Saving to: 'defiledlands-1.12.2-1.4.3.jar'

defiledlands-1.12.2-1.4.3.jar                        100%[======================================================================================================================>] 762.13K  3.50MB/s    in 0.2s

2021-11-16 17:10:35 (3.50 MB/s) - 'defiledlands-1.12.2-1.4.3.jar' saved [780421/780421]

mcuser@minecraft:~/minecraft/mods$ wget https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar
--2021-11-16 17:23:53--  https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar
Resolving media.forgecdn.net (media.forgecdn.net)... 13.224.226.110, 13.224.226.86, 13.224.226.83, ...
Connecting to media.forgecdn.net (media.forgecdn.net)|13.224.226.110|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 108450 (106K) [application/octet-stream]
Saving to: 'Baubles-1.12-1.5.2.jar'

Baubles-1.12-1.5.2.jar                               100%[======================================================================================================================>] 105.91K  --.-KB/s    in 0.04s

2021-11-16 17:23:54 (2.38 MB/s) - 'Baubles-1.12-1.5.2.jar' saved [108450/108450]

mcuser@minecraft:~/minecraft/mods$ cd ..

mcuser@minecraft:~/minecraft$ java -Xmx2048M -Xms2048M -jar minecraft_server.1.12.2.jar nogui

Now if we want to run our minecraft forge server we need an older version of java:



mcuser@minecraft:~/minecraft$ sudo apt purge java-common default-jdk default-jre 
mcuser@minecraft:~/minecraft$ sudo apt install openjdk-8-jre -y
mcuser@minecraft:~/minecraft$ java -version
mcuser@minecraft:~/minecraft$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

mcuser@minecraft:~/minecraft$ java -Xmx2048M -Xms2048M -jar forge-1.12.2-14.23.5.2855.jar nogui
[17:24:19] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLServerTweaker
[17:24:19] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLServerTweaker
[17:24:19] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLServerTweaker
[17:24:19] [main/INFO] [FML]: Forge Mod Loader version 14.23.5.2855 for Minecraft 1.12.2 loading
[17:24:19] [main/INFO] [FML]: Java is OpenJDK 64-Bit Server VM, version 1.8.0_292, running on Linux:amd64:5.4.143-1-pve, installed at /usr/lib/jvm/java-8-openjdk-amd64/jre
[17:24:19] [main/INFO] [FML]: Searching /home/mcuser/minecraft/./mods for mods
[17:24:19] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:24:19] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[17:24:19] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:24:19] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:24:19] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[17:24:23] [main/INFO] [FML]: Found valid fingerprint for Minecraft Forge. Certificate fingerprint e3c3d50c7c986df74c645c0ac54639741c90a557
[17:24:23] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[17:24:23] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[17:24:23] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker
[17:24:23] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker
[17:24:24] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.server.MinecraftServer}
[17:24:29] [Server thread/INFO] [minecraft/DedicatedServer]: Starting minecraft server version 1.12.2
[17:24:29] [Server thread/INFO] [FML]: MinecraftForge v14.23.5.2855 Initialized
[17:24:29] [Server thread/INFO] [FML]: Starts to replace vanilla recipe ingredients with ore ingredients.
[17:24:29] [Server thread/INFO] [FML]: Invalid recipe found with multiple oredict ingredients in the same ingredient...
[17:24:30] [Server thread/INFO] [FML]: Replaced 1227 ore ingredients
[17:24:30] [Server thread/INFO] [FML]: Searching /home/mcuser/minecraft/./mods for mods
[17:24:31] [Server thread/INFO] [FML]: Forge Mod Loader has identified 6 mods to load
[17:24:31] [Server thread/WARN] [FML]: Missing English translation for FML: assets/fml/lang/en_us.lang
[...]

And now it loads our mods ! Now let's download the mods locally for our client:

If you try to login without the mods on the client you will see an error like that one:


[ 10.66.66.2/32 ] [ /dev/pts/139 ] [~/.minecraft/mods]
→ wget https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar
--2021-11-16 18:26:43--  https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar
SSL_INIT
Loaded CA certificate '/etc/ssl/certs/ca-certificates.crt'
Resolving media.forgecdn.net (media.forgecdn.net)... 13.224.226.83, 13.224.226.110, 13.224.226.86, ...
Connecting to media.forgecdn.net (media.forgecdn.net)|13.224.226.83|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 108450 (106K) [application/octet-stream]
Saving to: ‘Baubles-1.12-1.5.2.jar’

Baubles-1.12-1.5.2.jar                               100%[=====================================================================================================================>] 105.91K  --.-KB/s    in 0.05s

2021-11-16 18:26:43 (1.98 MB/s) - ‘Baubles-1.12-1.5.2.jar’ saved [108450/108450]


[ 10.66.66.2/32 ] [ /dev/pts/139 ] [~/.minecraft/mods]
→ wget https://media.forgecdn.net/files/2835/318/defiledlands-1.12.2-1.4.3.jar
--2021-11-16 18:26:50--  https://media.forgecdn.net/files/2835/318/defiledlands-1.12.2-1.4.3.jar
SSL_INIT
Loaded CA certificate '/etc/ssl/certs/ca-certificates.crt'
Resolving media.forgecdn.net (media.forgecdn.net)... 13.224.226.86, 13.224.226.83, 13.224.226.110, ...
Connecting to media.forgecdn.net (media.forgecdn.net)|13.224.226.86|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 780421 (762K) [application/x-amz-json-1.0]
Saving to: ‘defiledlands-1.12.2-1.4.3.jar’

defiledlands-1.12.2-1.4.3.jar                        100%[=====================================================================================================================>] 762.13K  2.89MB/s    in 0.3s

2021-11-16 18:26:51 (2.89 MB/s) - ‘defiledlands-1.12.2-1.4.3.jar’ saved [780421/780421]
	

And we manage to login!

And that's it! We managed to log into our modded minecraft server.

Setup



For the players who want to download the mods they need to log into the server, you can setup a simple nginx to allow them to get there:


	
root@minecraft:~# vim /etc/nginx/sites-available/default
root@minecraft:~# cat /etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;


        root /home/mcuser/minecraft/mods;

        index index.html index.htm index.nginx-debian.html;

        server_name _;
        autoindex on;

        location / {
                try_files $uri $uri/ =404;
        }
}


root@minecraft:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@minecraft:~# nginx -s reload

Now let's make a systemd service to launch our minecraft server


root@minecraft:~# vim /etc/systemd/system/minecraft.service
root@minecraft:~# cat /etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft Server
After=syslog.target network.target

[Service]
# Ensure to set the correct user and working directory (installation directory of your server) here
User=mcuser
WorkingDirectory=/home/mcuser/minecraft/

# You can customize the maximum amount of memory as well as the JVM flags here
ExecStart=/usr/bin/java -XX:+UseG1GC -Xmx6G -jar forge-1.12.2-14.23.5.2855.jar --nojline --noconsole -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1HeapRegionSize=32M -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50

# Restart the server when it is stopped or crashed after 30 seconds
# Comment out RestartSec if you want to restart immediately
Restart=always
RestartSec=3

# Alternative: Restart the server only when it stops regularly
# Restart=on-success

# Do not remove this!
StandardInput=null

[Install]
WantedBy=multi-user.target
	
root@minecraft:~# systemctl daemon-reload
root@minecraft:~# systemctl enable --now minecraft
Created symlink /etc/systemd/system/multi-user.target.wants/minecraft.service -> /etc/systemd/system/minecraft.service.
root@minecraft:~# systemctl status minecraft
* minecraft.service - Minecraft Server
     Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-11-18 08:16:11 UTC; 5s ago
   Main PID: 31956 (java)
      Tasks: 33 (limit: 7372)
     Memory: 113.1M
     CGroup: /system.slice/minecraft.service
             `-31956 /usr/bin/java -XX:+UseG1GC -Xmx3G -jar forge-1.12.2-14.23.5.2855.jar --nojline --noconsole

Nov 18 08:16:11 minecraft systemd[1]: Started Minecraft Server.


For other minecraft versions you will need to install other java versions, sadly you need to deal with oracle being a corporation and you may need to login there. You're going to need either openjdk 11 or 17+, openjdk 11 being the cutover version from minecraft 1.16.5


use java version 1.8.0 (download it from the oracle website)  to make a minecraft server 1.12.2 or on 1.16.5

>> https://www.oracle.com/java/technologies/downloads/archive/ (yes you need to create an account there, just fill it with garbage data)

Nihilism

Until there is Nothing left.

About nihilist

Donate XMR: 8AUYjhQeG3D5aodJDtqG499N5jXXM71gYKD8LgSsFB9BUV1o7muLv3DXHoydRTK4SZaaUBq4EAUqpZHLrX2VZLH71Jrd9k8


Contact: nihilist@nihilism.network (PGP)