> 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 服务器，以便进行集中日志管理、归档和合规。

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 系统向同一个收集器转发时，这会产生歧义。常见主机名模式：

| 模式                                 | 示例输出                          | 用途                |
| ---------------------------------- | ----------------------------- | ----------------- |
| `%HOSTNAME%`                       | `node1`                       | 单个系统              |
| `mycluster-%HOSTNAME%`             | `mycluster-node1`             | 每个系统一个前缀；推荐用于多个系统 |
| `%HOSTNAME%.mycluster.example.com` | `node1.mycluster.example.com` | FQDN 风格           |
| {% endhint %}                      |                               |                   |

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/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
