Killing Floor 2

Killing Floor 2

Not enough ratings
在 Linux 系统中创建 Killing Floor 2 专用服务器
By soyoker
   
Award
Favorite
Favorited
Unfavorite
安装 SteamCMD
Ubuntu 系统
创建名为 steam 的用户以用于运行服务器端:
sudo useradd -m -s /bin/bash steam
安装 SteamCMD:
sudo add-apt-repository multiverse -y sudo dpkg --add-architecture i386 sudo apt update -y sudo apt-get remove needrestart -y echo steam steam/license note '' | sudo debconf-set-selections echo steam steam/question select "I AGREE" | sudo debconf-set-selections sudo apt install steamcmd -y
CentOS 系统
更多详细信息,请访问 SteamCMD Wiki
安装 Killing Floor 2 服务器端
下载安装 Killing Floor 2 服务端文件:
sudo -u steam /usr/games/steamcmd +login anonymous +app_update 232130 +quit
配置 Killing Floor 2 服务器端
在安装完服务端后,运行一次以生成默认配置文件:
/home/steam/Steam/steamapps/common/KFServer/Binaries/Win64/KFGameSteamServer.bin.x86_64 kf-bioticslab
简易配置版
只需配置 Web 控制台即可,其它服务器端的配置都可以通过访问 Web 控制台来修改,对于不熟悉 Linux 环境的推荐采用此种方法。
我们主要修改 KFWeb.ini 文件和 LinuxServer-KFGame.ini 文件来启用和配置 Web 控制台:
cd /home/steam/KFServer/KFGame/Config
sudo vim KFWeb.ini ... [IpDrv.WebServer] ... #为了安全起见,可以将默认的8080端口改为其他端口 ListenPort=8080 ... #启用 Web 控制台 bEnabled=true ...
sudo vim LinuxServer-KFGame.ini ... [Engine.AccessControl] ... #Web 管理后台与游戏管理员登录时用到的密码 AdminPassword= #游戏房间密码,可选项 GamePassword= ...
下表为搭建服务器所用到的所有端口,云服务器需要在安全组/防火墙放行以下端口通信:
端口类型
端口号
端口协议
用途说明
Game Port
7777
UDP
【必要】游戏服务主端口
Query Port
27015
UDP
【可选】用来控制服务器是否显示在公开服务器列表
Steam Port
20560
UDP
【可选】Steam 通信端口,主要控制工坊物品下载
NTP Port
123
UDP
【可选】仅适用于每周模式,用于与官方同步时间,开启每周任务
Web Admin
8080
TCP
【可选】Web 控制台的管理端口,默认为 8080
以下以阿里云为例,安全组设置如下:
最后访问 服务器地址:ListenPort,用户 Admin,密码 AdminPassword 来管理配置其它服务器参数。
安装 Killing Floor 2 社区模组
以安装伤害显示和自定义玩家人数模组为例子:
伤害显示:https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=2625647922
最大人数:https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=2143104493
找到需要的模组地址,记录下模组订阅 ID,编辑以下配置文件,请确保编辑前服务器端未在运行中。
sudo vim /home/ubuntu/KFServer/KFGame/Config/LinuxServer-KFEngine.ini ... [IpDrv.TcpNetDriver] ... #在所有 “DownloadManagers=” 最上方添加此行 DownloadManagers=OnlineSubsystemSteamworks.SteamWorkshopDownload ... ... [OnlineSubsystemSteamworks.KFWorkshopSteamworks] #在下面添加需要订阅的模组 ID ServerSubscribedWorkshopItems=2625647922 ServerSubscribedWorkshopItems=2143104493 ...
保存后,重新开启服务器端,等待服务器订阅的工坊模组下载成功,可查看 KFGame\Cache 目录下是否出现工坊 ID 名字的文件夹确定。
管理 Killing Floor 2 服务器端
  • 注册 Killing Floor 2 服务器端服务
