Wazuh+Graylog替代Splunk:零成本SIEM方案搭建实战
企业级SIEM(安全信息与事件管理)是安全运营的核心,但商业方案的价格令人望而却步。Splunk Enterprise起步价$1,800/GB/年,最低$15,000/年;IBM QRadar企业级$50,000+/年;LogRhythm估计$30,000+/年。本文用Wazuh+Graylog+Elasticsearch搭建一套功能完整的免费SIEM平台,覆盖日志收集、威胁检测、告警响应全流程。
一、付费SIEM工具定价对比
| 工具 | 定价模式 | 入门价格 | 企业级价格 | 核心优势 |
|---|---|---|---|---|
| Splunk Enterprise | 按数据量(GB/年) | $1,800/GB/年,最低$15,000/年 | $50,000+/年 | SPL查询语言、应用生态丰富、机器学习 |
| IBM QRadar | 按EPS(事件/秒) | $10,000+/年 | $50,000+/年 | 自动化威胁情报、合规报告 |
| LogRhythm | 按节点/日志量 | $30,000+/年 | $80,000+/年 | SIEM+UEBA+SOAR一体化 |
二、免费替代方案介绍
Wazuh
Wazuh是开源的XDR和SIEM平台,前身是OSSEC HIDS的分支。它集成了主机入侵检测(HIDS)、漏洞检测、合规审计、文件完整性监控(FIM)等功能。Wazuh 4.x版本引入了新的索引引擎,性能大幅提升。GitHub: https://github.com/wazuh/wazuh
Graylog
Graylog是开源的日志管理平台,专注于日志的收集、解析、搜索和告警。支持GELF、Syslog、Beats等多种输入协议。Graylog 5.x版本优化了搜索性能和告警机制。GitHub: https://github.com/Graylog2/graylog2-server
Elasticsearch
Elasticsearch作为Graylog的存储后端,提供分布式全文搜索和分析能力。使用开源版本(OpenSearch兼容)即可满足SIEM需求。
Sigma Rules
Sigma是通用的SIEM检测规则格式,类似于YARA之于文件。一个Sigma规则可以在不同SIEM平台间转换使用,避免重复编写检测逻辑。GitHub: https://github.com/SigmaHQ/sigma
三、完整安装步骤
3.1 环境准备
系统要求:Ubuntu 22.04 LTS,最低8GB RAM,4核CPU,100GB磁盘
# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装基础依赖
sudo apt install -y curl wget apt-transport-https openjdk-17-jre-headless
# 设置主机名
sudo hostnamectl set-hostname siem-server
3.2 安装Wazuh
Wazuh提供了一键安装脚本,部署Wazuh Manager + Wazuh Indexer + Wazuh Dashboard三个组件:
# 下载Wazuh安装脚本
curl -sO https://packages.wazuh.com/4.7/wazuh-install.sh
chmod +x wazuh-install.sh
# 生成配置文件(单节点模式)
sudo ./wazuh-install.sh --generate-config-files
# 安装Wazuh Manager
sudo ./wazuh-install.sh --wazuh-server wazuh-manager
# 安装Wazuh Indexer(内置Elasticsearch兼容引擎)
sudo ./wazuh-install.sh --wazuh-indexer wazuh-indexer
# 初始化索引器集群
sudo ./wazuh-install.sh --start-cluster
# 安装Wazuh Dashboard(Kibana替代)
sudo ./wazuh-install.sh --wazuh-dashboard wazuh-dashboard
# 启动所有服务
sudo systemctl daemon-reload
sudo systemctl enable wazuh-manager wazuh-indexer wazuh-dashboard
sudo systemctl start wazuh-manager wazuh-indexer wazuh-dashboard
验证安装:
# 检查Wazuh Manager状态
sudo systemctl status wazuh-manager
# 检查API是否可用
curl -k -u wazuh:wazuh https://localhost:55000/?pretty
# 默认Dashboard地址: https://<IP>:443
# 默认账号: admin / admin(首次登录强制修改)
3.3 安装Elasticsearch(给Graylog用)
Graylog需要Elasticsearch或OpenSearch作为后端存储。推荐使用OpenSearch:
# 导入OpenSearch GPG key
curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo gpg --dearmor -o /usr/share/keyrings/opensearch-keyring.gpg
# 添加OpenSearch仓库
echo "deb [signed-by=/usr/share/keyrings/opensearch-keyring.gpg] https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-2.x.list
sudo apt update
# 安装OpenSearch(禁用安全插件简化部署)
sudo OPENSEARCH_INITIAL_ADMIN_PASSWORD=StrongP@ssw0rd! apt install -y opensearch
# 配置OpenSearch
sudo tee /etc/opensearch/opensearch.yml << 'EOF'
cluster.name: graylog-cluster
node.name: opensearch-node1
path.data: /var/lib/opensearch
path.logs: /var/log/opensearch
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node
plugins.security.disabled: true
EOF
# 增加JVM内存(至少2GB)
sudo sed -i 's/-Xms1g/-Xms2g/' /etc/opensearch/jvm.options
sudo sed -i 's/-Xmx1g/-Xmx2g/' /etc/opensearch/jvm.options
# 启动OpenSearch
sudo systemctl enable opensearch
sudo systemctl start opensearch
# 验证
curl -s http://localhost:9200/ | python3 -m json.tool
3.4 安装MongoDB(Graylog依赖)
# 导入MongoDB GPG key
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
# 添加MongoDB仓库
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl enable mongod
sudo systemctl start mongod
3.5 安装Graylog
# 下载Graylog安装包
wget https://packages.graylog2.org/repo/packages/graylog-5.2-repository_latest.deb
sudo dpkg -i graylog-5.2-repository_latest.deb
sudo apt update
sudo apt install -y graylog-server
# 生成password_secret(用于加密)
SECRET=$(pwgen -s 96 1)
echo "password_secret = $SECRET" | sudo tee -a /etc/graylog/server/server.conf
# 生成admin密码的SHA256 hash
ADMIN_PASS=$(echo -n 'YourStrongAdminPass123!' | sha256sum | awk '{print $1}')
echo "root_password_sha2 = $ADMIN_PASS" | sudo tee -a /etc/graylog/server/server.conf
# 配置关键参数
sudo tee -a /etc/graylog/server/server.conf << 'EOF'
# Elasticsearch连接
elasticsearch_hosts = http://127.0.0.1:9200
# HTTP绑定地址
http_bind_address = 0.0.0.0:9000
# 外部访问URL
http_publish_uri = http://YOUR_SERVER_IP:9000/
# 时区
root_timezone = Asia/Shanghai
# 消息处理
processbuffer_processors = 5
outputbuffer_processors = 3
processor_wait_strategy = blocking
# 索引设置
elasticsearch_max_docs_per_index = 20000000
elasticsearch_max_number_of_indices = 20
rotation_strategy = count
EOF
# 启动Graylog
sudo systemctl enable graylog-server
sudo systemctl start graylog-server
# 验证:访问 http://YOUR_SERVER_IP:9000
# 登录账号:admin / YourStrongAdminPass123!
3.6 安装Wazuh Agent(目标主机)
在需要监控的服务器上安装Agent:
# Ubuntu/Debian
curl -s https://packages.wazuh.com/key/GPG-KEY-WAZUH | sudo gpg --dearmor -o /usr/share/keyrings/wazuh-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/wazuh-archive-keyring.gpg] https://packages.wazuh.com/4.x/apt stable main" | sudo tee /etc/apt/sources.list.d/wazuh.list
sudo apt update
sudo apt install -y wazuh-agent
# 配置Manager地址
sudo sed -i 's/<address>MANAGER_IP</address>/<address>YOUR_SIEM_SERVER_IP</address>/' /var/ossec/etc/ossec.conf
sudo systemctl enable wazuh-agent
sudo systemctl start wazuh-agent
四、配置示例
4.1 Graylog输入配置(接收Syslog)
在Graylog Web界面操作:
导航到 System > Inputs
选择 Syslog TCP
点击 Launch new input
配置:
- Title: Syslog TCP Input
- Bind address: 0.0.0.0
- Port: 5140
- Store full message: true
点击 Save
也可通过命令行添加Syslog UDP输入:
# 通过Graylog REST API添加输入
curl -u admin:YourStrongAdminPass123! \
-H "Content-Type: application/json" \
-H "X-Requested-By: cli" \
-X POST http://localhost:9000/api/system/inputs \
-d '{
"title": "Syslog UDP",
"type": "org.graylog2.inputs.syslog.udp.SyslogUDPInput",
"global": true,
"configuration": {
"bind_address": "0.0.0.0",
"port": 5141,
"recv_buffer_size": 262144,
"number_worker_threads": 4,
"override_source": null,
"force_rdns": true,
"allow_override_date": true,
"store_full_message": true
}
}'
4.2 Wazuh告警规则配置
编辑 /var/ossec/etc/rules/local_rules.xml:
<!-- 自定义规则:检测SSH暴力破解 -->
<group name="local,syslog,sshd,">
<rule id="100001" level="10" frequency="5" timeframe="60">
<if_matched_sid>5716</if_matched_sid>
<description>SSH brute force detected from same source</description>
<group>authentication_failures,</group>
</rule>
<!-- 检测可疑的cron任务 -->
<rule id="100002" level="12">
<if_sid>534</if_sid>
<match>crontab</match>
<description>Suspicious crontab modification detected</description>
<group>rootcheck,</group>
</rule>
</group>
重启Wazuh Manager使规则生效:
sudo systemctl restart wazuh-manager
4.3 Sigma规则转换与使用
安装Sigma CLI工具并转换规则给Wazuh使用:
# 安装sigmatool
pip install sigma-cli pySigma-backend-wazuh
# 下载Sigma规则仓库
git clone https://github.com/SigmaHQ/sigma.git /opt/sigma-rules
# 转换规则为Wazuh格式
sigma convert -t wazuh -p sysmon /opt/sigma-rules/rules/windows/process_creation/ > /var/ossec/etc/rules/sigma_converted.xml
sudo systemctl restart wazuh-manager
4.4 将Wazuh告警转发到Graylog
在Wazuh Manager的 /var/ossec/etc/ossec.conf 中添加集成:
<integration>
<name>custom-graylog</name>
<hook_url>http://YOUR_SERVER_IP:5141/gelf</hook_url>
<level>3</level>
<alert_format>json</alert_format>
</integration>
创建集成脚本 /var/ossec/integrations/custom-graylog:
#!/bin/bash
ALERT_FILE=$1
ALERT_JSON=$(cat $ALERT_FILE)
# 发送到Graylog GELF TCP输入
echo -e "$ALERT_JSON\x00" | nc -w 1 YOUR_SERVER_IP 5141
sudo chmod +x /var/ossec/integrations/custom-graylog
sudo systemctl restart wazuh-manager
五、功能对比表
| 功能 | Splunk | Wazuh+Graylog | 差距说明 |
|---|---|---|---|
| 日志收集 | ✅ 万能Forwarder | ✅ Agent+Syslog+Beats | Wazuh Agent覆盖面广 |
| 搜索查询 | ✅ SPL语言(极强) | ⚠️ Lucene+Graylog查询语法 | 缺少SPL的灵活管道操作 |
| 威胁检测 | ✅ ESIM+ML Kit | ✅ Wazuh规则+Sigma | 社区规则数量可观 |
| 告警响应 | ✅ SOAR集成 | ⚠️ Wazuh主动响应+脚本 | 缺少完整的SOAR编排 |
| 可视化仪表板 | ✅ 内置大量模板 | ✅ Wazuh Dashboard+Graylog | 应用生态不如Splunk |
| 合规报告 | ✅ PCI/HIPAA/SOX | ✅ Wazuh合规模块 | 基本满足合规需求 |
| 漏洞管理 | ✅ Splunk VM | ✅ Wazuh漏洞检测器 | Wazuh原生支持CVE扫描 |
| 文件完整性 | ✅ 需插件 | ✅ Wazuh FIM模块 | Wazuh开箱即用 |
| 用户行为分析 | ✅ UBA | ⚠️ 需额外工具 | 明显差距 |
| 应用生态 | ✅ 2000+应用 | ⚠️ 有限 | 最大差距所在 |
| 成本 | $15,000+/年 | $0(开源) | 核心优势 |
六、性能优化建议
# 优化Wazuh Indexer性能
curl -k -u admin:admin -X PUT "https://localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{
"persistent": {
"indices.memory.index_buffer_size": "20%",
"thread_pool.write.queue_size": 1000
}
}'
# 优化Graylog索引策略
curl -u admin:YourStrongAdminPass123! \
-H "Content-Type: application/json" \
-H "X-Requested-By: cli" \
-X PUT http://localhost:9000/api/system/indices/index_set_defaults \
-d '{
"rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategy",
"rotation_strategy": { "type": "org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategyConfig", "rotation_period": "P1D" },
"retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy",
"retention_strategy": { "type": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig", "max_number_of_indices": 30 }
}'
# 定期清理Wazuh旧索引
crontab -e
# 添加:每天凌晨3点清理30天前的索引
0 3 * * * curl -k -u admin:admin -X DELETE "https://localhost:9200/wazuh-alerts-4.x-$(date -d '30 days ago' +%Y.%m.%d)" 2>/dev/null
七、总结
Wazuh+Graylog+Elasticsearch的组合可以替代80%的Splunk核心功能,而成本为零。Wazuh提供了强大的主机安全监控能力(HIDS/FIM/漏洞检测/合规审计),Graylog提供了高效的日志管理和告警机制。主要不足在于查询语言的灵活性(SPL > Lucene)和应用生态系统,但对于中小型企业的安全运营需求,这套方案完全够用。
建议从Wazuh单节点部署开始,逐步扩展Agent覆盖范围,再引入Graylog统一日志管理。当数据量超过100GB/天时,考虑分布式部署OpenSearch集群。
评论