Hi,聆听·彼岸



听说,你是我最遥不可及的梦。
What should I do?
What should I do?
I think I'm going to fall in love with myself.

用dockerfile构建加部署我的世界基岩版服务器

发表于 2023-08-22| 分类于 笔记 | | 评论数

首先基岩版服务器去国际版官网下载。然后解压,在服务器根目录下写Dockerfile

FROM ubuntu:20.04

WORKDIR /mc
COPY . .

RUN bash repair.sh

ENTRYPOINT ["bash","./run.sh"]

修复脚本repair.sh

echo -e " deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse" > /etc/apt/sources.list
apt-get update
apt-get install --reinstall ca-certificates -y
echo -e " deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse" > /etc/apt/sources.list
apt-get update
apt-get install libcurl4-openssl-dev -y
apt-get install curl -y

然后,非常重要,非常重要,非常重要的事。
基岩版用的是udp协议,在云服务商那里打开19132端口(有本事的可以改),如果用宝塔的,宝塔也要开放19132端口,记得udp,然后docker部署的时候要有-p 19132:19132/udp
少一步网络都不通。
然后就没啥了,给一下我的配置
server.properties

server-name=jnuse
# Used as the server name
# Allowed values: Any string without semicolon symbol.

emit-server-telemetry=true

gamemode=survival
# Sets the game mode for new players.
# Allowed values: "survival", "creative", or "adventure"

force-gamemode=false
# force-gamemode=false (or force-gamemode is not defined in the server.properties)
# prevents the server from sending to the client gamemode values other
# than the gamemode value saved by the server during world creation
# even if those values are set in server.properties after world creation.
#
# force-gamemode=true forces the server to send to the client gamemode values
# other than the gamemode value saved by the server during world creation
# if those values are set in server.properties after world creation.

difficulty=normal
# Sets the difficulty of the world.
# Allowed values: "peaceful", "easy", "normal", or "hard"

allow-cheats=true
# If true then cheats like commands can be used.
# Allowed values: "true" or "false"

max-players=5
# The maximum number of players that can play on the server.
# Allowed values: Any positive integer

online-mode=false
# If true then all connected players must be authenticated to Xbox Live.
# Clients connecting to remote (non-LAN) servers will always require Xbox Live authentication regardless of this setting.
# If the server accepts connections from the Internet, then it's highly recommended to enable online-mode.
# Allowed values: "true" or "false"

allow-list=false
# If true then all connected players must be listed in the separate allowlist.json file.
# Allowed values: "true" or "false"

server-port=19132
# Which IPv4 port the server should listen to.
# Allowed values: Integers in the range [1, 65535]

server-portv6=19133
# Which IPv6 port the server should listen to.
# Allowed values: Integers in the range [1, 65535]

enable-lan-visibility=true
# Listen and respond to clients that are looking for servers on the LAN. This will cause the server
# to bind to the default ports (19132, 19133) even when `server-port` and `server-portv6`
# have non-default values. Consider turning this off if LAN discovery is not desirable, or when
# running multiple servers on the same host may lead to port conflicts.
# Allowed values: "true" or "false"

view-distance=32
# The maximum allowed view distance in number of chunks.
# Allowed values: Positive integer equal to 5 or greater.

tick-distance=4
# The world will be ticked this many chunks away from any player.
# Allowed values: Integers in the range [4, 12]

player-idle-timeout=0
# After a player has idled for this many minutes they will be kicked. If set to 0 then players can idle indefinitely.
# Allowed values: Any non-negative integer.

max-threads=8
# Maximum number of threads the server will try to use. If set to 0 or removed then it will use as many as possible.
# Allowed values: Any positive integer.

level-name=Bedrock level
# Allowed values: Any string without semicolon symbol or symbols illegal for file name: /\n\r\t\f`?*\\<>|\":

level-seed=
# Use to randomize the world
# Allowed values: Any string

default-player-permission-level=member
# Permission level for new players joining for the first time.
# Allowed values: "visitor", "member", "operator"

texturepack-required=false
# Force clients to use texture packs in the current world
# Allowed values: "true" or "false"

content-log-file-enabled=false
# Enables logging content errors to a file
# Allowed values: "true" or "false"

compression-threshold=1
# Determines the smallest size of raw network payload to compress
# Allowed values: 0-65535

compression-algorithm=zlib
# Determines the compression algorithm to use for networking
# Allowed values: "zlib", "snappy"

