

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Splunk 查看 AWS Network Firewall 日志和指标
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk"></a>

*Ivo Pinto，Amazon Web Services*

## Summary
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk-summary"></a>

许多组织使用 [Splunk Enter](https://www.splunk.com/en_us/products/splunk-enterprise.html) prise 作为来自不同来源的日志和指标的集中聚合和可视化工具。 此模式可帮助您配置 Splunk，使其使用适用[于 AWS 的 Splunk 插件从[亚马逊 CloudWatch 日志](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html)中获取 AWS Network Firew](https://docs.aws.amazon.com/network-firewall/latest/developerguide/what-is-aws-network-firewall.html) all 日志和指标。 

为此，您需要创建一个只读的 AWS Identity and Access Management（IAM）角色。适用于 AWS 的 Splunk 附加组件使用此角色进行访问 CloudWatch。您可以配置 AWS 的 Splunk 插件以从中 CloudWatch获取指标和日志。最后，您需要在 Splunk 中根据检索到的日志数据和指标来创建可视化。

## 先决条件和限制
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk-prereqs"></a>

**先决条件**
+ 一个 [Splunk](https://www.splunk.com/) 账户
+ 一个 Splunk Enterprise 实例，版本 8.2.2 或更高版本 
+ 一个活跃的 AWS 账户
+ Network Firewall，[设置](https://docs.aws.amazon.com/network-firewall/latest/developerguide/getting-started.html)并[配置为](https://docs.aws.amazon.com/network-firewall/latest/developerguide/logging-cw-logs.html)向日志发送 CloudWatch 日志

**限制**
+ 必须将 Splunk Enterprise 作为一组 Amazon Elastic Compute Cloud（Amazon EC2）实例部署到 AWS 云端。
+ AWS 中国区域不支持使用自动为 Amazon EC2 发现的 IAM 角色来收集数据。

## 架构
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk-architecture"></a>

![AWS Network Firewall 和 Splunk 日志记录架构](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/c6ce254a-841f-4bed-8f9f-b35e99f22e56/images/3dd420e9-70af-4a42-b24d-c54872c55e0b.png)


下图说明了以下内容：

1. Network Firewall 将日志发布到 CloudWatch 日志。

1. Splunk Enterprise 从中检索指标和日志。 CloudWatch

为了在此架构中填充示例指标和日志，一个工作负载会生成流量，这些流量将经过 Network Firewall 端点流向互联网。这是通过使用[路由表](https://docs.aws.amazon.com/network-firewall/latest/developerguide/vpc-config.html#vpc-config-route-tables)来实现的。 尽管此模式使用单个 Amazon EC2 实例作为工作负载，但只要将 Network Firewall 配置为向 CloudWatch 日志发送日志，这种模式就可以应用于任何架构。

此架构还使用了另一个虚拟私有云（VPC）中的一个 Splunk Enterprise 实例。但是，Splunk 实例可以位于其他位置，例如与工作负载位于同一个 VPC 中，前提是它可以到达。 CloudWatch APIs

## 工具
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk-tools"></a>

**AWS 服务**
+ [Amazon CloudWatch Lo](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) gs 可帮助您集中管理来自所有系统、应用程序和 AWS 服务的日志，以便您可以监控它们并安全地将其存档。
+ [Amazon Elastic Compute Cloud（Amazon EC2）](https://docs.aws.amazon.com/ec2/)在 AWS 云提供了可扩展的计算容量。您可以根据需要启动任意数量的虚拟服务器，并快速纵向扩展或缩减这些服务器。
+ [AWS Network Fire](https://docs.aws.amazon.com/network-firewall/latest/developerguide/what-is-aws-network-firewall.html) wall 是一项有状态的托管式网络防火墙以及入侵检测和防御服务，适用于 AWS 云 VPCs 中。

**其他工具**
+ [Splunk](https://www.splunk.com/) 可帮助您监控、可视化和分析日志数据。

## 操作说明
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk-epics"></a>

### 创建一个 IAM 角色
<a name="create-an-iam-role"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 IAM 策略。 | 按照[使用 JSON 编辑器创建策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create-console.html#access_policies_create-json-editor)中的说明创建授予 CloudWatch 日志数据和 CloudWatch 指标只读访问权限的 IAM 策略。将如下策略粘贴到 JSON 编辑器中。<pre>{<br />    "Statement": [<br />        {<br />            "Action": [<br />                "cloudwatch:List*",<br />                "cloudwatch:Get*",<br />                "network-firewall:List*",<br />                "logs:Describe*",<br />                "logs:Get*",<br />                "logs:List*",<br />                "logs:StartQuery",<br />                "logs:StopQuery",<br />                "logs:TestMetricFilter",<br />                "logs:FilterLogEvents",<br />                "network-firewall:Describe*"<br />            ],<br />            "Effect": "Allow",<br />            "Resource": "*"<br />        }<br />    ],<br />    "Version": "2012-10-17"<br />}</pre> | AWS 管理员 | 
| 创建一个新的 IAM 角色。 | 按照[创建角色中的说明向 AWS 服务委派权限，创建适用于 AWS](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html) 的 Splunk 附加组件访问 CloudWatch的 IAM 角色。对于**权限策略**，选择您之前创建的策略。 | AWS 管理员 | 
| 将此 IAM 角色分配给 Splunk 集群中的 EC2 实例。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html) | AWS 管理员 | 

### 安装适用于 AWS 的 Splunk 附加组件
<a name="install-the-splunk-add-on-for-aws"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 安装此附加组件。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html) | Splunk 管理员 | 
| 配置 AWS 凭证。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html)有关详情，请参阅 Splunk 文档中的[在您的 Splunk 平台实例内查找 IAM 角色](https://splunk.github.io/splunk-add-on-for-amazon-web-services/#Find_an_IAM_role_within_your_Splunk_platform_instance)。 | Splunk 管理员 | 

### 将 Splunk 的访问权限配置为 CloudWatch
<a name="configure-splunk-access-to-cloudwatch"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 配置从日志中检索 Network Firewall 日 CloudWatch 志。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html)默认情况下，Splunk 每 10 分钟获取一次日志数据。这是**高级设置**下方的一个可配置参数。有关更多信息，请参阅 Splunk [文档中的使用 Splunk Web 配置 CloudWatch 日志输入](https://splunk.github.io/splunk-add-on-for-amazon-web-services/#Configure_a_CloudWatch_Logs_input_using_Splunk_Web)。 | Splunk 管理员 | 
| 配置从中检索 Network Firewall 指标 CloudWatch。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html)默认情况下，Splunk 每 5 分钟获取一次指标数据。这是**高级设置**下方的一个可配置参数。有关更多信息，请参阅 Splunk [文档中的使用 Splunk Web 配置 CloudWatch 输入](https://splunk.github.io/splunk-add-on-for-amazon-web-services/#Configure_a_CloudWatch_input_using_Splunk_Web)。 | Splunk 管理员 | 

### 使用查询创建 Splunk 可视化
<a name="create-splunk-visualizations-by-using-queries"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 查看排名靠前的源 IP 地址。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html) | Splunk 管理员 | 
| 查看数据包统计数据。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html) | Splunk 管理员 | 
| 查看最常用的源端口。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/view-aws-network-firewall-logs-and-metrics-by-using-splunk.html) | Splunk 管理员 | 

## 相关资源
<a name="view-aws-network-firewall-logs-and-metrics-by-using-splunk-resources"></a>

**AWS 文档**
+ [创建向 AWS 服务委托权限的角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)（IAM 文档）
+ [创建 IAM 策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create-console.html#access_policies_create-start)（IAM 文档）
+ [在 AWS Network Firewall 中进行日志记录和监控](https://docs.aws.amazon.com/network-firewall/latest/developerguide/logging-monitoring.html)（Network Firewall 文档）
+ [AWS Network Firewall 的路由表配置](https://docs.aws.amazon.com/network-firewall/latest/developerguide/route-tables.html)（Network Firewall 文档）

**AWS 博客文章**
+ [AWS Network Firewall 部署模式](https://aws.amazon.com/pt/blogs/networking-and-content-delivery/deployment-models-for-aws-network-firewall/)

**Amazon Web Services Marketplace**
+ [Splunk Enterprise 亚马逊机器映像（AMI）](https://aws.amazon.com/marketplace/pp/prodview-l6oos72bsyaks)