默认情况下,Killing Floor 2 服务器端是前台运行的,只要我们离开当前运行界面,服务器端便会停止服务。
在大多数 Linux 中都包含 systemd 工具,我们将 Killing Floor 服务器端注册为服务,以此来方便的管理 Killing Floor 2 服务器端。
cat <<EOF > /usr/lib/systemd/system/kf2-server.service [Unit] Description=kf2-server.service After=network.target [Service] User=steam Restart=on-failure RestartSec=30s ExecStart=/home/steam/Steam/steamapps/common/KFServer/Binaries/Win64/KFGameSteamServer.bin.x86_64 kf-bioticslab [Install] WantedBy=multi-user.target EOF
保存退出后,我们就可以使用 systemctl 来管理 Killing Floor 2 服务器端进程:
命令
用途
systemctl start kf-server.service
启动 Killing Floor 2 服务器端
systemctl status kf-server.service
查看 Killing Floor 2 服务器端状态
systemctl stop kf-server.service
停止 Killing Floor 2 服务器端
systemctl restart kf-server.service
重启 Killing Floor 2 服务器端
为了防止系统重启后,Killing Floor 2 服务器端关闭,我们将 kf-server 服务设置为开机启动:
systemctl enable kf-server.service
部署 Killing Floor 2 服务器端脚本
#!/bin/bash echo "#----------------------------- check & add user -----------------------------" #以普通用户运行 steam 游戏服务器端 run_user=steam install_log=/tmp/pal_install.log # 使用compgen -u 判断用户是否存在 if compgen -u ${run_user} >/dev/null 2>&1; then echo "User ${run_user} exists." else echo "User ${run_user} does not exist.Adding ${run_user} ..." sudo useradd -m -s /bin/bash ${run_user} fi # 使用getent passwd 判断用户是否存在 # if getent passwd ${run_user} >/dev/null 2>&1; then # echo "User ${run_user} exists." #else # echo "User ${run_user} does not exist.Adding ${run_user} ..." # sudo useradd -m -s /bin/bash ${run_user} #fi # 使用 grep 判断用户是否存在 #if grep ${run_user} /etc/passwd >/dev/null 2>&1; then # echo "User ${run_user} exists." #else # echo "User ${run_user} does not exist.Adding ${run_user} ..." # sudo useradd -m -s /bin/bash ${run_user} #fi echo "-----------------------------adding steamcmd repository -----------------------------" sudo add-apt-repository multiverse -y sudo dpkg --add-architecture i386 sudo apt update -y sudo apt-get remove needrestart -y echo steam steam/license note '' | sudo debconf-set-selections echo steam steam/question select "I AGREE" | sudo debconf-set-selections echo "----------------------------- installing steamcmd -----------------------------" sudo apt install steamcmd -y >> ${install_log} echo "----------------------------- installing kf2-server -----------------------------" steamcmd_path=$(which steamcmd) user_home="/home/${run_user}" sudo -u steam /usr/games/steamcmd +login anonymous +app_update 232130 +quit echo "-----------------------------register kf2-server as service -----------------------------" service_unit=kf2-server cat <<EOF > /usr/lib/systemd/system/${service_unit}.service [Unit] Description=${service_unit}.service After=network.target [Service] User=steam Restart=on-failure RestartSec=30s ExecStart=/home/steam/Steam/steamapps/common/kf2server/Binaries/Win64/KFGameSteamServer.bin.x86_64 kf-bioticslab [Install] WantedBy=multi-user.target EOF echo "-----------------------------Enable Web Console -----------------------------" sed -i "s/bEnabled=false/bEnabled=true/" /home/steam/Steam/steamapps/common/kf2server/KFGame/Config/KFWeb.ini echo "-----------------------------Set Password For Admin -----------------------------" sed -i "s/^AdminPassword=/AdminPassword=kfserver@cloud\!/" /home/steam/Steam/steamapps/common/kf2server/KFGame/Config/LinuxServer-KFGame.ini echo "-----------------------------Disable Takeover -----------------------------" sed -i "s/bUsedForTakeover=TRUE/bUsedForTakeover=FALSE/" /home/steam/Steam/steamapps/common/kf2server/KFGame/Config/LinuxServer-KFEngine.ini sudo systemctl enable ${service_unit} sudo systemctl start ${service_unit} if sudo systemctl is-active ${service_unit} then echo "${service_unit} 运行成功!" else echo "出错了,检查下${install_log}" fi echo "现在你可以使用 systemctl status kf2-server 来查看运行状态,systemctl restart kf2-server 来重启服务器端,记得在安全组放通相关端口!"