如何搭建 GTA 5 私服 -FiveM 的搭建

本贴最后更新于 1834 天前,其中的信息可能已经时移俗易

打开官网( 文皆可),点击 下载服务端(非商业),如图所示
image.png

网页跳转到官方说明文档
image.png

该说明文档提供了安装在 Windows 和 Linux 上的方法,下面逐一介绍。

Windows

前提条件:

1.Visual C++ Redistributable 2019

2.Git

安装步骤

1.创建新文件夹为 D:\FxServer
image.png

2.下载最新 Windows 端服务器文件:artifacts server

image.png

3.解压下载的服务器文件到 FxServer 文件夹中
image.png

4.克隆 cfx-server-dataD:\FxServer 中,并重名名为 server-data,且与服务器文件夹 server 同级.命令:git clone https://github.com/citizenfx/cfx-server-data.git server-data
image.png

image.png

5.在 server-data 文件夹下创建 server.cfg 配置文件,文件内容来自 example server.cfg,内容如下:

# Only change the IP if you're using a server with multiple network interfaces, otherwise change the port only.
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

# These resources will start by default.
ensure mapmanager
ensure chat
ensure spawnmanager
ensure sessionmanager
ensure fivem
ensure hardcap
ensure rconlog
ensure scoreboard

# This allows players to use scripthook-based plugins such as the legacy Lambda Menu.
# Set this to 1 to allow scripthook. Do note that this does _not_ guarantee players won't be able to use external plugins.
sv_scriptHookAllowed 0

# Uncomment this and set a password to enable RCON. Make sure to change the password - it should look like rcon_password "YOURPASSWORD"
#rcon_password ""

# A comma-separated list of tags for your server.
# For example:
# - sets tags "drifting, cars, racing"
# Or:
# - sets tags "roleplay, military, tanks"
sets tags "default"

# A valid locale identifier for your server's primary language.
# For example "en-US", "fr-CA", "nl-NL", "de-DE", "en-GB", "pt-BR"
sets locale "root-AQ" 
# please DO replace root-AQ on the line ABOVE with a real language! :)

# Set an optional server info and connecting banner image url.
# Size doesn't matter, any banner sized image will be fine.
#sets banner_detail "https://url.to/image.png"
#sets banner_connecting "https://url.to/image.png"

# Set your server's hostname
sv_hostname "FXServer, but unconfigured"

# Nested configs!
#exec server_internal.cfg

# Loading a server icon (96x96 PNG file)
#load_server_icon myLogo.png

# convars which can be used in scripts
set temp_convar "hey world!"

# Uncomment this line if you do not want your server to be listed in the server browser.
# Do not edit it if you *do* want your server listed.
#sv_master1 ""

# Add system admins
add_ace group.admin command allow # allow all commands
add_ace group.admin command.quit deny # but don't allow quit
add_principal identifier.fivem:1 group.admin # add the admin to the group

# Hide player endpoints in external log output.
sv_endpointprivacy true

# Server player slot limit (must be between 1 and 32, unless using OneSync)
sv_maxclients 32

# Steam Web API key, if you want to use Steam authentication (https://steamcommunity.com/dev/apikey)
# -> replace "" with the key
set steam_webApiKey ""

# License key for your server (https://keymaster.fivem.net)
sv_licenseKey changeme

中文解释:

# 一般情况下不用修改!
# 只有使用多个服务器协议的时候才需要更改。默认的TCP和UDP端口为30120
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

# 默认启动资源。
start mapmanager
start chat
start spawnmanager
start sessionmanager
start fivem
start hardcap
start rconlog
start scoreboard
start playernames

# 允许玩家使用scripthook挂载的修改器,例如lambda菜单。
# 设置为0可以禁用。
sv_scriptHookAllowed 1

# 取消前面的#可以启动RCON,记住你更改的密码。
#rcon_password changeme			#一般用不到

# 服务器标签,中间用逗号隔开
# 例如:
# - sets tags "drifting, cars, racing"
# 或者:
# - sets tags "roleplay, military, tanks"
sets tags "default"

# 设置服务器横幅或者链接横幅的URL
# 大小没有限制,任何图像都可以.
#sets banner_detail "http://url.to/image.png"
#sets banner_connecting "http://url.to/image.png"

