使用 FXServer 搭建服务器端

FXServer分步搭建指南

服务器端分步搭建教程

Windows

先决条件

  1. 如果你想按照推荐的方式 克隆 基础服务器端数据,请使用 Git

安装

  1. 创建一个新目录(例如 C:\FXServer\server),这将用于服务器端程序文件。

  2. Windows服务器端构建列表下载当前推荐的 Windows master 分支构建程序。

  3. 将下载的文件解压缩到先前创建的目录中。

    • 3b. 使用任意第三方解压缩工具(例如 WinRAR 或 7-Zip)打开 .7z 文件。
  4. cfx-server-data Clone 到服务器端程序文件夹之外的新文件夹中,例如 C:\FXServer\server-data

    • 4b. git clone https://github.com/citizenfx/cfx-server-data.git server-data (要输入此命令,你需要打开命令提示符,按 Win + R,在弹出的运行对话框中输入cmd然后按回车键,请记住通过键入 cd C:\FXServer 将目录切换到你计划clone的目录。)
  5. 在你的server-data文件夹中创建一个server.cfg文件(将以下示例 server.cfg文件复制到该文件中)。

  6. 使用sv_licenseKey "licenseKeyGoesHere"在server.cfg 中设置许可证密钥。

  7. server-data 文件夹运行服务器。例如,在命令提示符 (cmd.exe) 窗口中运行:

    cd /d C:\FXServer\server-data
    C:\FXServer\server\FXServer.exe +exec server.cfg
    

    (仅当将目录更改为不同驱动器上的某个路径时才需要添加 /d 指令)


Linux

先决条件

  1. 如果你想按照推荐的方式 克隆 基础服务器端数据,请使用 Git
  2. 安装 xzxz-utils 包。

安装

  1. 创建一个新文件夹(例如 mkdir -p ~/FXServer/server),这将用于保存服务器端程序文件。
  2. Linux服务器端构建列表下载当前推荐的 Linux master 分支构建程序(复制推荐服务器端版本 URL 并使用 wget <url> 下载它)
  3. 使用 cd ~/FXServer/server && tar xf fx.tar.xz 将下载的文件解压缩到之前创建的目录(你需要安装 xz,在 Debian/Ubuntu 上在 xz-utils 包中)。
  4. cfx-server-data Clone 到服务器端程序文件夹之外的新文件夹中。
    示例:git clone https://github.com/citizenfx/cfx-server-data.git ~/FXServer/server-data
  5. 在你的server-data文件夹中创建一个server.cfg文件(将以下示例 server.cfg文件复制到该文件中)。
  6. 使用sv_licenseKey "licenseKeyGoesHere"在server.cfg 中设置许可证密钥。
  7. server-data 文件夹运行服务器端。
    cd ~/FXServer/server-data && bash ~/FXServer/server/run.sh +exec server.cfg

server.cfg

下面是一个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 basic-gamemode
ensure hardcap
ensure rconlog

# 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. This is not usually shown anywhere in listings.
sv_hostname "FXServer, but unconfigured"

# Set your server's Project Name
sets sv_projectName "My FXServer Project"

# Set your server's Project Description
sets sv_projectDesc "Default FXServer requiring configuration"

# 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!"

# Remove the `#` from the below line if you want your server to be listed as 'private' in the server browser.
# Do not edit it if you *do not* want your server listed as 'private'.
# Check the following url for more detailed information about this:
# https://docs.fivem.net/docs/server-manual/server-commands/#sv_master1-newvalue
#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

# enable OneSync (required for server-side state awareness)
set onesync on

# Server player slot limit (see https://fivem.net/server-hosting for limits)
sv_maxclients 48

# 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

常见问题

  • 如果提示resources found并且显示Failed to start resource则说明你没有cd到正确的文件夹路径。
  • 如果没有提示resources get started而且你也无法连接服务器(如timed out/connection refused),那么你没有添加+exec指令。
  • 如果提示no license key was specified则可能出现上述两个问题之一。
最后修改 2023年01月26日: 翻译服务器端手册 (8f628f2)