
Wazuh 5.0 Syslog 输入迁移指南从 remoted 到 rsyslog Logcollector 的完整实践【免费下载链接】wazuhWazuh - The Open Source Security Platform. Unified XDR and SIEM protection for endpoints and cloud workloads.项目地址: https://gitcode.com/GitHub_Trending/wa/wazuh导读Wazuh 从 4.x 升级到 5.0 后manager 的remoted模块不再接收网络设备防火墙、路由器、交换机发送的原始 syslog 消息该能力被移除模块现在只处理加密的 agent 连接。要继续收集网络设备的 syslog必须在一台收集主机上部署 rsyslog 接收消息并在该主机上安装 Wazuh agent由 agent 的 logcollector 将日志转发给 Wazuh server。本文基于官方迁移文档完整讲解Option Arsyslog → journald → logcollector与Option Brsyslog → 日志文件 → logcollector两条迁移路径涵盖配置映射、rsyslog 配置、agent 配置、验证方法、decoder/rule 兼容性及完整迁移示例并结合仓库源码说明底层原理。迁移背景4.x 到 5.x 发生了什么变化在 Wazuh 4.x 中manager 的remoted模块通过connectionsyslog/connection配置直接监听 514 端口接收网络设备防火墙、路由器、交换机的原始 syslog 消息。从源码结构看remoted模块src/remoted在 5.0 中已经不再包含 syslog 接收相关实现其连接类型固定为secure参见 src/remoted/src/config.c 中cJSON_AddStringToObject(conn, connection, secure)即仅处理加密的 agent 连接。这意味着没有自动化的迁移工具你必须手动配置 rsyslog并在 syslog 收集主机上安装 Wazuh agent。下表汇总了两代版本在 syslog 采集链路上的差异方面Wazuh 4.xWazuh 5.xSyslog 接收端Managerremoted端口 514外部 syslog 守护进程rsyslog日志摄入直接进入analysisd经由 Wazuh agent logcollector配置位置Managerossec.conf的remote块rsyslog 配置 agentossec.conf主机上的 Wazuh agent不需要必需 —— 5.0 中 agent 不随 manager 自动安装IP 白名单/黑名单ossec.conf中的allowed-ips/denied-ipsrsyslog$AllowedSender或主机防火墙规则架构对比Wazuh 4.xNetwork device ──(UDP/TCP port 514)──► Wazuh manager (remoted) ──► analysisdWazuh 5.x —— Option AjournaldNetwork device ──(UDP/TCP port 514)──► rsyslog (omjournal) ──► systemd journal │ Wazuh agent (logcollector) │ Wazuh manager (analysisd)Wazuh 5.x —— Option B日志文件Network device ──(UDP/TCP port 514)──► rsyslog ──► /var/log/remote/host.log │ Wazuh agent (logcollector) │ Wazuh manager (analysisd)两种方案如何选择Option A —— journaldOption B —— 日志文件Agent 配置变更无 —— Wazuh agent 默认读取 journald需要localfile块按主机过滤通过 journald 字段_HOSTNAME等通过文件路径/var/log/remote/host.log操作系统要求基于 systemd 的 Linux 主机任意 Linux 主机rsyslog 模块omjournal—— 在 rsyslog 8.x 上自定义模板可能静默失败内置文件输出Option A 更易于运维journald 自动处理日志保留retentionagent 无需额外配置即可读取。Option B 可移植性更强适用于无 systemd 的系统且每个主机有独立日志文件便于人工检查。配置映射4.x → 5.x迁移的核心是将原来 managerossec.conf中remote块的各项配置映射到 rsyslog 配置与 agent 配置4.xossec.conf5.x 对应项方案remote.connectionsyslogrsyslogimudp/imtcp输入模块两者remote.portrsysloginput端口两者remote.protocolrsyslogimudpUDP或imtcpTCP两者remote.allowed-ipsrsyslog$AllowedSender或防火墙规则两者remote.denied-ips主机防火墙规则iptables/firewalld两者syslog 直接转发给analysisdrsyslogomjournal→ journald 读取器Option Asyslog 直接转发给analysisdagentlocalfile监控日志文件Option BWazuh 4.xossec.conf参考配置!-- Wazuh 4.x manager ossec.conf -- ossec_config remote connectionsyslog/connection port514/port protocoludp/protocol allowed-ips192.168.1.0/24/allowed-ips /remote /ossec_config这段配置是 4.x 网络设备 syslog 采集的入口connectionsyslog开启 raw syslog 接收port514监听标准 syslog 端口protocoludp指定传输协议allowed-ips限制允许发送日志的源网段。迁移到 5.0 后这三项能力分别由 rsyslog 输入模块imudp/imtcp、输入端口和防火墙规则承担。前置条件两种方案通用开始迁移前请确认Wazuh 5.0 或更高版本已完整部署indexer、manager、dashboard一台运行 rsyslog 的 Linux 主机 —— 可以是 Wazuh manager 所在主机也可以是专用服务器该主机已安装 rsyslog网络设备已配置为向该主机 IP 的 514 端口发送 syslog已在 syslog 收集主机上安装 Wazuh agent见下文安装 Wazuh agent重要在 Wazuh 5.0 中Wazuh agent不会随 manager 自动安装。即使 rsyslog 与 Wazuh manager 运行在同一台主机上也必须在该主机上单独安装并注册一个 Wazuh agent。从 Wazuh dashboard 进入Agent management - Summary点击Deploy new agent填写相关信息使用生成的命令安装 agent。如果 agent 与 manager 运行在同一主机manager 地址填写127.0.0.1。安装后启用并启动 agent 服务sudo systemctl daemon-reload sudo systemctl enable wazuh-agent sudo systemctl start wazuh-agentagent 会在几秒内出现在 Wazuh dashboard 的Agent management - Summary中Option Arsyslog → journald → logcollectorrsyslog 接收 syslog 消息后使用omjournal输出模块直接写入 systemd journal。Wazuh agent默认读取 journal无需额外的 agent 配置。重要systemd journal 中的_HOSTNAME字段是受信任字段—— journald 始终将其设置为本地主机的主机名任何应用程序包括 rsyslog都无法覆盖它。1. 安装 rsyslog journal 输出模块omjournal模块包含在大多数发行版的主 rsyslog 包中但有些发行版需要单独的包# Debian/Ubuntu sudo apt install rsyslog # RHEL/CentOS/Amazon Linux sudo yum install rsyslog2. 配置 rsyslog创建/etc/rsyslog.d/99-wazuh-remote.conf内容如下module(loadimudp) module(loadimtcp) module(loadomjournal) ruleset(nameremote_to_journal) { action(typeomjournal) } input(typeimudp port514 rulesetremote_to_journal) input(typeimtcp port514 rulesetremote_to_journal)注意如果不使用模板写入会成功但远程主机名不会出现在MESSAGE字段中。如果你在 Wazuh 4.x 中使用过allowed-ips限制可发送 syslog 的主机请在防火墙层面施加等效限制sudo firewall-cmd --permanent --add-rich-rulerule familyipv4 source address192.168.1.0/24 port port514 protocoludp accept sudo firewall-cmd --permanent --add-rich-rulerule familyipv4 source address192.168.1.0/24 port port514 protocoltcp accept sudo firewall-cmd --reload重启 rsyslog 使配置生效sudo systemctl restart rsyslog验证 rsyslog 正在监听 514 端口sudo ss -ulnp | grep 514 sudo ss -tlnp | grep 5143. 验证 journal 摄入从远程主机发送测试消息确认链路工作正常# 从远程设备或其他机器执行 logger -n SYSLOG_HOST_IP -P 514 --udp Test syslog message from migration在收集主机上确认消息已进入 journaljournalctl -fWazuh agent 会读取 journal ——无需修改/var/ossec/etc/ossec.conf。从源码层面看agent 的 logcollector 通过动态加载libsystemdsd_journal系列 API实现对 journal 的读取见 src/logcollector/src/journal_log.c 中的函数指针表包括w_journal_open、w_journal_seek_tail、w_journal_get_data等日志条目的 syslog 格式解析为$TIMESTAMP $HOSTNAME $SYSLOG_IDENTIFIER[$PID]: $MESSAGE见journal_log.c第 502 行附近。_HOSTNAME是 journald 写入的受信任字段logcollector 读取该字段作为事件主机名对应get_field_ptr(ctx, _HOSTNAME)。4. 验证事件出现在 dashboard 中在 Wazuh dashboard 中进入Explore - Discover。来自远程设备的事件将以wazuh.protocol.location: journald出现。与 Wazuh 4.x 中匹配你的设备的相同 decoders无需修改即可继续生效。Option Brsyslog → 日志文件 → logcollectorrsyslog 接收 syslog 消息并写入/var/log/remote/下按主机区分的日志文件Wazuh agent 通过localfile块监控这些文件。1. 配置 rsyslog创建/etc/rsyslog.d/99-wazuh-remote.conf内容如下module(loadimudp) module(loadimtcp) template(nameRemoteHostLogs typestring string/var/log/remote/%FROMHOST-IP%.log) ruleset(nameremote_to_file) { action(typeomfile dynaFileRemoteHostLogs) } input(typeimudp port514 rulesetremote_to_file) input(typeimtcp port514 rulesetremote_to_file)如果之前在 Wazuh 4.x 使用过allowed-ips请添加等效限制sudo firewall-cmd --permanent --add-rich-rulerule familyipv4 source address192.168.1.0/24 port port514 protocoludp accept sudo firewall-cmd --permanent --add-rich-rulerule familyipv4 source address192.168.1.0/24 port port514 protocoltcp accept sudo firewall-cmd --reload在启动 rsyslog 前先创建目标目录。在 Debian/Ubuntu 上rsyslog 会降权到非特权syslog用户该用户无法自行在/var/log下创建目录因此/var/log/remote必须预先存在且对该用户可写rsyslog 才能写入%FROMHOST-IP%文件在基于 RHEL 的系统上 rsyslog 以root运行会自动创建sudo install -d -o syslog -g adm /var/log/remote重启 rsyslog 使配置生效sudo systemctl restart rsyslog验证 rsyslog 正在监听 514 端口sudo ss -ulnp | grep 514 sudo ss -tlnp | grep 5142. 配置 Wazuh agent 监控 syslog 文件编辑 agent 的配置文件/var/ossec/etc/ossec.conf添加localfile块ossec_config localfile location/var/log/remote/*.log/location log_formatsyslog/log_format /localfile /ossec_config这一个块即可覆盖 rsyslog 在/var/log/remote/下写入的所有文件无论未来新增多少源主机都无需改动。消息格式与 Wazuh decoder 兼容性上述dynaFile方式使用 rsyslog 的默认消息格式其中包含 syslog 时间戳如Jun 3 08:14:22。Wazuh 内置的 syslog decoders 要求该时间戳作为第一个字段才能匹配。如果使用自定义消息模板必须在开头包含%timereported:::date-rfc3164%# 正确 —— 包含时间戳Wazuh syslog decoders 可匹配 template(nameMsgFmt typestring string%timereported:::date-rfc3164% %HOSTNAME% %app-name%[%procid%]: %msg%\n) action(typeomfile file/var/log/remote/syslog.log templateMsgFmt) # 错误 —— 无时间戳事件落入 wazuh-events-v5-unclassified-* 且无字段提取 template(nameMsgFmt typestring string%HOSTNAME% %app-name%[%procid%]: %msg%\n)缺少时间戳的事件会出现在 Wazuh dashboard 的wazuh-events-v5-unclassified-*索引中只有event.original被填充没有任何解码字段。重启 agent 使配置生效sudo systemctl restart wazuh-agent确认 logcollector 正在读取文件sudo grep logcollector /var/ossec/logs/ossec.log | grep remote预期输出2026/06/03 08:16:01 wazuh-logcollector: INFO: (1950): Analyzing file: log_file_configured.3. 验证事件出现在 dashboard 中在 Wazuh dashboard 中进入Explore - Discover按location: /var/log/remote/过滤。与 Wazuh 4.x 中匹配你的设备的相同 decoders无需修改即可继续生效。Decoder 与规则兼容性现有面向网络设备 syslog 的 Wazuh decoders 与 rules例如cisco-asa、pf、juniper在两种方案下都无需修改即可继续工作。rsyslog 转发的 syslog 消息体与 4.x 中remoted在 514 端口接收到的内容完全一致本次迁移不需要更新任何 decoder。注意在 Wazuh 4.x 中远程设备的源 IP 是可用的因为remoted直接接收连接。在 Wazuh 5.x 中agent 从本地文件或 journal 读取因此原始源 IP 只有在 rsyslog 记录它时才会被保留 —— 要么记录在文件路径中Option B 在dynaFile模板中使用%FROMHOST-IP%每个设备得到独立文件要么通过自定义模板属性如%fromhost-ip%作为消息的一部分。这一差异也解释了两种方案在按主机区分事件上的设计取舍journald 方案依赖_HOSTNAME等受信任字段注意它永远等于本地主机名文件方案则依赖%FROMHOST-IP%生成独立文件路径。完整迁移示例以下示例完整演示从 4.x 到 5.x 两种方案的迁移过程供实际部署对照。Wazuh 4.x 启用 syslog 的配置生成远程日志ubuntuubu24-2:~$ i22; while true; do logger -n 192.168.70.104 --rfc3164 -P 514 New remote log $i; ((i)); sleep 1; doneWazuh manager 配置配置/var/ossec/etc/ossec.conf启用远程 syslog 接收ossec_config remote connectionsyslog/connection port514/port protocoludp/protocol allowed-ips192.168.1.0/24/allowed-ips /remote /ossec_config在/var/ossec/etc/rules/local_rules.xml中添加规则以匹配远程日志group namesyslog,remote_test, rule id100002 level3 matchNew remote log/match descriptionRemote syslog test message/description /rule /group告警出现在/var/ossec/logs/alerts/alerts.log[wazuh-userwazuh-server ~]$ sudo tail -f /var/ossec/logs/alerts/alerts.log ** Alert 1780935033.426378: - syslog,remote_test, 2026 Jun 08 16:10:33 ubu24-2-192.168.70.105 Rule: 100002 (level 3) - Remote syslog test message from ubu24-2 Jun 8 13:10:24 ubu24-2 ubuntu: New remote log 1619 ** Alert 1780935036.426594: - syslog,remote_test, 2026 Jun 08 16:10:36 ubu24-2-192.168.70.105 Rule: 100002 (level 3) - Remote syslog test message from ubu24-2 Jun 8 13:10:26 ubu24-2 ubuntu: New remote log 1620 ** Alert 1780935038.426810: - syslog,remote_test, 2026 Jun 08 16:10:38 ubu24-2-192.168.70.105 Rule: 100002 (level 3) - Remote syslog test message from ubu24-2 Jun 8 13:10:29 ubu24-2 ubuntu: New remote log 1621dashboard 中可见的事件Wazuh 5.0 —— Option Arsyslog → journald生成远程日志ubuntuubu24-2:~$ i22; while true; do logger -n 192.168.70.104 -P 514 New remote log $i; ((i)); sleep 1; donersyslog 配置创建/etc/rsyslog.d/remote.conf将远程 syslog 转发到 systemd journalmodule(loadimudp) module(loadimtcp) module(loadomjournal) ruleset(nameremote_to_journal) { action(typeomjournal) } input(typeimudp port514 rulesetremote_to_journal) input(typeimtcp port514 rulesetremote_to_journal)远程日志出现在 journal 中ubuntuubuntu-VirtualBox:~$ journalctl -f Jun 08 15:55:49 ubuntu-VirtualBox ubuntu[99023]: New remote log 2138 Jun 08 15:55:51 ubuntu-VirtualBox ubuntu[99023]: New remote log 2139 Jun 08 15:55:53 ubuntu-VirtualBox ubuntu[99023]: New remote log 2140 Jun 08 15:55:55 ubuntu-VirtualBox ubuntu[99023]: New remote log 2141 Jun 08 15:55:57 ubuntu-VirtualBox ubuntu[99023]: New remote log 2284 Jun 08 15:55:59 ubuntu-VirtualBox ubuntu[99023]: New remote log 2285dashboard 中可见的事件Wazuh 5.0 —— Option Brsyslog → 日志文件生成远程日志ubuntuubu24-2:~$ i22; while true; do logger -n 192.168.70.104 --rfc3164 -P 514 New remote log $i; ((i)); sleep 1; doneWazuh agent 配置在收集主机的/var/ossec/etc/ossec.conf中添加localfile块ossec_config localfile log_formatsyslog/log_format location/var/log/*.log/location /localfile /ossec_configrsyslog 配置创建/etc/rsyslog.d/remote.conf将远程 syslog 转发到文件module(loadimudp) module(loadimtcp) template(nameRemoteSyslog typestring string%timereported:::date-rfc3164% %HOSTNAME% %app-name%[%procid%]: %msg%\n) ruleset(nameremote_syslog) { action(typeomfile file/var/log/remote-syslog.log templateRemoteSyslog) } input(typeimudp port514 rulesetremote_syslog) input(typeimtcp port514 rulesetremote_syslog)注意此模板以%timereported:::date-rfc3164%RFC3164 格式时间戳开头这正是 Wazuh 内置 syslog decoders 能够匹配的关键 —— 与前述消息格式与 decoder 兼容性一节的结论一致。远程日志出现在输出文件中ubuntuubuntu-VirtualBox:~$ tail -f /var/log/remote-syslog.log Jun 8 16:12:58 ubu24-2 ubuntu[-]: New remote log 22 Jun 8 16:12:59 ubu24-2 ubuntu[-]: New remote log 23 Jun 8 16:13:00 ubu24-2 ubuntu[-]: New remote log 24 Jun 8 16:13:01 ubu24-2 ubuntu[-]: New remote log 25dashboard 中可见的事件迁移清单与要点回顾没有自动迁移工具4.x 的remoteconnectionsyslog/connection/remote配置不会自动转换需要手动配置 rsyslog 并在收集主机安装 Wazuh agent。5.0 中 agent 不随 manager 安装即使 rsyslog 与 manager 同机也必须单独安装并注册 agentmanager 地址填127.0.0.1。journald 方案的_HOSTNAME是受信任字段始终等于本地主机名无法被 rsyslog 覆盖不要依赖它区分远程设备要保留源 IP 信息需通过模板属性%fromhost-ip%写入消息或使用 Option B 的文件路径方案。模板必须带时间戳自定义 rsyslog 消息模板必须以%timereported:::date-rfc3164%开头否则事件落入wazuh-events-v5-unclassified-*无字段提取。Option B 需预创建目录Debian/Ubuntu 上 rsyslog 以降权的syslog用户运行/var/log/remote需提前用install -d -o syslog -g adm创建。原有 decoders/rules 零改动cisco-asa、pf、juniper等网络设备 decoder 与规则在两种方案下均可直接复用。如需进一步了解 4.x 到 5.x 其他组件的迁移可参考仓库 docs/guide/migration 目录下的系列文档例如 engine 迁移说明、manager 配置迁移 与 升级总览。【免费下载链接】wazuhWazuh - The Open Source Security Platform. Unified XDR and SIEM protection for endpoints and cloud workloads.项目地址: https://gitcode.com/GitHub_Trending/wa/wazuh创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考