# 设置服务器名称
sv_hostname "My new FXServer!"

# 嵌套配置!一般不改。
#exec server_internal.cfg

# 服务器LOGO图标 (96x96 PNG文件)
#load_server_icon myLogo.png

# 可以在脚本中使用的封面。
set temp_convar "hey world!"

# #如果你不想服务器显示在FiveM网页服务器列表,可以把#号删掉。
#sv_master1 ""

# 只能让Steam或者第三方运营商进入你的FiveM服务器?
# 不要忘记Social Club也是第三方提供商!
# 一般不改
#sv_authMaxVariance 1
#sv_authMinTrust 5

# 添加系统管理员。
add_ace group.admin command allow # allow all commands
add_ace group.admin command.quit deny # but don't allow quit
add_principal identifier.steam:1 group.admin # add the admin to the group

# 在外部输出日志上不显示玩家的信息。
sv_endpointprivacy true

# 服务器人数设置 (必须在 1 到 32)
sv_maxclients 32

# 服务器密钥 (https://keymaster.fivem.net)
sv_licenseKey changeme

需要修改的几项有:
sv_hostname:服务器名称,随便写
load_server_icon:服务器列表显示的图标,去掉#表示开启,自定义图片必须是 96x96 分辨率的 png 图片而且放在 server-data 目录中与配置文件同级目录
add_principal identifier.steam:根据注册的账号 ID 添加管理员

6.去 FiveM 论坛注册账户

7.再去获取服务器密钥(序列号申请次数无上限)
image.png

image.png

8.申请序列号之后将 server.cfg 配置文件最后一项的 changeme 部分替换成上一步申请的序列号即可
image.png

9.打开终端,输入下面两句命令即可启动 FiveM 服务器:

cd  /d D:\FXServer\server-data
D:\FXServer\server\run.cmd +exec server.cfg

image.png

注意:若觉得每次启动服务器麻烦,可以新建一个 bat 文件,将上述两句命令粘贴进去,每次启动服务器的时候双击 bat 文件即可

Linux

由于 Linux 搭建方法与 Windows 大同小异,故整理了一个自动化部署脚本

#下载服务器文件
wget https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/1688-c814f804e64c28952269bc5abbac92d7c956f844/fx.tar.xz

#下载资源文件
git clone https://github.com/citizenfx/cfx-server-data.git server-data

#创建文件夹
mkdir -p /usr/local/src/FiveM/server

#解压服务器文件到指定文件夹
tar -xf fx.tar.xz -C /usr/local/src/FiveM/server

#复制资源文件到指定文件夹
cp -r server-data /usr/local/src/FiveM/

#创建配置文件
cat <<EOF >/usr/local/src/FiveM/server-data/server.cfg
# Only change the IP if you're using a server with multiple network interfaces, otherwise change the port only.
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

# These resources will start by default.
ensure mapmanager
ensure chat
ensure spawnmanager
ensure sessionmanager
ensure fivem
ensure hardcap
ensure rconlog
ensure scoreboard

# This allows players to use scripthook-based plugins such as the legacy Lambda Menu.
# Set this to 1 to allow scripthook. Do note that this does _not_ guarantee players won't be able to use external plugins.
sv_scriptHookAllowed 0

# Uncomment this and set a password to enable RCON. Make sure to change the password - it should look like rcon_password "YOURPASSWORD"
#rcon_password ""

# A comma-separated list of tags for your server.
# For example:
# - sets tags "drifting, cars, racing"
# Or:
# - sets tags "roleplay, military, tanks"
sets tags "default"

# A valid locale identifier for your server's primary language.
# For example "en-US", "fr-CA", "nl-NL", "de-DE", "en-GB", "pt-BR"
sets locale "root-AQ" 
# please DO replace root-AQ on the line ABOVE with a real language! :)

# Set an optional server info and connecting banner image url.
# Size doesn't matter, any banner sized image will be fine.
#sets banner_detail "https://url.to/image.png"
#sets banner_connecting "https://url.to/image.png"

# Set your server's hostname
sv_hostname "FXServer, but unconfigured"

# Nested configs!
#exec server_internal.cfg

