搭建linuxgsm托管的求生之路2服务器
我使用的是Linux系统来跑求生之路2服务器端,因此使用了Linux上一个专门用于搭建游戏服务端的软件:Linux Game Server Managers
教程步骤基本遵循Linux Game Server Managers的官方教程来就可以了:
LinuxGSM L4D2板块:https://linuxgsm.com/lgsm/l4d2server/
<img src='' align='left'/>Ubuntu 16.04 LTS
<img src='' align='left'/>Debian 8
<img src='' align='left'/>Centos 7
注意:我使用的系统是Ubuntu 18 LTS x64,下列步骤基本都是基于Ubuntu 64位的.
一、选定自己要使用的系统
进入系统后使用对应系统的命令进行更新系统.
我所使用的是Ubuntu 64位,对应的命令是
sudo apt-get update && sudo apt-get upgrade
在使用后会提示Do you want to continue?,输入Y回车同意就好.
二、使用对应的命令来安装依赖库
点击左侧第二项Dependencies,右侧会出现三个系统的图标,选择你所使用的对应系统,然后复制给出的命令进行安装依赖项.
此处因为我使用的是Ubuntu 64位,所以使用Ubuntu 64位系统的命令来安装依赖库:
<img src='' align='left'/>Ubuntu 64:
sudo dpkg --add-architecture i386; sudo apt update; sudo apt install mailutils postfix curl wget file tar bzip2 gzip unzip bsdmainutils python util-linux ca-certificates binutils bc jq tmux lib32gcc1 libstdc++6 lib32stdc++6 steamcmd
在这个过程中会出现各个软件的安装界面:

steamcmd:第一个是声明,OK即可,第二个是询问是否同意协议,选择第二个"I AGREE"即可


三、创建专用账户
当依赖库都安装好之后,LinuxGSM就可以着手开始安装了.这里我们是搭建L4D2的服务器端,所以安装LinuxGSM for L4D2,一样官方同样有教程,跟着来就好了:
首先创建一个专用账户,用于跑l4d2server
ubuntu使用useradd创建帐户:
useradd的用法:
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options]
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
--extrausers Use the extra users database
我们使用如下命令创建一个用户名为"l4d2server",密码为"l4d2server"的帐户,同时在home下创建它的目录,:
sudo useradd -G root -m -r -s /bin/bash l4d2server
这里不推荐使用-p参数直接设置密码是因为-p参数要求后面的设置密码为加密后的密文,因此如果直接设置明文密码,例如"l4d2server"创建帐户后,是无法使用"l4d2server"来登录的,所以不推荐使用-p参数来设置密码,而是通过root帐户使用passwd来设置密码:
sudo passwd l4d2server
然后会出现提示"Enter new UNIX password",输入要修改的密码(输入密码时不会密码显示),输入完成后按回车提交,然后会提醒"Retype new UNIX password",要求再次输入密码,再输入一次设置的密码,然后回车提交,完成修改密码.
四、修改登录方式以及配置防火墙
1. 修改登录方式为密钥登录,并禁用密码登录:
分别为root帐户和l4d2server帐户创建密钥登录.
使用命令创建公玥和密钥:
ssh:keygen
然后会提示:
Enter file in which to save the key (/home/l4d2server/.ssh/id_rsa):"
这句话的意思是你希望把生成的密钥对放在哪个位置,默认的是:/root/.ssh/id_rsa 默认就好,所以我们这里直接回车就好。
Enter passphrase (empty for no passphrase):
这句话的意思是是否设置双重认证,就是为你的私钥添加一个密码,如果图方便,直接回车就好,如果为了更加安全,设置个简单密码就好。 如果设置了双重认证,需要再一次确认密码
完成之后使用sftp软件(如xftp)登录到服务器,在/root/.ssh/中将密钥文件下载到本地,这个密钥就相当于钥匙,用于登录.
然后配置SSHD,启用密钥登录,禁用密码登录:
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys //这一步是把生成的公钥导入到ssh的配置文件中
chmod 600 authorized_keys //以防万一,我们给予文件更高的权限
chmod 700 /root/.ssh
vim /etc/ssh/sshd_config //打开ssh配置文件
//找到PubkeyAuthentication(在第37行),默认的话,是被注释的,并且为no,我们把注释去掉,并且改为yes,开启密钥登陆 //找到PasswordAuthentication(在第56行),默认的话,是被注释的,并且为yes,我们把注释去掉,并且改为no,关闭密码登陆 //该文件中有port参数,这可以修改SSH的登录端口
service sshd restart //重启ssh服务
首先切换到l4d2server帐户,并转到l4d2server的目录:
su l4d2server
cd ~
mkdir ./.ssh
chmod 700 ./.ssh
然后这里说另一种方法生成密钥,使用xshell的用户密钥生成向导直接生成密钥:
打开xshell,工具-新建用户密钥生成向导



