乐趣区

关于docker:Docker里的泰拉瑞亚来开黑

筹备

  1. docker 装置,参考之前 docker 中部署开源的接口管理工具 doclever 中的 docker 装置局部,本篇环境 wsl2 的 ubuntu 零碎。
  2. 泰拉瑞亚服务端文件,下载地址泰拉瑞亚服务端,如果链接生效,能够百度 泰拉瑞亚官网 找下载。

构建

  1. 筹备一个长期文件夹,将下载的服务端文件解压后,只须要 copy linux 版本进来就行。

    $ mkdir temp
    # 给这个文件加上执行权限
    $ chmod +x linux/TerrariaServer.bin.x86_64
    $ cp linux temp/linux
  2. 创立 Dockerfile,与 linux 同级目录

    $ vim Dockerfile
  3. 编辑 Dockerfile

    # 申明根底镜像,我这里用的 ubuntu,大略 80m
    FROM ubuntu:latest AS base
    # 在 COPY 命令后,扭转容器的默认门路,这里间接进入到游戏文件根目录
    WORKDIR /usr/local/tserver
    # 将来裸露 7777 端口,因为泰拉瑞亚服务端端口默认 7777,没非凡必要不须要批改
    EXPOSE 7777
    # 将本地游戏文件复制到 ubuntu 的门路下
    COPY ./linux /usr/local/tserver 
    # 当容器运行后执行的开服命令
    # ./TerrariaServer.bin.x86_64   可执行文件
    # -config 指定游戏配置文件
    # serverconfig.txt 游戏服务器配置文件
    ENTRYPOINT ["./TerrariaServer.bin.x86_64","-config","serverconfig.txt"]
  4. 创立游戏服务器配置文件,在 linux 目录下,与游戏文件同级

    $ vim serverconfig.txt

    文件放到文章的最初,配置依据须要自行批改,我这里配置的是:

    1. 指定地图名称 TerrariaMaster1423.wld
    2. 指定地图加载门路 ./Worlds/
    3. 端口 7777
    4. 服务器明码 xxxx
    5. 最大玩家数 8 人
    6. 地图难度 大师级
    7. 地图尺寸 小型

  5. 所有准备就绪,构建开始

    # 不要遗记开端有个句点,这是示意从当前目录寻找 Dockerfile
    $ docker build -t 1423_master_smallworld:v1 . 

开黑

  1. 测试启动

    $ docker run --rm -it 1423_master_smallworld:v1

  2. 正式启动

    # -it 启动后进入 docker 容器外部
    # --rm 当容器进行后删除容器
    # -p 端口映射到物理机
    # -v 卷映射,将游戏存档长久化到物理机硬盘上
    $ docker run -it --rm -p 7777:7777 -v /home/xsf/temp/Worlds:/usr/local/tserver/Worlds 1423_master_smallworld:v1 

    至于为什么肯定须要 -it 而不是 -d 至于后盾启动,因为游戏服务的限度,必须前置终端输入,否则会启动失败
    如果须要在近程服务器上启动,须要用 screen 或 tmux 配合启动,因为当敞开近程后,服务会主动敞开(没有守护过程)

游戏成果

服务端:

客户端:


玩起来!!

后记

  1. 须要批改开服配置能够 clone 源文件

    xiaoshangfei/TerrariaServer1423(github.com),自行批改 serverconfig.txt。

  2. 不想麻烦的就间接下载 docker 镜像运行

    $ docker pull xiaoshangfei911213/1423_master_smallworld
  3. 游戏服务器配置文件(参考)
#this is an example config file for TerrariaServer.exe
#use the command 'TerrariaServer.exe -config serverconfig.txt' to use this configuration or run start-server.bat
#please report crashes by emailing crashlog.txt to support@terraria.org

#the following is a list of available command line parameters:

#-config <config file>                            Specifies the configuration file to use.
#-port <port number>                              Specifies the port to listen on.
#-players <number> / -maxplayers <number>    Sets the max number of players
#-pass <password> / -password <password>        Sets the server password
#-world <world file>                    Load a world and automatically start the server.
#-autocreate <#>                    Creates a world if none is found in the path specified by -world. World size is specified by: 1(small), 2(medium), and 3(large).
#-banlist <path>                    Specifies the location of the banlist. Defaults to "banlist.txt" in the working directory.
#-worldname <world name>                         Sets the name of the world when using -autocreate.
#-secure                        Adds addition cheat protection to the server.
#-noupnp                        Disables automatic port forwarding
#-steam                            Enables Steam Support
#-lobby <friends> or <private>                Allows friends to join the server or sets it to private if Steam is enabled
#-ip <ip address>                    Sets the IP address for the server to listen on
#-forcepriority <priority>                Sets the process priority for this task. If this is used the "priority" setting below will be ignored.
#-disableannouncementbox                Disables the text announcements Announcement Box makes when pulsed from wire.
#-announcementboxrange <number>                Sets the announcement box text messaging range in pixels, -1 for serverwide announcements.
#-seed <seed>                        Specifies the world seed when using -autocreate

#remove the # in front of commands to enable them.

#Load a world and automatically start the server.
world=./Worlds/TerrariaMaster1423.wld

#Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large).
autocreate=1

#Sets the world seed when using autocreate
seed=AwesomeSeed

#Sets the name of the world when using autocreate
worldname=TerrariaMaster1423

#Sets the difficulty of the world when using autocreate 0(classic), 1(expert), 2(master), 3(journey)
difficulty=2

#Sets the max number of players allowed on a server.  Value must be between 1 and 255
maxplayers=8

#Set the port number
port=7777

#Set the server password
password=xxxx

#Set the message of the day
motd=Please don�t cut the purple trees!

#Sets the folder where world files will be stored
worldpath=./Worlds/

#Sets the number of rolling world backups to keep
worldrollbackstokeep=2

#The location of the banlist. Defaults to "banlist.txt" in the working directory.
#banlist=banlist.txt

#Adds addition cheat protection.
#secure=1

#Sets the server language from its language code. 
#English = en-US, German = de-DE, Italian = it-IT, French = fr-FR, Spanish = es-ES, Russian = ru-RU, Chinese = zh-Hans, Portuguese = pt-BR, Polish = pl-PL,
language=zh-Hans

#Automatically forward ports with uPNP
#upnp=1

#Reduces enemy skipping but increases bandwidth usage. The lower the number the less skipping will happen, but more data is sent. 0 is off.
#npcstream=60

#Default system priority 0:Realtime, 1:High, 2:AboveNormal, 3:Normal, 4:BelowNormal, 5:Idle
priority=1

#Reduces maximum liquids moving at the same time. If enabled may reduce lags but liquids may take longer to settle.
#slowliquids=1

#Journey mode power permissions for every individual power. 0: Locked for everyone, 1: Can only be changed by host, 2: Can be changed by everyone
#journeypermission_time_setfrozen=2
#journeypermission_time_setdawn=2
#journeypermission_time_setnoon=2
#journeypermission_time_setdusk=2
#journeypermission_time_setmidnight=2
#journeypermission_godmode=2
#journeypermission_wind_setstrength=2
#journeypermission_rain_setstrength=2
#journeypermission_time_setspeed=2
#journeypermission_rain_setfrozen=2
#journeypermission_wind_setfrozen=2
#journeypermission_increaseplacementrange=2
#journeypermission_setdifficulty=2
#journeypermission_biomespread_setfrozen=2
#journeypermission_setspawnrate=2
退出移动版