0%

Minecraft建服记录

Linux上手动安装1.19.2 Fabric服务端

不同服务端的区别参考Wiki

你也可以使用Docker快速安装:https://github.com/itzg/docker-minecraft-server

安装Java

1.18+需要Java17环境,安装步骤参考这篇文章

注意:CPU的指令集不同,需要下载的JDK也不同,可以使用如下命令查看

1
2
> arch
x86_64 #x64指令集

安装Fabric端

参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 创建文件夹
> mkdir minecraft
> cd minecraft

# 下载安装器
> wget https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.1/fabric-installer-0.11.1.jar

# 查看安装命令
> java -jar fabric-installer-0.11.1.jar help
...
server -dir <install dir, default current dir> -mcversion <minecraft version, default latest> -loader <loader version, default latest> -downloadMinecraft
Latest Version: 1.19.2
Latest Loader: 0.14.11

# 开始安装Fabric服务端
> java -jar fabric-installer-0.11.1.jar server -mcversion 1.19.2 -downloadMinecraft(下载原版核心)
...
Done, start server by running fabric-server-launch.jar
> rm -f fabric-installer-0.11.1.jar #删除安装器

> mv server.jar vanilla.jar
> mv fabric-server-launch.jar server.jar
> echo "serverJar=vanilla.jar" > fabric-server-launcher.properties
> java -jar server.jar #第一次启动
Unpacking...
[22:41:20] [main/INFO]: Loading Minecraft 1.19.2 with Fabric Loader 0.14.11
[22:41:20] [main/INFO]: Fabric is preparing JARs on first launch, this may take a few seconds...
[22:41:21] [main/INFO]: Loading 3 mods:
- fabricloader 0.14.11
- java 17
- minecraft 1.19.2
[22:41:21] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=file:/root/minecraft/libraries/net/fabricmc/sponge-mixin/0.11.4+mixin.0.8.5/sponge-mixin-0.11.4+mixin.0.8.5.jar Service=Knot/Fabric Env=SERVER
[22:41:26] [main/INFO]: Building unoptimized datafixer
[22:41:28] [main/ERROR]: Failed to load properties from file: server.properties
[22:41:29] [main/WARN]: Failed to load eula.txt
[22:41:29] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

# 同意EULA
> echo "eula=true" > eula.txt

# 配置服务端
> vim server.properties

各配置属性参考Wiki,常用的属性有:

  • online-mode=true 关闭正版验证

  • server-port=xxxxx 运行端口,玩家不需要在URL中输入默认的25565端口

  • white-list=true 启用白名单(如果不想让陌生人进入),whitelist.jsonops.json在成功启动Server后才会生成

    ops.json自动视为白名单,其格式为

    1
    2
    3
    4
    5
    6
    {
    "uuid":"xxxx"
    "name":"xxxx"
    "level":4
    "bypassesPlayerLimit": false
    }

    whitelist.json格式类似

  • motd:服务器介绍

  • 服务器图标:服务器图标必须为64x64,这里有一个好用的图标制作网站,下载后将图标重命名为server-icon.png,放在根目录

OP在游戏中使用/reload命令可以热加载server.properties中的某些属性,而不需要重启Server

存档自动备份

参考文章

在服务器运行时直接对/world文件夹备份是不安全的,因为此时存档可能是残缺的

应该用命令/save-off停止自动存档,/save-all手动保存所有内容,备份存档后再/save-on开启自动存档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
> mkfifo mc.fifo #创建命令管道
> mkdir saves #创建备份文件夹
> vim start.sh

#!/bin/bash
# Xmx指定最大堆内存
# Xms指定初始堆内存
tail -f mc.fifo | nohup java -Xmx850m -jar server.jar --nogui & #启动服务器

> chmod a+x start.sh
> vim auto-save.sh

#!/bin/bash
max_saves=20 #最多保留20个备份
while true; do
{
echo "say 开始自动备份"
echo save-off
echo save-all
echo "say 正在保存存档..."
}>mc.fifo
zip -qr saves/$(date +%Y-%m-%d-%H-%M-%S).zip world
{
echo save-on
echo "say 自动备份完成"
}>mc.fifo
cd saves
save_num=$(ls -l | wc -l)
if [ $save_num -gt $max_saves ]; then #删除过旧的备份
num=$(expr $save_num - $max_saves)
ls -tr | head -$num | xargs -i -n1 rm {}
fi
cd ..
sleep 1d #每天备份一次
done

> chmod a+x auto-save.sh

Minecraft,启动!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
> ./start.sh #将在根目录生成nohup.out日志
...
[23:43:15] [Worker-Main-5/INFO]: Preparing spawn area: 84%
[23:43:15] [Worker-Main-5/INFO]: Preparing spawn area: 85%
[23:43:16] [Worker-Main-1/INFO]: Preparing spawn area: 86%
[23:43:16] [Worker-Main-1/INFO]: Preparing spawn area: 86%
[23:43:17] [Worker-Main-1/INFO]: Preparing spawn area: 87%
[23:43:17] [Worker-Main-1/INFO]: Preparing spawn area: 87%
[23:43:18] [Worker-Main-1/INFO]: Preparing spawn area: 88%
[23:43:18] [Worker-Main-1/INFO]: Preparing spawn area: 88%
[23:43:19] [Worker-Main-1/INFO]: Preparing spawn area: 89%
[23:43:19] [Worker-Main-1/INFO]: Preparing spawn area: 89%
[23:43:20] [Worker-Main-1/INFO]: Preparing spawn area: 90%
[23:43:20] [Worker-Main-1/INFO]: Preparing spawn area: 90%
[23:43:21] [Worker-Main-1/INFO]: Preparing spawn area: 91%
[23:43:21] [Worker-Main-1/INFO]: Preparing spawn area: 92%
[23:43:22] [Worker-Main-1/INFO]: Preparing spawn area: 92%
[23:43:22] [Worker-Main-1/INFO]: Preparing spawn area: 93%
[23:43:23] [Worker-Main-1/INFO]: Preparing spawn area: 93%
[23:43:23] [Worker-Main-1/INFO]: Preparing spawn area: 94%
[23:43:24] [Worker-Main-1/INFO]: Preparing spawn area: 95%
[23:43:24] [Worker-Main-1/INFO]: Preparing spawn area: 96%
[23:43:25] [Worker-Main-1/INFO]: Preparing spawn area: 96%
[23:43:25] [Worker-Main-1/INFO]: Preparing spawn area: 96%
[23:43:26] [Worker-Main-1/INFO]: Preparing spawn area: 97%
[23:43:26] [Worker-Main-1/INFO]: Preparing spawn area: 98%
[23:43:27] [Worker-Main-1/INFO]: Preparing spawn area: 98%
[23:43:27] [Worker-Main-1/INFO]: Preparing spawn area: 99%
[23:43:28] [Worker-Main-1/INFO]: Preparing spawn area: 99%
[23:43:31] [Server thread/INFO]: Time elapsed: 114686 ms
[23:43:31] [Server thread/INFO]: Done (138.641s)! For help, type "help"
> nohup ./auto-save.sh & #开启自动备份