密钥名称一般填写密钥对应的登录账户,下面是否加密是可选的.

如果不设置加密,会出现该提示,点击"是"即可

然后将此处的公玥全部复制

然后回到云服务器,进入对应的帐户,例如刚才的l4d2server,然后进入刚才创建的.ssh目录:
su l4d2server
cd ~/.ssh/
然后创建对应文件存放刚才的公玥:
vim ~/.ssh/authorized_keys
按insert(ins)进入编辑模式,然后把刚才复制的公玥粘贴在文件内,然后再按ESC进入命令模式输入"wq"回车保存退出.
再重启一下sshd即可:
service sshd restart
2. 配置防火墙
Ubuntu使用UFW来配置防火墙,UFW非常简单,在此就不再解答使用方法,记得放行对应端口即可,L4D2所需的端口一般是:
TCP:27015-27016、27060
UDP:27015-27016、27036
五、安装LinuxGSM for L4D2
同样跟着官方的教程来操作即可:
首先切换到专用账号并切换到账号目录,我是使用的l4d2server:
su l4d2server
cd ~
然后输入官方给出的一键脚本:
wget -O linuxgsm.sh https://linuxgsm.sh && chmod +x linuxgsm.sh && bash linuxgsm.sh l4d2server
下载脚本完成后会提醒你使用以下命令安装:
./l4d2server install

复制给出命令粘贴回车执行:
然后开始安装,第一个询问"是否继续",直接回车确定:

之后便会检测依赖库是否完整,如果不完整会自动安装,安装完依赖库之后会自动下载L4D2服务端:

安装完成后会有提示:

然后会询问一次是否允许匿名统计使用信息,默认允许,之后就完成了L4D2服务端的安装:

六、安装插件平台
先切换到专用账户,并来到其目录下:
su l4d2server
cd ~
然后使用LinuxGSM安装插件平台:
./l4d2server mi
//按照提示安装metamod和sourcemod
七、配置服务器
LinuxGSM for L4D2中,LGSM使用和来配置L4D2的启动参数,而用来控制L4D2服务端本身的参数.
1. 配置LGSM

该文件夹内有三个文件,存放了LGSM的默认配置,不可修改则是LGSM for L4D2的相关设置,则存放了L4D2的启动参数以及最大玩家数量等.在此我给出我的和的配置:
##################################
######## Common Settings #########
##################################
# PLACE GLOBAL SETTINGS HERE
## These settings will apply to all instances
## LinuxGSM Stats
# Send useful stats to LinuxGSM developers.
# https://docs.linuxgsm.com/configuration/linuxgsm-stats
# (on|off)
stats="on"
## Updating | https://docs.linuxgsm.com/commands/update
updateonstart="on"
(stats="on"是开启监控,updateonstart="on"是开启每次启动服务器时检查更新,可以关掉,每次开启比较费时间)
##################################
####### Instance Settings ########
##################################
# PLACE INSTANCE SETTINGS HERE
## These settings will apply to a specific instance
## Server Start Command | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters
fn_parms(){
parms="-game left4dead2 -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -tickrate 100 -nomaster +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
}
## Server Start Settings | https://docs.linuxgsm.com/configuration/start-parameters
maxplayers="8"
(其中加入了"-tickrate 100"、"-nomaster"两个参数,第一个参数是用于设置服务器的tickrate为100,第二个参数是隐藏服务器,以免被炸服狗DDOS攻击.)
2. 配置
是L4D2服务器本身的参数,用于设置游戏服务器名称、游戏服务器所属steam组、是否开放、是否允许大厅连接等功能。
注意,在LGSM中,默认名为
输入./l4d2server dt
可以查看lgsm设定的的路径和名称:

