2020年6月7日日曜日

SpigotでMinecraftマルチプレイサーバを立ててみた

今回は“Spigot”をインストールしてみました。


検証に使用したサーバのスペックは以下の通りです。
OS:Ubuntu 20.04 LTS (x86_64)
CPU:2コア
RAM:1GB

SpigotのインストールにはBuildToolsを使用しますが、現時点ではJava 11には対応していないようです。

*** The version you have requested to build requires Java versions between [Java 8, Java 10], but you are using Java 11
*** Please rerun BuildTools using an appropriate Java version. For obvious reasons outdated MC versions do not support Java versions that did not exist at their release.

そのためuniverseリポジトリからJava 8をインストールします。

# apt install software-properties-common
# add-apt-repository universe
# apt install openjdk-8-jre-headless

複数バージョンのJavaがインストールされている環境で、使用するJavaのバージョンを変更するためには次のコマンドを実行します。

# update-alternatives --config java
 There are 2 choices for the alternative java (providing /usr/bin/java).
 
   Selection    Path                                            Priority   Status
 ------------------------------------------------------------
 * 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
   1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
   2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

今回は使用するJavaのバージョンは変更せず、BuildToolsの実行時のみJava 8を指定して実行しました。

# apt install software-properties-common
# add-apt-repository universe
# apt install screen git default-jre-headless openjdk-8-jre-headless
# su - minecraft
$ mkdir spigot
$ mkdir spigot_live
$ cd spigot
$ wget -O BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
$ git config --global --unset core.autocrlf
$ /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -Xmx512M -jar BuildTools.jar --rev 1.12.2
 openjdk version "1.8.0_252"
 OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
 OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
 minecraft@osaka:~/spigot$ /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -Xmx512M -jar BuildTools.jar --rev 1.12.2
 Loading BuildTools version: git-BuildTools-975b734-112 (#112)
 Java Version: Java 8
 Current Path: /home/minecraft/spigot/.
 git version 2.25.1
 BuildTools
 unconfigured@null.spigotmc.org
 Attempting to build version: '1.12.2' use --rev  to override
 Found version
 
 
 ~中略~
 
 
 Success! Everything completed successfully. Copying final .jar files now.
 Copying craftbukkit-1.12.2-R0.1-SNAPSHOT.jar to /home/minecraft/spigot/./craftbukkit-1.12.2.jar
   - Saved as ./craftbukkit-1.12.2.jar
 Copying spigot-1.12.2-R0.1-SNAPSHOT.jar to /home/minecraft/spigot/./spigot-1.12.2.jar
  - Saved as ./spigot-1.12.2.jar

さっそく実行してみます。

$ cp spigot-1.12.2.jar ../spigot_live/spigot-1.12.2.jar
$ cd ../spigot_live
$ java -Xms1G -Xmx1G -jar spigot-1.12.2.jar
 Loading libraries, please wait...
 [23:55:15 INFO]: Starting minecraft server version 1.12.2
 [23:55:15 INFO]: Loading properties
 [23:55:15 WARN]: server.properties does not exist
 [23:55:15 INFO]: Generating new properties file
 [23:55:15 WARN]: Failed to load eula.txt
 [23:55:15 INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
 [23:55:15 INFO]: Stopping server

EULAを読んで同意できる場合はeula.txtを編集してeula=trueとします。

$ vi eula.txt
 #By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
 #Sat Jun 06 23:55:15 JST 2020
 eula=true

再び実行してみます。

$ java -Xms1G -Xmx1G -jar spigot-1.12.2.jar
 Loading libraries, please wait...
 [23:57:18 INFO]: Starting minecraft server version 1.12.2
 [23:57:18 INFO]: Loading properties
 [23:57:18 INFO]: Default game type: SURVIVAL
 [23:57:18 INFO]: This server is running CraftBukkit version git-Spigot-79a30d7-acbc348 (MC: 1.12.2) (Implementing API version 1.12.2-R0.1-SNAPSHOT)
 [23:57:19 INFO]: Debug logging is disabled
 [23:57:19 INFO]: Server Ping Player Sample Count: 12
 [23:57:19 INFO]: Using 4 threads for Netty based IO
 [23:57:19 INFO]: Generating keypair
 [23:57:19 INFO]: Starting Minecraft server on *:25565
 [23:57:19 INFO]: Using epoll channel type
 [23:57:19 INFO]: **** Beginning UUID conversion, this may take A LONG time ****
 
 
 ~中略~
 
 
 [23:57:40 INFO]: Done (21.146s)! For help, type "help" or "?"
 >help
 [23:58:27 INFO]: --------- Help: Index ---------------------------
 [23:58:27 INFO]: Use /help [n] to get page n of help.
 [23:58:27 INFO]: Aliases: Lists command aliases
 [23:58:27 INFO]: Bukkit: All commands for Bukkit
 [23:58:27 INFO]: Minecraft: All commands for Minecraft
 [23:58:27 INFO]: /advancement: A Mojang provided command.
 [23:58:27 INFO]: /ban: A Mojang provided command.
 [23:58:27 INFO]: /ban-ip: A Mojang provided command.
 [23:58:27 INFO]: /banlist: A Mojang provided command.
 [23:58:27 INFO]: /blockdata: A Mojang provided command.
 [23:58:27 INFO]: /clear: A Mojang provided command.
 [23:58:27 INFO]: /clone: A Mojang provided command.
 [23:58:27 INFO]: /debug: A Mojang provided command.
 [23:58:27 INFO]: /defaultgamemode: A Mojang provided command.
 [23:58:27 INFO]: /deop: A Mojang provided command.
 [23:58:27 INFO]: /difficulty: A Mojang provided command.
 [23:58:27 INFO]: /effect: A Mojang provided command.
 [23:58:27 INFO]: /enchant: A Mojang provided command.
 [23:58:27 INFO]: /entitydata: A Mojang provided command.
 [23:58:27 INFO]: /execute: A Mojang provided command.
 [23:58:27 INFO]: /fill: A Mojang provided command.
 [23:58:27 INFO]: /function: A Mojang provided command.
 [23:58:27 INFO]: /gamemode: A Mojang provided command.
 [23:58:27 INFO]: /gamerule: A Mojang provided command.
 [23:58:27 INFO]: /give: A Mojang provided command.
 [23:58:27 INFO]: /help: Shows the help menu
 [23:58:27 INFO]: /kick: A Mojang provided command.
 [23:58:27 INFO]: /kill: A Mojang provided command.
 [23:58:27 INFO]: /list: A Mojang provided command.
 [23:58:27 INFO]: /locate: A Mojang provided command.
 [23:58:27 INFO]: /me: A Mojang provided command.
 [23:58:27 INFO]: /minecraft:help: A Mojang provided command.
 [23:58:27 INFO]: /minecraft:reload: A Mojang provided command.
 [23:58:27 INFO]: /minecraft:tell: A Mojang provided command.
 [23:58:27 INFO]: /op: A Mojang provided command.
 [23:58:27 INFO]: /pardon: A Mojang provided command.
 [23:58:27 INFO]: /pardon-ip: A Mojang provided command.
 [23:58:27 INFO]: /particle: A Mojang provided command.
 [23:58:27 INFO]: /playsound: A Mojang provided command.
 [23:58:27 INFO]: /plugins: Gets a list of plugins running on the server
 [23:58:27 INFO]: /recipe: A Mojang provided command.
 [23:58:27 INFO]: /reload: Reloads the server configuration and plugins
 [23:58:27 INFO]: /replaceitem: A Mojang provided command.
 [23:58:27 INFO]: /restart: Restarts the server
 [23:58:27 INFO]: /save-all: A Mojang provided command.
 [23:58:27 INFO]: /save-off: A Mojang provided command.
 [23:58:27 INFO]: /save-on: A Mojang provided command.
 [23:58:27 INFO]: /say: A Mojang provided command.
 [23:58:27 INFO]: /scoreboard: A Mojang provided command.
 [23:58:27 INFO]: /seed: A Mojang provided command.
 [23:58:27 INFO]: /setblock: A Mojang provided command.
 [23:58:27 INFO]: /setidletimeout: A Mojang provided command.
 [23:58:27 INFO]: /setworldspawn: A Mojang provided command.
 [23:58:27 INFO]: /spawnpoint: A Mojang provided command.
 [23:58:27 INFO]: /spigot: Spigot related commands
 [23:58:27 INFO]: /spreadplayers: A Mojang provided command.
 [23:58:27 INFO]: /stats: A Mojang provided command.
 [23:58:27 INFO]: /stop: A Mojang provided command.
 [23:58:27 INFO]: /stopsound: A Mojang provided command.
 [23:58:27 INFO]: /summon: A Mojang provided command.
 [23:58:27 INFO]: /teleport: A Mojang provided command.
 [23:58:27 INFO]: /tell: A Mojang provided command.
 [23:58:27 INFO]: /tellraw: A Mojang provided command.
 [23:58:27 INFO]: /testfor: A Mojang provided command.
 [23:58:27 INFO]: /testforblock: A Mojang provided command.
 [23:58:27 INFO]: /testforblocks: A Mojang provided command.
 [23:58:27 INFO]: /time: A Mojang provided command.
 [23:58:27 INFO]: /timings: Manages Spigot Timings data to see performance of the server.
 [23:58:27 INFO]: /title: A Mojang provided command.
 [23:58:27 INFO]: /toggledownfall: A Mojang provided command.
 [23:58:27 INFO]: /tp: A Mojang provided command.
 [23:58:27 INFO]: /tps: Gets the current ticks per second for the server
 [23:58:27 INFO]: /trigger: A Mojang provided command.
 [23:58:27 INFO]: /version: Gets the version of this server including any plugins in use
 [23:58:27 INFO]: /weather: A Mojang provided command.
 [23:58:27 INFO]: /whitelist: A Mojang provided command.
 [23:58:27 INFO]: /worldborder: A Mojang provided command.
 [23:58:27 INFO]: /xp: A Mojang provided command.

実際の運用ではSystemdを使いたいため、設定を行います。

# vi /etc/systemd/system/spigot.service
 [Unit]
 Description=Spigot server
 After=network.target
 
 [Service]
 Type=simple
 User=minecraft
 WorkingDirectory=/home/minecraft/spigot_live
 ExecStart=/usr/bin/sh -c '/usr/bin/screen -DmS SpigotScreen /usr/bin/java -Xms1G -Xmx1G -XX:+UseG1GC -jar /home/minecraft/spigot_live/spigot-1.12.2.jar --noconsole'
 ExecStop=/usr/bin/screen -S SpigotScreen -X eval 'stuff "save-all"\\015'
 ExecStop=/usr/bin/screen -S SpigotScreen -X eval 'stuff "stop"\\015'
 
 TimeoutStartSec=15
 TimeoutStopSec=60
 Restart=on-failure
 
 [Install]
 WantedBy=multi-user.target

# systemctl daemon-reload

主な操作方法は次の通りです。
・起動させるとき
  # systemctl start spigot.service
・終了させるとき
  # systemctl stop spigot.service
・サーバ起動時に自動的に起動させるとき
  # systemctl enable spigot.service
・現在の状態を確認するとき
  # systemctl status spigot.service
・ログを確認するとき
  # journalctl -u spigot.service

Spigotの設定についてはWikiを参照して行います。
https://www.spigotmc.org/wiki/spigot/