# Loading a server icon (96x96 PNG file)
#load_server_icon myLogo.png

# convars which can be used in scripts
set temp_convar "hey world!"

# Uncomment this line if you do not want your server to be listed in the server browser.
# Do not edit it if you *do* want your server listed.
#sv_master1 ""

# Add system admins
add_ace group.admin command allow # allow all commands
add_ace group.admin command.quit deny # but don't allow quit
add_principal identifier.fivem:1 group.admin # add the admin to the group

# Hide player endpoints in external log output.
sv_endpointprivacy true

# Server player slot limit (must be between 1 and 32, unless using OneSync)
sv_maxclients 32

# Steam Web API key, if you want to use Steam authentication (https://steamcommunity.com/dev/apikey)
# -> replace "" with the key
set steam_webApiKey ""

# License key for your server (https://keymaster.fivem.net)
sv_licenseKey changeme

EOF

将脚本中的 changeme 替换成服务器密钥即可部署

启动服务

使用如下命令启动:

cd /usr/local/src/FiveM/server-data 
/usr/local/src/FiveM/server/run.sh +exec server.cfg

切记,不可用 /usr/local/src/FiveM/server/run.sh +exec /usr/local/src/FiveM/server-data/server.cfg 命令启动,会失败,具体原因未知

开机自启

为了做到开机自启,我采用了 Supervisor 的方式(使用 systemctl 方式会无限重启,原因未知):
先创建一个启动服务的脚本 /usr/local/src/FiveM/start.sh:

cd /usr/local/src/FiveM/server-data && /usr/local/src/FiveM/server/run.sh +exec server.cfg

然后在 Supervisor 的配置文件夹 /etc/supervisor/conf.d/ 中新建 FiveM 的启动文件 fivem.conf

[program:fivem]
command=/usr/bin/bash /usr/local/src/FiveM/start.sh
directory=/usr/local/src/FiveM
user=root
stdout_logfile=/var/log/fivem.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT

最后使用 supervisorctl reload,选择 y 即可开机自启 FiveM 服务

[root@centos ~]# supervisorctl status
fivem                            RUNNING   pid 3316, uptime 5:24:59

实时日志如下(每三分钟发一次心跳):

[root@centos ~]# tail /var/log/fivem.log -f
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110
Sending heartbeat to live-internal.fivem.net:30110

连接情况(若是云服务器或者是非本机的电脑需要添加 30120 的 TCP 和 UDP 入站规则):

