> For the complete documentation index, see [llms.txt](https://docs.verge.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verge.io/knowledge-base/zh/troubleshooting/configuring-remote-log-forwarding.md).

# 配置远程日志转发（Syslog）

可以将 VergeOS 配置为将日志转发到远程 Syslog 服务器；对于利用日志聚合进行集中管理、日志归档和合规的组织而言，这是一项重要能力。

{% hint style="success" %}
**日志保留**

已记录的活动通常可在 VergeOS 用户界面中保留，最长为 **45 天**。配置远程日志转发可使日志保留更长时间。
{% endhint %}

## 先决条件

* VergeOS 与远程 syslog 服务器之间的网络连通性
* 适当的防火墙规则，以允许 syslog 流量（通常为 514 端口）
* 可访问 VergeOS 系统设置

## 配置步骤

要将日志转发配置到远程 syslog 服务器：

### 1. 导航到高级设置

导航到 **系统 > 设置 > 高级设置**.

### 2. 配置远程 Syslog 服务器

1. 在“Setting”列标题下，输入 `syslog` 并按 **Enter** 以搜索
2. 选择并编辑 **远程 syslog 服务器（tcp: @@name/ip:port, udp: @name/ip:port）**
3. 根据远程服务器期望的语法配置此设置：

{% hint style="info" %}
**服务器配置示例**

* **对于 TCP：** `@@10.10.10.10:514`
* **对于 UDP：** `@10.10.10.10:514`
  {% endhint %}

{% hint style="info" %}
**选择 TCP 或 UDP**

* **TCP（`@@`)** 提供可靠投递；请将其用于审计和合规日志。
* **UDP（`@`)** 是“发送即忘”：开销更低，但在负载下消息可能丢失。
  {% endhint %}

{% hint style="info" %}
**收集器端口**

监听 514 端口需要收集器具有 root 权限。许多收集器以非特权方式运行（例如在容器中），并监听端口 **1514** 。请输入收集器正在监听的端口。
{% endhint %}

4. 单击 **提交** 页面底部以保存

### 3. 配置格式模板

1. 搜索 `syslog` 再次在设置中
2. 选择并编辑 **用于定义 syslog 服务器的模板（格式请参见 rsyslog）**
3. 输入与远程 syslog 服务器兼容的 syslog 模板格式

{% hint style="info" %}
**模板示例**

```plaintext
   RFC5424,"<%PRI%>1 %TIMESTAMP:::date-rfc3339% %HOSTNAME%.your-hostname-here %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n"
```

{% endhint %}

{% hint style="warning" %}
请使用字面上的 `1` 后 `<%PRI%>` ——它是 RFC 5424 版本字段。不要使用 `%PROTOCOL-VERSION%`：它在传输线上会被渲染为 `0` ，而严格的 RFC 5424 收集器（Promtail/Loki、Fluent Bit、现代 Graylog）会因解析错误而拒绝版本 0。
{% endhint %}

{% hint style="info" %}
将 `your-hostname-here` 替换为你的实际主机名，或者保留为 `.HOSTNAME_HERE` 以使用默认系统主机名。
{% endhint %}

{% hint style="info" %}
**从多个 VergeOS 系统转发**

`%HOSTNAME%` 解析为裸节点名称（`node1`, `node2`），这在多个 VergeOS 系统转发到同一收集器时会产生歧义。常见的主机名模式：
{% endhint %}

| 模式                                 | 示例输出                          | 使用                |
| ---------------------------------- | ----------------------------- | ----------------- |
| `%HOSTNAME%`                       | `node1`                       | 单个系统              |
| `mycluster-%HOSTNAME%`             | `mycluster-node1`             | 每个系统一个前缀；建议用于多个系统 |
| `%HOSTNAME%.mycluster.example.com` | `node1.mycluster.example.com` | FQDN 风格           |

4. 单击 **提交** 在页面底部保存格式

## 收集器说明

上面的 RFC 5424 模板适用于常见收集器：

| 收集器           | 配置说明                                                            |
| ------------- | --------------------------------------------------------------- |
| Graylog       | 使用一个 **Syslog TCP** 或 **Syslog UDP** 输入。                        |
| Loki          | 使用 Promtail `syslog` 抓取作业；Promtail 需要严格的 RFC 5424（字面上的 `1` 版本）。 |
| Splunk        | 使用 TCP 或 UDP 数据输入，或者使用 Splunk Connect for Syslog。               |
| Elasticsearch | 通过 Logstash 使用 `syslog` 输入插件摄取。                                 |
| rsyslog 中继    | 使用标准 `imtcp` 或 `imudp` 侦听器。                                     |

## 附加资源

有关 syslog 模板和格式选项的更多信息，请访问 [Rsyslog 文档](https://www.rsyslog.com/doc/master/configuration/examples.html).

## 验证

保存配置后，VergeOS 会开始向指定服务器转发日志。检查收集器以确认 VergeOS 日志已到达。

如果日志未到达：

1. 在收集器主机上，抓取配置的 syslog 端口上的流量，以确认数据包到达（替换 `514` 为你配置的端口）：

   ```bash
   tcpdump -i any -A port 514
   ```
2. 检查捕获到的消息以验证线上的格式。RFC 5424 消息以 `<PRI>1` （例如， `<30>1 2026-04-15T...`）；版本为 `0` 表示模板仍在使用 `%PROTOCOL-VERSION%` ——参见上面的模板警告。
3. 确保 VergeOS 与收集器之间的防火墙规则允许所配置的端口和协议。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.verge.io/knowledge-base/zh/troubleshooting/configuring-remote-log-forwarding.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
