使用Velocity搭建子服

前几天开了一个我的世界服务器,但是买的服务器是4h4g的,内存有点不足,很快就被霍霍空了。想要加内存又贵的离谱。于是有了一个想法:通过Velocity端搭建子服务器(已老实,下次一定买雨云的)

  • 介绍与下载

Velocity is the modern, high-performance proxy. Designed with performance and stability in mind, it’s a full alternative to Waterfall with its own plugin ecosystem.

直白点来说就是代理端,可以让你的服务器划分各个子服务器。

需要代理端的几类用户:

1、我有一台服务器A,但是我担心暴露A的iP会受到攻击。

2、我的玩家很多,单个服务器性能不足,需要划分生存一区二区

3、要写教程骗积分的

从PaperMC下载(国内不推荐)

直接下载velocity3.4

  • 安装与配置
    这里以雨云的MCSM面板为例
    进入文件管理,删掉server.properties,上传velocity3.4.jar
    修改启动脚本为
java -jar velocity3.4.jar

返回,开启服务器。

服务端没有eula.txt,无需同意。运行成功后关闭服务器,打开文件管理,可见这个toml文件
这是服务器配置文件的汉化。

# 配置版本。请勿更改此项
config-version = "2.7"

# 代理服务器绑定端口
bind = "0.0.0.0:25565"

# MOTD,当玩家将你的服务器添加到他们的服务器列表时,将显示这串内容。
# 支持中文,但请将汉字转换为unicode编码
# 只接受MiniMessage格式。
motd = "<#09add3>一个Velocity服务器"

# 显示的最大玩家数量?(Velocity不支持控制在线玩家数量的上限,仅为显示值)
show-max-players = 500

# 是否启用正版验证
online-mode = true

# 是否强制执行代理新的公钥安全标准?
force-key-authentication = true

# 如果来自此代理的客户端的ISP/AS与来自Mojang的身份验证服务器的不同,
# 玩家将被踢出。这将阻止一些VPN和代理连接,但是一种较弱的保护形式。
prevent-client-proxy-connections = false

# 我们是否应该将IP地址和其他数据转发给后端服务器?
# 可用选项:
# - "none":不进行转发。所有玩家将显示是从代理连接的,并将具有离线模式UUID。
# - "legacy":以前BungeeCord兼容的格式转发玩家IP和UUID。
#   如果你运行的是使用Minecraft 1.12或更低版本的服务器,请使用这个。
# - "bungeeguard":以前BungeeGuard插件支持的格式转发玩家IP和UUID。
#    如果你运行的是使用Minecraft 1.12或更低版本的服务器,并且无法实现网络级别的防火墙(在共享主机上),请使用这个。
# - "modern":作为登录过程的一部分使用Velocity的原生转发来转发玩家IP和UUID。仅适用于Minecraft 1.13或更高版本。
player-info-forwarding-mode = "NONE"

# 如果你使用的是modern或BungeeGuard IP转发,请在这里配置密钥文件。
# 文件应该是UTF-8编码的,并且不为空。
forwarding-secret-file = "forwarding.secret"

# 是否显示你的服务器支持Forge?如果你运行的是模组服务器,我们建议开启这个。
# 如果你的网络持续运行一个模组包,考虑使用ping-passthrough = "mods"以获得更美观的服务器列表显示。
announce-forge = false

# 如果启用,并且代理处于在线模式,如果发生重复的连接尝试,Velocity将踢出任何在线的现有玩家。
kick-existing-players = false

# Velocity是否应该将服务器列表ping请求传递给后端服务器?
# 可用选项:
# - "disabled":不进行传递。velocity.toml和server-icon.png
#                  将决定初始的服务器列表ping响应。
# - "mods":只从你的后端服务器传递模组列表到响应中。
#                  尝试列表(或强制主机)中的第一个具有模组列表的服务器将被使用。如果没有可以联系的后端服务器,Velocity将不会显示任何模组信息。
# - "description":使用后端服务器的描述和模组列表。
#                  尝试列表(或强制主机)中第一个响应的服务器将被用于描述和模组列表。
# - "all":使用后端服务器的响应作为代理响应。如果没有服务器可以联系,将使用Velocity配置。
ping-passthrough = "DISABLED"

# 如果不启用,则玩家IP地址将在日志中被<ip address withheld>替换
enable-player-address-logging = true

[servers]
# 在这里配置你的服务器。每个键代表服务器的名称,值代表要连接的服务器的IP地址。
lobby = "127.0.0.1:30066"
factions = "127.0.0.1:30067"
minigames = "127.0.0.1:30068"