[root@VM_0_7_centos ~]# lsof -i:30120
COMMAND    PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
ld-musl-x 3317 root   28u  IPv4 36571478      0t0  TCP VM_0_7_centos:30120->150.116.85.124:55130 (ESTABLISHED)
ld-musl-x 3317 root   31u  IPv4 36470180      0t0  TCP *:30120 (LISTEN)
ld-musl-x 3317 root   33u  IPv6 36470181      0t0  UDP *:30120
ld-musl-x 3317 root   35u  IPv4 36476879      0t0  TCP VM_0_7_centos:30120->201.75.45.121:52624 (ESTABLISHED)
ld-musl-x 3317 root   36u  IPv4 36477004      0t0  TCP VM_0_7_centos:30120->67.166.27.29:57882 (ESTABLISHED)
ld-musl-x 3317 root   37u  IPv4 36509773      0t0  TCP VM_0_7_centos:30120->adria.kvarteto.net:50084 (ESTABLISHED)
ld-musl-x 3317 root   38u  IPv4 36483951      0t0  TCP VM_0_7_centos:30120->cable-188-2-205-27.dynamic.sbb.rs:52447 (ESTABLISHED)
ld-musl-x 3317 root   39u  IPv4 36484090      0t0  TCP VM_0_7_centos:30120->49.230.56.194:50631 (ESTABLISHED)
ld-musl-x 3317 root   40u  IPv4 36571801      0t0  TCP VM_0_7_centos:30120->176.148.208.253:58608 (ESTABLISHED)
ld-musl-x 3317 root   41u  IPv4 36484632      0t0  TCP VM_0_7_centos:30120->179.219.232.155:55005 (ESTABLISHED)
ld-musl-x 3317 root   42u  IPv4 36488632      0t0  TCP VM_0_7_centos:30120->client-201.230.158.233.speedy.net.pe:13723 (ESTABLISHED)
ld-musl-x 3317 root   43u  IPv4 36489318      0t0  TCP VM_0_7_centos:30120->112.201.139.65.pldt.net:ema-sent-lm (ESTABLISHED)
ld-musl-x 3317 root   44u  IPv4 36504202      0t0  TCP VM_0_7_centos:30120->cpc69049-oxfd25-2-0-cust839.4-3.cable.virginm.net:55972 (ESTABLISHED)
ld-musl-x 3317 root   45u  IPv4 36509900      0t0  TCP VM_0_7_centos:30120->106.203.63.106:64732 (ESTABLISHED)
ld-musl-x 3317 root   46u  IPv4 36490560      0t0  TCP VM_0_7_centos:30120->177.155.219.25:58726 (ESTABLISHED)
ld-musl-x 3317 root   47u  IPv4 36510686      0t0  TCP VM_0_7_centos:30120->187.21.113.230:51463 (ESTABLISHED)
ld-musl-x 3317 root   48u  IPv4 36509557      0t0  TCP VM_0_7_centos:30120->pc-252-52-100-190.cm.vtr.net:50904 (ESTABLISHED)
ld-musl-x 3317 root   49u  IPv4 36492966      0t0  TCP VM_0_7_centos:30120->170.254.133.248:4657 (ESTABLISHED)
ld-musl-x 3317 root   50u  IPv4 36512199      0t0  TCP VM_0_7_centos:30120->93-86-107-145.dynamic.isp.telekom.rs:58530 (ESTABLISHED)
ld-musl-x 3317 root   51u  IPv4 36523715      0t0  TCP VM_0_7_centos:30120->c-71-193-90-215.hsd1.mn.comcast.net:64846 (ESTABLISHED)
ld-musl-x 3317 root   52u  IPv4 36515098      0t0  TCP VM_0_7_centos:30120->37.236.124.65:60517 (ESTABLISHED)
ld-musl-x 3317 root   53u  IPv4 36524821      0t0  TCP VM_0_7_centos:30120->ppp-223-24-144-28.revip6.asianet.co.th:11693 (ESTABLISHED)
ld-musl-x 3317 root   54u  IPv4 36522366      0t0  TCP VM_0_7_centos:30120->c-98-192-236-150.hsd1.de.comcast.net:58986 (ESTABLISHED)
ld-musl-x 3317 root   55u  IPv4 36522517      0t0  TCP VM_0_7_centos:30120->190.200.255.39:17832 (ESTABLISHED)
ld-musl-x 3317 root   56u  IPv4 36525992      0t0  TCP VM_0_7_centos:30120->cm-27-145-135-149.revip12.asianet.co.th:52631 (ESTABLISHED)
ld-musl-x 3317 root   57u  IPv4 36531724      0t0  TCP VM_0_7_centos:30120->73.126.70.158:50722 (ESTABLISHED)
ld-musl-x 3317 root   58u  IPv4 36555357      0t0  TCP VM_0_7_centos:30120->cpc139088-jarr15-2-0-cust109.16-2.cable.virginm.net:52928 (ESTABLISHED)
ld-musl-x 3317 root   59u  IPv4 36531740      0t0  TCP VM_0_7_centos:30120->c-174-50-61-97.hsd1.la.comcast.net:52188 (ESTABLISHED)
ld-musl-x 3317 root   60u  IPv4 36551137      0t0  TCP VM_0_7_centos:30120->187.21.84.137:65142 (ESTABLISHED)
ld-musl-x 3317 root   61u  IPv4 36555172      0t0  TCP VM_0_7_centos:30120->77.202.162.69:54845 (ESTABLISHED)
ld-musl-x 3317 root   62u  IPv4 36563973      0t0  TCP VM_0_7_centos:30120->199.199.246.200:63485 (ESTABLISHED)

注意:因为我是放在云服务器上的,所以刚搭建完没多久就有客户端连接上来了

资源占用情况:
image.png

  • FiveM
    1 引用 • 2 回帖
  • GTA
    2 引用 • 3 回帖
  • 游戏

    沉迷游戏伤身,强撸灰飞烟灭。

    176 引用 • 815 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...