房主说还是基岩版舒服,而且能跨平台游玩,好吧再搞个基岩版的。
基岩版部署显然简单多了,而且性能开销也小于 Java 版。
重要
Java 版本服务器部署见:大内网战略(9):LXC 容器搭建 Minecraft 服务器
警告
基岩版客户端的版本号也要和服务器的版本号对应。
备注
基岩版和 java 版存档互相转换:https://chunker.app/#
前置步骤&创建LXC容器
见大内网战略(9):LXC 容器搭建 Minecraft 服务器相应部分。内存可以给少点(我只给了1G)。
防火墙设置
需要放行端口,否则 Tailscale 会被阻挡。
必要安装
apt install unzip curl
部署服务端
新建文件夹
mkdir -p /opt/minecraft_br
cd /opt/minecraft_br
下载:
wget https://minecraft.azureedge.net/bin-linux/bedrock-server-1.20.81.01.zip
解压
unzip bedrock-server-1.20.81.01.zip
在 LXC 容器中使用 Tailscale
见大内网战略(9):LXC 容器搭建 Minecraft 服务器相应部分.
后台运行
方法一:Screen
启动新的 screen:
screen -R mc
# 注意如果有重名的会进入已有的
# 想要重名,将-r改成-S
启动 mc:
./bedrock_server
其他 screen 的操作见大内网战略(9):LXC 容器搭建 Minecraft 服务器相应部分。
方法二:Systemd (推荐)
本方法可以开机自启。
新建服务文件:
vim /etc/systemd/system/minecraft_br.service
输入以下内容:
[Unit]
Description=Minecraft Bedrock Server
After=network.target
[Service]
WorkingDirectory=/opt/minecraft_br
# Solves the issue where the minecraft server will endlessly restart itself
# See https://askubuntu.com/questions/953920/systemctl-service-timed-out-during-start for more info
Type=simple
PrivateUsers=true
# Users Database is not available from within the unit, only root and minecraft is available, everybody else is nobody
ProtectSystem=full
# Read only mapping of /usr /boot and /etc
ProtectHome=true
# /home, /root and /run/user seem to be empty from within the unit. It is recommended to enable this setting for all long-running services (in particular network-facing ones).
ProtectKernelTunables=true
# /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats, /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be read-only within the unit. It is recommended to turn this on for most services.
# Implies MountFlags=slave
ProtectKernelModules=true
# Block module system calls, also /usr/lib/modules. It is recommended to turn this on for most services that do not need special file systems or extra kernel modules to work
# Implies NoNewPrivileges=yes
ProtectControlGroups=true
# It is hence recommended to turn this on for most services.
# Implies MountAPIVFS=yes
ExecStart=/bin/sh -c './bedrock_server'
Restart=on-failure
RestartSec=60s
Sockets=minecraft_br.socket
StandardInput=socket
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
新建一个 socket:
vim /etc/systemd/system/minecraft_br.socket
输入内容:
[Unit]
PartOf=minecraft_br.service
[Socket]
ListenFIFO=%t/minecraft_br.stdin
然后
# 重新加载所有服务
systemctl daemon-reload
# 服务开机自启
systemctl enable minecraft_br.service
# 启动服务
systemctl start minecraft_br.service
# 如果不需要了
# 停止服务
systemctl stop minecraft_br.service
# 禁用开机自启
systemctl disable minecraft_br.service
# 删除服务&重新加载
rm /etc/systemd/system/minecraft_br.service && systemctl daemon-reload
读取日志:
# 最后的数字表示读取最近的多少行日志
journalctl -u minecraft_br -f -n 50
在 bash 中输入以下指令即可使用控制台:
# 替换掉双引号内的内容
echo "help" > /run/minecraft_br.stdin
echo "gamerule keepInventory true" > /run/minecraft_br.stdin
性能
2个人玩(注意客户端视野太大会增加服务器负载,我只开了16)
Comments NOTHING