本文只讲 Linux 系统开服。用 Windows 的朋友请转:《CS2 开服保姆级教程(Windows版)》→ https://z0w.cn/wiki/cs2-server-guide-windows.html
Linux 系统准备见:《Linux 云服务器开服通用前置教程》→ https://z0w.cn/wiki/linux-gameserver-setup.html
CS2 服务端在 Linux 上是官方原生支持的,Valve 给的文档就以 Ubuntu 为例,这比很多只有 Windows 版的生存游戏省心多了。
一、开服前必读:三个坑
坑 1:AppID 是 730,不是 740
CS:GO 时代服务端是 740,CS2 把客户端和服务端合并成 730。任何教你 app_update 740 或跑 srcds_run 的教程都是过时的。
坑 2:没 GSLT 就不公开
去 https://steamcommunity.com/dev/managegameservers 用 App ID 730 免费申请 Game Server Login Token。没有它,服务端只能局域网跑。
坑 3:磁盘 80G 起,且需要 glibc 2.31+
系统要求 Ubuntu 20.04 / Debian 11 / RHEL 9 以上。磁盘:服务端约 60G,加上更新余量、日志、备份,建议 100G。
二、配置与端口规划
| 项目 | 要求 |
|---|---|
| 系统 | Ubuntu 22.04 / 24.04(glibc ≥ 2.31) |
| CPU | 4 核高频(单核性能优先) |
| 内存 | 5v5:4-8G | 社区服:8-12G |
| 硬盘 | 80-100G NVMe |
端口表:
| 端口 | 协议 | 用途 | 必开 |
|---|---|---|---|
| 27015 | TCP + UDP | 连接 + 查询 | ✅ |
| 27020 | UDP | CSTV 观战(可选) | 按需 |
| 22 | TCP | SSH | ✅ |
三、准备系统环境
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl ca-certificates tar lib32gcc-s1 lib32stdc++6 ufw创建专用用户(别用 root 跑):
sudo adduser --disabled-password --gecos "" cs2
sudo install -d -o cs2 -g cs2 /opt/steamcmd
sudo install -d -o cs2 -g cs2 /opt/cs2
sudo -iu cs2四、安装 SteamCMD 并下载服务端
cd /opt/steamcmd
curl -fsSL https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz -o steamcmd_linux.tar.gz
tar -xzf steamcmd_linux.tar.gz
./steamcmd.sh +quit下载 CS2 服务端(约 60G,耗时较长):
/opt/steamcmd/steamcmd.sh \
+force_install_dir /opt/cs2 \
+login anonymous \
+app_update 730 validate \
+quitforce_install_dir 要放在 login 之前。确认二进制存在:
test -x /opt/cs2/game/bin/linuxsteamrt64/cs2 && echo "OK"
du -sh /opt/cs2五、保护 GSLT 令牌
不要把令牌明文写进 systemd unit 或截图。用环境变量文件:
exit # 回到 root
sudo install -d -m 700 -o root -g root /etc/cs2
sudo nano /etc/cs2/cs2.env写入一行:
CS2_GSLT=你的32位令牌sudo chown root:root /etc/cs2/cs2.env
sudo chmod 600 /etc/cs2/cs2.env六、配置 server.cfg
sudo install -d -o cs2 -g cs2 /opt/cs2/game/csgo/cfg
sudo -u cs2 nano /opt/cs2/game/csgo/cfg/server.cfghostname "我的CS2服务器"
sv_password ""
rcon_password "你的RCON密码"
sv_lan 0
sv_cheats 0
sv_hibernate_when_empty 0
log on
mp_autoteambalance 1
mp_limitteams 1
exec banned_user.cfg
exec banned_ip.cfg
writeid
writeipsudo chmod 600 /opt/cs2/game/csgo/cfg/server.cfg七、systemd 服务(推荐方式)
创建 /etc/systemd/system/cs2.service:
[Unit]
Description=Counter-Strike 2 Dedicated Server
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=cs2
Group=cs2
WorkingDirectory=/opt/cs2/game/bin/linuxsteamrt64
EnvironmentFile=/etc/cs2/cs2.env
ExecStart=/opt/cs2/game/bin/linuxsteamrt64/cs2 -dedicated -console -usercon -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2 +sv_setsteamaccount ${CS2_GSLT} +exec server.cfg
Restart=on-failure
RestartSec=10
KillSignal=SIGINT
TimeoutStopSec=90
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target⚠️ systemd 里${CS2_GSLT}的写法要注意:Typecho/Shell 不会展开,systemd 的 EnvironmentFile 配合${}是可以的,但如果启动失败提示变量未展开,改成${CS2_GSLT}前加\$或直接把令牌写进 ExecStart(安全性降低)。
启动:
sudo systemctl daemon-reload
sudo systemctl enable --now cs2
sudo systemctl status cs2 --no-pager
sudo journalctl -u cs2 -n 150 --no-pager模式对照表:
| game_type | game_mode | 模式 |
|---|---|---|
| 0 | 0 | 休闲 |
| 0 | 1 | 竞技 |
| 1 | 0 | 军备竞赛 |
| 1 | 2 | 死亡竞赛 |
八、放行端口
sudo ufw allow OpenSSH
sudo ufw allow 27015/udp
sudo ufw allow 27015/tcp
# CSTV 按需
sudo ufw allow 27020/udp
sudo ufw enable检查监听:
sudo ss -lntup | grep -E ':27015|:27020'NAT 型服务器还要在服务商控制台映射 27015 的 TCP 和 UDP。详见:《NAT 端口映射完全指南》→ https://z0w.cn/wiki/nat-port-forwarding-guide.html
九、连接服务器
客户端控制台输入:
connect 外网IP:外网端口十、自动更新
/opt/steamcmd/update.sh:
#!/bin/bash
systemctl stop cs2
sudo -iu cs2 /opt/steamcmd/steamcmd.sh +force_install_dir /opt/cs2 +login anonymous +app_update 730 +quit
systemctl start cs2sudo chmod +x /opt/steamcmd/update.sh
sudo crontab -e
# 每周一凌晨 5 点更新
0 5 * * 1 /opt/steamcmd/update.sh十一、常见问题
Q:systemd 报 GSLT 变量未展开?
检查 EnvironmentFile 路径和权限;确认 unit 里写的是 ${CS2_GSLT};改完 daemon-reload 再重启。
Q:服务器搜不到?
GSLT 是否正确、sv_lan 0、27015 的 TCP 和 UDP 是否都放行(很多人只开了 UDP)。
Q:只用 SteamCMD 装了一半就停了?
磁盘空间不足,df -h 检查。
Q:报缺 libstdc++?sudo apt install lib32gcc-s1 lib32stdc++6。
Q:开机不自动启动?sudo systemctl enable cs2 没执行,或 unit 文件路径不对。
十二、总结
| 项目 | 值 |
|---|---|
| AppID | 730 |
| 端口 | TCP + UDP 27015 |
| 启动方式 | game/bin/linuxsteamrt64/cs2 -dedicated |
| 系统要求 | glibc ≥ 2.31(Ubuntu 20.04+) |
| 守护 | systemd |
| 磁盘 | 80-100G |
📌 收藏备用,有问题评论区见。
我们家的云服务器 NVMe 固态 + 高频 CPU,跑 128tick 无压力;NAT 型价格更省,控制台自助映射端口 → 财富云计算 https://z0w.cn
延伸阅读
- 网站环境怎么选:LNMP 手动 / 宝塔面板 / Docker / 云开发
- 问卷表单系统搭建:SurveyKing / Formbricks,数据自己收
- 图床搭建:Lsky Pro / Lychee,自托管图片托管方案
- 邮件列表搭建:listmonk 自托管 Newsletter,把读者握在自己手里
- 文档站点搭建:MkDocs / VuePress / Docsify,产品文档与技术手册方案
- RSS 阅读器搭建:FreshRSS 自托管,把信息流拿回自己手里
- 短链接服务搭建:Shlink 自托管,链接数据自己掌握
- 网站状态监控页搭建:Uptime Kuma,服务器挂了第一时间知道

[...]这是本站长期维护的游戏配置与教程总索引。想开服,先在这页搞清楚两件事:你的游戏要吃多少配置、你的系统该看哪篇教程。建议收藏——换游戏、加 MOD、人数变多时,回来核对一遍能省掉大部分"卡爆了"和"连不上"。搭配阅读:还没买服务器?先看购前决策索引(预算分级 / NAT vs 独立 IP / 避坑清单);端口映射看不懂?先看端口速查表(40+ 游戏端口协议一页查清)。一、全游戏配置需求速查表下表按"[...]
2026-10-18 回复