# 当玩家登录或被服务器踢出时,我们应该按什么顺序尝试服务器。
try = [
    "lobby"
]

[forced-hosts]
# 在这里配置你的强制主机。
"lobby.example.com" = [
    "lobby"
]
"factions.example.com" = [
    "factions"
]
"minigames.example.com" = [
    "minigames"
]

[advanced]
# Minecraft数据包需要有多大才进行压缩。将其设置为0将压缩所有数据包,
# 设置为-1将完全禁用压缩。
compression-threshold = 256

# 应该进行多少压缩(从0到9)。默认是-1,使用默认级别6。
compression-level = -1

# 客户端在最后一次连接后多久可以连接(以毫秒为单位)。默认为三秒。禁用此功能,请将其设置为0。
login-ratelimit = 3000

# 在这里指定连接超时的自定义超时时间。默认是五秒。
connection-timeout = 5000

# 在这里指定连接的读取超时时间。默认是30秒。
read-timeout = 30000

# 启用与HAProxy的PROXY协议的兼容性。如果你不知道这是用于什么的,那么不要启用它。
haproxy-protocol = false

# 在代理上启用TCP快速打开支持。需要在Linux上运行代理。
tcp-fast-open = false

# 在Velocity上启用BungeeCord插件消息通道支持。
bungee-plugin-message-channel = true

# 显示客户端对代理的ping请求。
show-ping-requests = false

# 默认情况下,Velocity将尝试优雅地处理用户意外断开与服务器的连接的情况,通过尝试将用户回退,
# 除了读取超时的情况。BungeeCord会断开用户连接。你可以禁用此设置以使用BungeeCord的行为。
failover-on-unexpected-server-disconnect = true

# 向1.13+客户端声明代理命令。
announce-proxy-commands = true

# 启用命令执行的日志记录
log-command-executions = false

# 启用记录玩家连接到代理、切换服务器和从代理断开连接的情况。
log-player-connections = true

# 允许接收通过Transfer数据包(Minecraft 1.20.5)从其他主机转移来的玩家。
accepts-transfers = false

[query]
# 是否启用响应GameSpy 4查询响应?
enabled = false

# 查询协监听端口
port = 25565

# 这是报告给查询服务的地图名称。
map = "Velocity"

# 是否默认显示插件在查询响应中
show-plugins = false

其中有几项需要我们注意的。
首先就是

bind = "0.0.0.0:25565"
和最后的
port = 25565

在这里,我们需要修改为服务器开放端口

online-mode = true

老生常谈的正版验证。即使子服务器未开启正版验证,这开了也是进不了服务器哒

player-info-forwarding-mode = "NONE"

这个高版本建议改为modern,否则ban-ip会导致所有人被ban,因为显示的是从同一个iP进入到游戏里的


[servers]
# 在这里配置你的服务器。每个键代表服务器的名称,值代表要连接的服务器的IP地址。
lobby = "127.0.0.1:30066"
factions = "127.0.0.1:30067"
minigames = "127.0.0.1:30068"

# 当玩家登录或被服务器踢出时,我们应该按什么顺序尝试服务器。
try = [
    "lobby"
]

[forced-hosts]
# 在这里配置你的强制主机。
"lobby.example.com" = [
    "lobby"
]
"factions.example.com" = [
    "factions"
]
"minigames.example.com" = [
    "minigames"
]

最重要的就是这一段。配置服务器的信息
前面三个是子服的iP,try中天下顺序,并删除[forced-hosts]中的内容
最后保存,可以选择上传server-icon.png
我的服务器配置如下

# Config version. Do not change this
config-version = "2.7"

# What port should the proxy be bound to? By default, we'll bind to all addresses on port 25565.
bind = "0.0.0.0:25565"

# What should be the MOTD? This gets displayed when the player adds your server to
# their server list. Only MiniMessage format is accepted.
motd = "<#09add3>A Velocity Server"

# What should we display for the maximum number of players? (Velocity does not support a cap
# on the number of players online.)
show-max-players = 500

# Should we authenticate players with Mojang? By default, this is on.
online-mode = false

# Should the proxy enforce the new public key security standard? By default, this is on.
force-key-authentication = true

# If client's ISP/AS sent from this proxy is different from the one from Mojang's
# authentication server, the player is kicked. This disallows some VPN and proxy
# connections but is a weak form of protection.
prevent-client-proxy-connections = false