可以看到Config file是在/home/l4d2server/serverfiles/left4dead2/cfg/目录下,名为
给出我的配置,在LGSM中为:
//--> This is the name for your server
hostname "[HK]第三方投票换地图换模式"
sv_steamgroup 11223344
sv_search_key ""
sv_steamgroup_exclusive 0
rcon_password "yourRCONpassword"
sv_tags "hidden"
//Allow connections without creating lobby (connect IP:PORT)
//--> "0" = Off
//--> "1" = On
sv_allow_lobby_connect_only 0
sm_cvar sb_all_bot_game 1
//--> All talk - Allow both teams to use audio chat to speak with each other
//--> "0" = Off
//--> "1" = On
sv_alltalk 1
sv_region 255
sv_cheats 0
sv_contact "your@"
//--> Admin Contact email address to display on serverinfo.
// Log Settings
log on
sv_logecho 0
sv_logfile 1
sv_log_onefile 0
sv_logbans 1
sv_logflush 0
sv_logsdir logs
//sm_cvar mp_gamemode versus
//--> sourcemod override forcing gamemod.
//--> versus, survival, scavenge, coop.
// Some tweaking
//--> Remove the clamp.
sm_cvar sv_client_cmdrate_difference 0
// Rate Settings.By tickrate-enabler
sm_cvar sv_minrate 100000
sm_cvar sv_maxrate 100000
sm_cvar sv_minupdaterate 100
sm_cvar sv_maxupdaterate 100
sm_cvar sv_mincmdrate 100
sm_cvar sv_maxcmdrate 100
sm_cvar sv_client_min_interp_ratio -1
sm_cvar sv_client_max_interp_ratio 0
sm_cvar nb_update_frequency 0
sm_cvar net_splitrate 2
sm_cvar fps_max 0
sm_cvar net_splitpacket_maxrate 50000
// Admin Menu plugins
sm_cvar bind i "show_menu Menu"
// Execute ban files
exec banned_user.cfg
exec banned_ip.cfg
writeid
writeip
要想服务器为中文名,记得该文件保存为UTF-8-BOM编码才行.
3. 配置
配置该文件设置管理员:在求生之路游戏中控制台中输入status以查看自己的steamid,例如我得到的信息就是:
5794 1 "z282846139" STEAM_1:1:124906097 00:28 97 0 active 30000
其中STEAM_1:1:124906097便是我的steamid,将其填入即可,如下:
// Examples: (do not put // in front of real lines, as // means 'comment')
//
// "STEAM_0:1:16" "bce" //generic, kick, unban for this steam ID, no immunity
// "!" "99:z" //all permissions for this ip, immunity value is 99
// "BAILOPAN" "abc" "Gab3n" //name BAILOPAN, password "Gab3n": gets reservation, generic, kick
//
"!" "99:z" //all permissions for this ip, immunity value is 99
"STEAM_1:1:124906097" "99:z" //all permissions for this ip, immunity value is 99
八、安装插件Tickrate使服务器更流畅
上面的配置文件中其实我已经将Tickrate插件的配置参数写在里面了,是基于Tickrate100的:
Tickrate插件链接:
tickrate-enabler:https://github.com/Satanic-Spirit/Tickrate-Enabler
Get TickRate:https://forums.alliedmods.net/showthread.php?t=73925
1. Tickrate-Enabler:
该插件解锁游戏的tick值,使游戏传输更多的数据流,会得到更流畅的游戏体验
到Tickrate-Enabler的Github页面,在Releases中找到下载并解压,会得到一个文件夹,里面有两个子文件夹:Package-l4d和Package-l4d2,分别用于L4D1和L4D2:

打开Package-l4d2,会看见一个addons文件夹:

将该文件夹完整上传至服务器的/home/l4d2server/serverfiles/left4dead2/addons,如下图:

至此,Tickrate-Enabler安装完成,游戏也启用了100tick,服务器游戏会更加流畅,但是注意这样会消耗更多的网络带宽,请注意服务器带宽,在游戏控制台中输入net_graph 4
开启游戏网络状况统计,留意游戏中loss和choke值,它显示你目前网络情况,loss表示丢包,choke表示拥堵,一般loss勉强能够忍受(移动用户常态),如果出现choke则表明网络发生拥堵,这时候卡顿会非常明显。

2. Get TickRate:
该插件在玩家输入sm_gettickrate
后反馈给玩家当前服务器的tick值,可以直接在控制台中输入,也可以在聊天窗口中在前面加上感叹号!输入

结语
至此,一个tickrate为100的求生之路纯净服搭建完成。有什么疑问或者指正请在评论区指出。