

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

# 使用亚马逊 Athena 和亚马逊可视化 Amazon Redshift 审计日志 QuickSight
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight"></a>

*Sanket Sirsikar 和 Gopal Krishna Bhatia，Amazon Web Services*

## Summary
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight-summary"></a>

安全性是 Amazon Web Services（AWS）云上数据库操作不可或缺的一部分。您的组织应确保监视数据库用户活动和连接，以检测潜在的安全事件和风险。此模式有助于您监控数据库以确保安全并进行故障排除，该流程通常称为数据库审计。

 此模式提供了一个 SQL 脚本，可以自动创建 Amazon Athena 表和亚马逊报告控制面板的视图，从而帮助您审计 A QuickSight mazon Redshift 日志。这可确保负责监控数据库活动的用户能够方便地访问数据安全功能。 

## 先决条件和限制
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight-prereqs"></a>

**先决条件**
+ 一个活跃的 AWS 账户。
+ 现有 Amazon Redshift 集群。有关更多信息，请参阅 Amazon Redshift 文档中的[创建 Amazon Redshift 集群](https://docs.aws.amazon.com/redshift/latest/dg/tutorial-loading-data-launch-cluster.html)。
+ 访问现有 Athena 工作组。有关更多信息，请参阅 Amazon Athena 文档中的工作组的[工作原理](https://docs.aws.amazon.com/athena/latest/ug/user-created-workgroups.html)。 
+ 具有所需 AWS Identity and Access Management（IAM）权限的现有 Amazon Simple Storage Service（Amazon S3）源存储桶。有关更多信息，请参阅 Amazon Redshift 文档中的[数据库审计日志](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html)记录中的 [Amazon Redshift 审计日志记录的存储桶权限](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html#db-auditing-bucket-permissions)。

## 架构
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight-architecture"></a>

![\[Data flow diagram showing Amazon Redshift, logs, S3 bucket, Amazon Athena, and Amazon Quick.\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/90e69009-001e-4ced-bef0-3c361f93ae87/images/9fde7f01-17ab-4207-8a59-a12daf85a382.png)


 

**技术堆栈 **
+ Athena
+ Amazon Redshift 
+ Amazon S3 
+ QuickSight

## 工具
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight-tools"></a>
+ [Amazon Athena](https://docs.aws.amazon.com/athena/latest/ug/what-is.html) – Athena 是一种交互式查询服务，方便使用标准 SQL 分析 Amazon S3 的数据。 
+ [Amazon QuickSight](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) — QuickSight 是一项可扩展、无服务器、可嵌入、由机器学习提供支持的商业智能 (BI) 服务。 
+ [Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html) – Amazon Redshift 是一种完全托管的企业 PB 级数据仓库服务。 
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是一项面向互联网的存储服务。

## 操作说明
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight-epics"></a>

### 配置 Amazon Redshift 集群
<a name="configure-the-amazon-redshift-cluster"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
|  为 Amazon Redshift 集群启用审计日志记录。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight.html) | 数据库管理员、数据工程师 | 
| 在 Amazon Redshift 集群参数组中启用日志记录。 | 您可以使用 AWS 管理控制台、Amazon Redshift API 参考或 AWS 命令行界面（AWS CLI）同时启用对连接日志、用户日志和用户活动日志的审计。 要审计用户活动日志，您还必须启用 `enable_user_activity_logging` 数据库参数。如果您仅启用审计日志记录功能，但不启用相关参数，则数据库审计日志将仅为连接日志和用户日志记录信息，而不为用户活动日志记录信息。默认情况下未启用 `enable_user_activity_logging` 参数，但可以将它从 `false` 更改为 `true` 以便启用它。您需要使用已启用的 `user_activity_logging` 参数创建一个新的集群参数组，并将它附加到 Amazon Redshift 集群。有关详情，请参阅 Amazon Redshift 文档中的[修改集群](https://docs.aws.amazon.com/redshift/latest/mgmt/managing-clusters-console.html#modify-cluster)。有关此任务的更多信息，请参阅 Amazon Redshift 文档中的 [Amazon Redshift 参数组](https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-parameter-groups.html)和[使用控制台配置审计](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing-console.html)。 | 数据库管理员、数据工程师 | 
| 为 Amazon Redshift 集群日志记录配置 S3 存储桶权限。 | 当您启用日志记录时，Amazon Redshift 会收集日志记录信息并将其上载到 S3 存储桶中存储的日志文件。您可以使用现有的 S3 存储桶，也可以创建一个新的存储桶。确保 Amazon Redshift 具有访问 S3 存储桶所需的 IAM 权限。有关这方面的更多信息，请参阅 Amazon Redshift 文档中的[数据库审计日志记录](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html)中的 [Amazon Redshift 审计日志记录的存储桶权限](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html#db-auditing-bucket-permissions)。 | 数据库管理员、数据工程师 | 

### 创建 Athena 表和视图
<a name="create-the-athena-table-and-views"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 Athena 表和视图以从 S3 存储桶查询 Amazon Redshift 审计日志数据。 | 打开 Amazon Athena 控制台，并使用 `AuditLogging.sql` SQL 脚本（附加）中的数据定义语言（DDL）查询为用户活动日志、用户日志和连接日志创建表和视图。有关更多信息和说明，请参阅 Amazon Athena 研讨会中的[创建表和运行查询](https://athena-in-action.workshop.aws/30-basics/301-create-tables.html)教程。 | 数据工程师 | 

### 在 QuickSight 控制面板中设置日志监控
<a name="set-up-log-monitoring-in-the-quicksight-dashboard"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 使用 Athena 作为数据源创建 QuickSight 控制面板。 | 打开亚马逊 QuickSight 控制台，按照亚马逊 Athena 研讨会的 “[ QuickSight 使用 Athena 进行可视化](https://athena-in-action.workshop.aws/30-basics/307-quicksight.html)” 教程中的说明创建控制 QuickSight 面板。 | 数据库管理员、数据工程师 | 

## 相关资源
<a name="visualize-amazon-redshift-audit-logs-using-amazon-athena-and-amazon-quicksight-resources"></a>
+ [在 Athena 中创建表并运行查询](https://athena-in-action.workshop.aws/30-basics/301-create-tables.html)
+ [ QuickSight 使用 Athena 进行可视化](https://athena-in-action.workshop.aws/30-basics/307-quicksight.html)

## 附件
<a name="attachments-90e69009-001e-4ced-bef0-3c361f93ae87"></a>

要访问与此文档相关联的其他内容，请解压以下文件：[attachment.zip](samples/p-attach/90e69009-001e-4ced-bef0-3c361f93ae87/attachments/attachment.zip)