# Should we forward IP addresses and other data to backend servers?
# Available options:
# - "none":        No forwarding will be done. All players will appear to be connecting
#                  from the proxy and will have offline-mode UUIDs.
# - "legacy":      Forward player IPs and UUIDs in a BungeeCord-compatible format. Use this
#                  if you run servers using Minecraft 1.12 or lower.
# - "bungeeguard": Forward player IPs and UUIDs in a format supported by the BungeeGuard
#                  plugin. Use this if you run servers using Minecraft 1.12 or lower, and are
#                  unable to implement network level firewalling (on a shared host).
# - "modern":      Forward player IPs and UUIDs as part of the login process using
#                  Velocity's native forwarding. Only applicable for Minecraft 1.13 or higher.
player-info-forwarding-mode = "NONE"

# If you are using modern or BungeeGuard IP forwarding, configure a file that contains a unique secret here.
# The file is expected to be UTF-8 encoded and not empty.
forwarding-secret-file = "forwarding.secret"

# Announce whether or not your server supports Forge. If you run a modded server, we
# suggest turning this on.
# 
# If your network runs one modpack consistently, consider using ping-passthrough = "mods"
# instead for a nicer display in the server list.
announce-forge = false

# If enabled (default is false) and the proxy is in online mode, Velocity will kick
# any existing player who is online if a duplicate connection attempt is made.
kick-existing-players = false

# Should Velocity pass server list ping requests to a backend server?
# Available options:
# - "disabled":    No pass-through will be done. The velocity.toml and server-icon.png
#                  will determine the initial server list ping response.
# - "mods":        Passes only the mod list from your backend server into the response.
#                  The first server in your try list (or forced host) with a mod list will be
#                  used. If no backend servers can be contacted, Velocity won't display any
#                  mod information.
# - "description": Uses the description and mod list from the backend server. The first
#                  server in the try (or forced host) list that responds is used for the
#                  description and mod list.
# - "all":         Uses the backend server's response as the proxy response. The Velocity
#                  configuration is used if no servers could be contacted.
ping-passthrough = "DISABLED"

# If not enabled (default is true) player IP addresses will be replaced by <ip address withheld> in logs
enable-player-address-logging = true

[servers]
# Configure your servers here. Each key represents the server's name, and the value
# represents the IP address of the server to connect to.
lobby = "*.*.*.*:24463"
factions = "*.*.*.*:24463"
minigames = "*.*.*.*:24463"

# In what order we should try servers when a player logs in or is kicked from a server.
try = [
    "lobby"
]



[advanced]
# How large a Minecraft packet has to be before we compress it. Setting this to zero will
# compress all packets, and setting it to -1 will disable compression entirely.
compression-threshold = 256

# How much compression should be done (from 0-9). The default is -1, which uses the
# default level of 6.
compression-level = -1

# How fast (in milliseconds) are clients allowed to connect after the last connection? By
# default, this is three seconds. Disable this by setting this to 0.
login-ratelimit = 3000

# Specify a custom timeout for connection timeouts here. The default is five seconds.
connection-timeout = 5000

# Specify a read timeout for connections here. The default is 30 seconds.
read-timeout = 30000

# Enables compatibility with HAProxy's PROXY protocol. If you don't know what this is for, then
# don't enable it.
haproxy-protocol = false

# Enables TCP fast open support on the proxy. Requires the proxy to run on Linux.
tcp-fast-open = false

# Enables BungeeCord plugin messaging channel support on Velocity.
bungee-plugin-message-channel = true

# Shows ping requests to the proxy from clients.
show-ping-requests = false

# By default, Velocity will attempt to gracefully handle situations where the user unexpectedly
# loses connection to the server without an explicit disconnect message by attempting to fall the
# user back, except in the case of read timeouts. BungeeCord will disconnect the user instead. You
# can disable this setting to use the BungeeCord behavior.
failover-on-unexpected-server-disconnect = true

# Declares the proxy commands to 1.13+ clients.
announce-proxy-commands = true

# Enables the logging of commands
log-command-executions = false

# Enables logging of player connections when connecting to the proxy, switching servers
# and disconnecting from the proxy.
log-player-connections = true

# Allows players transferred from other hosts via the
# Transfer packet (Minecraft 1.20.5) to be received.
accepts-transfers = false

[query]
# Whether to enable responding to GameSpy 4 query responses or not.
enabled = false

# If query is enabled, on what port should the query protocol listen on?
port = 25565

# This is the map name that is reported to the query services.
map = "Velocity"

# Whether plugins should be shown in query response by default or not
show-plugins = false

最后就是激动人心的时刻:开启服务器!

  • 演示
    运行服务器,输入服务器iP,可以搜索到服务器,可以正确加载
    代理端可以看到转发信息,服务端展示为代理iP(我没有设置Modern转发)

    可以在游戏内使用/server切换子服