server-authoritative-movement=server-auth
# Allowed values: "client-auth", "server-auth", "server-auth-with-rewind"
# Enables server authoritative movement. If "server-auth", the server will replay local user input on
# the server and send down corrections when the client's position doesn't match the server's.
# If "server-auth-with-rewind" is enabled and the server sends a correction, the clients will be instructed
# to rewind time back to the correction time, apply the correction, then replay all the player's inputs since then. This results in smoother and more frequent corrections.
# Corrections will only happen if correct-player-movement is set to true.

player-movement-score-threshold=20
# The number of incongruent time intervals needed before abnormal behavior is reported.
# Disabled by server-authoritative-movement.

player-movement-action-direction-threshold=0.85
# The amount that the player's attack direction and look direction can differ.
# Allowed values: Any value in the range of [0, 1] where 1 means that the
# direction of the players view and the direction the player is attacking
# must match exactly and a value of 0 means that the two directions can
# differ by up to and including 90 degrees.

player-movement-distance-threshold=0.3
# The difference between server and client positions that needs to be exceeded before abnormal behavior is detected.
# Disabled by server-authoritative-movement.

player-movement-duration-threshold-in-ms=500
# The duration of time the server and client positions can be out of sync (as defined by player-movement-distance-threshold)
# before the abnormal movement score is incremented. This value is defined in milliseconds.
# Disabled by server-authoritative-movement.

correct-player-movement=false
# If true, the client position will get corrected to the server position if the movement score exceeds the threshold.

server-authoritative-block-breaking=false
# If true, the server will compute block mining operations in sync with the client so it can verify that the client should be able to break blocks when it thinks it can.

chat-restriction=None
# Allowed values: "None", "Dropped", "Disabled"
# This represents the level of restriction applied to the chat for each player that joins the server.
# "None" is the default and represents regular free chat.
# "Dropped" means the chat messages are dropped and never sent to any client. Players receive a message to let them know the feature is disabled.
# "Disabled" means that unless the player is an operator, the chat UI does not even appear. No information is displayed to the player.

disable-player-interaction=false
# If true, the server will inform clients that they should ignore other players when interacting with the world. This is not server authoritative.

client-side-chunk-generation-enabled=true
# If true, the server will inform clients that they have the ability to generate visual level chunks outside of player interaction distances.

block-network-ids-are-hashes=true
# If true, the server will send hashed block network ID's instead of id's that start from 0 and go up. These id's are stable and won't change regardless of other block changes.

disable-persona=false
# Internal Use Only

disable-custom-skins=false
# If true, disable players customized skins that were customized outside of the Minecraft store assets or in game assets. This is used to disable possibly offensive custom skins players make.

server-build-radius-ratio=Disabled
# Allowed values: "Disabled" or any value in range [0.0, 1.0]
# If "Disabled" the server will dynamically calculate how much of the player's view it will generate, assigning the rest to the client to build.
# Otherwise from the overridden ratio tell the server how much of the player's view to generate, disregarding client hardware capability.
# Only valid if client-side-chunk-generation-enabled is enabled

把改好了配置和Dockerfile的文件夹打包上传,开始构建

docker build -t mc:v1 . # 构建镜像
docker run -d -i -t -p 19132:19132/udp --name mc mc:v1

然后就大功告成了,连接服务器ip,端口是19132(默认端口)

# 死亡不掉落
/gamerule keepInventory true
# 设置管理员
op <name>

设置管理员也可以新建operators.txt,写入管理员的游戏名字


因为一开始切不进控制台所以引进了screen命令
基本screen用法: 在启动screen后,你将进入一个新的终端会话。在这个会话中,你可以执行所有常规的终端命令。以下是一些常用的screen命令

screen -S session_name # 创建一个具有自定义名称的新 screen 会话
screen -ls # 查看会话列表
screen -r session_name # 重新连接会话:当你重新连接服务器时,可以使用以下命令重新连接到之前分离的screen会话
screen -d session_name # 放后台
exit # 退出会话

然而并没有成功,所以我决定换个方法
新建一个run.sh

./bedrock_server
# tail -f /dev/null > 2
# sleep infinity

这样一般情况就会运行服务器,但是如果我exec进容器修改了这个sh就可以运行服务器控制台修改一下配置,完美!

错误提示:检查换行符风格是否为unix


满分是10分的话,这篇文章你给几分,您的支持将鼓励我继续创作!