

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon Kinesis 代理程式入門
<a name="getting-started"></a>

您可以使用適用於微軟視窗的 Amazon Kinesis 代理程式 (適用於視窗) 收集、剖析、轉換並將日誌、事件和指標從您的 Windows 叢集串流至各種 AWS 服務。以下資訊包含安裝及設定適用於 Windows 版 Kinesis 代理程式的事前準備和逐步說明。

**Topics**
+ [Prerequisites](#getting-started-prerequisites)
+ [設定 AWS 帳戶](#getting-started-setting-up)
+ [安裝適用於視窗的 Kinesis 代理程式](#getting-started-installation)
+ [設定和啟動視窗的 Kinesis 代理程式](#getting-started-start-service)

## Prerequisites
<a name="getting-started-prerequisites"></a>

在安裝 Windows 專用 Kinesis 代理程式之前，請務必備妥下列先決條件：
+ 熟悉視窗概念的 Kinesis 代理程式。如需詳細資訊，請參閱 [微軟視窗概念的 Amazon Kinesis Kinesis 代理程式](kinesis-agent-windows-concepts.md)。
+ AWS 帳戶，可使用各種與您資料管道相關的 AWS 服務。如需建立和設定 AWS 帳戶的資訊，請參閱[設定 AWS 帳戶](#getting-started-setting-up)。
+ 在每個將執行 Kinesis 代理程式的桌面平台或伺服器上安裝 Microsoft .NET 架構 4.6 或更新版本。如需詳細資訊，請參閱 Microsoft .NET 文件中的 [Install the .NET Framework for developers](https://docs.microsoft.com/en-us/dotnet/framework/install/guide-for-developers)。

  若要判斷在桌面平台或伺服器上安裝的 .NET Framework 最新版本，請使用以下 PowerShell 指令碼：

  ```
       [System.Version](
       (Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse `
       | Get-ItemProperty -Name Version -ErrorAction SilentlyContinue `
       | Where-Object { ($_.PSChildName -match 'Full') } `
       | Select-Object Version | Sort-Object -Property Version -Descending)[0]).Version
  ```
+ 您希望從 Windows 專用 Kinesis 代理程式傳送 Amazon Kinesis Data Streams (若使用)。建立串流使用[Kinesis Data Streams 主控台](https://console.aws.amazon.com/kinesis/)，[AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/kinesis/create-stream.html), 或[適用於 Windows PowerShell 的 AWS 工具](https://docs.aws.amazon.com/powershell/latest/reference/items/New-KINStream.html)。如需詳細資訊，請參閱「」[建立及更新資料串流](https://docs.aws.amazon.com/streams/latest/dev/amazon-kinesis-streams.html)中的*Amazon Kinesis Data Streams 開發人員指南*。
+ 您希望從 Windows 專用 Kinesis 代理程式傳送資料的 Amazon Kinesis Data Firehose 交串流 (若使用)。建立交付串流使用[Kinesis Data Firehose 主控台](https://console.aws.amazon.com/firehose/)，[AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/firehose/create-delivery-stream.html), 或[適用於 Windows PowerShell 的 AWS 工具](https://docs.aws.amazon.com/powershell/latest/reference/items/New-KINFDeliveryStream.html)。如需詳細資訊，請參閱「」[建立 Amazon Kinesis Data Firehose 交付串流](https://docs.aws.amazon.com/firehose/latest/dev/basic-create.html)中的*Amazon Kinesis Data Firehose 開發人員指南*。

## 設定 AWS 帳戶
<a name="getting-started-setting-up"></a>

如果您還沒有 AWS 帳戶，請完成下列步驟建立新帳戶。

**註冊 AWS 帳戶**

1. 開啟 [https://portal.aws.amazon.com/billing/signup](https://portal.aws.amazon.com/billing/signup)。

1. 請遵循線上指示進行。

   部分註冊程序需接收來電，並在電話鍵盤輸入驗證碼。

**為您自己建立一個管理員使用者，並將使用者新增至管理員群組 (主控台)**

1. 登入。[IAM 主控台](https://console.aws.amazon.com/iam/)作為帳戶擁有者，請選擇**根使用者**，然後輸入您的 AWS 帳戶電子郵件地址。在下一頁中，輸入您的密碼。
**注意**  
強烈建議您遵循使用**Administrator**遵循並妥善鎖藏根使用者登入資料的 IAM 使用者。只在需要執行少數[帳戶和服務管理任務](https://docs.aws.amazon.com/general/latest/gr/aws_tasks-that-require-root.html)時，才以根使用者身分登入。

1. 在導覽窗格中，選擇 **Users** (使用者)，然後選擇 **Add user** (新增使用者)。

1. 在 **User name (使用者名稱)** 中輸入 **Administrator**。

1. 選取 **AWS Management Console access (AWS 管理主控台存取)** 旁的核取方塊。然後選取 **Custom password (自訂密碼)**，接著在文字方塊中輸入您的新密碼。

1. (選用) 根據預設，AWS 會要求新使用者在第一次登入時建立新密碼。您可以清除 **User must create a new password at next sign-in (使用者下次登入必須建立新的密碼)** 旁的核取方塊，讓新使用者登入時可以重設密碼。

1. 選擇**下一頁: 許可。**

1. 在 **Set permissions (設定許可)** 下，選擇 **Add user to group (將使用者新增至群組)**。

1. 選擇 **Create group** (建立群組)。

1. 在 **Create group (建立群組)** 對話方塊中，請於 **Group name (群組名稱)** 輸入 **Administrators**。

1. 選擇**篩選政策**，然後選取**AWS 託管-工作功能**來篩選表格內容。

1. 在政策清單中，選取 **AdministratorAccess** 的核取方塊。接著選擇 **Create group (建立群組)**。
**注意**  
您必須先啟用 IAM 使用者和角色對帳單的存取權，才能使用 `AdministratorAccess` 許可存取 AWS 帳單和成本管理主控台。若要這樣做，請遵循[委派對帳單主控台的存取權相關教學課程的步驟 1](https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_billing.html) 中的指示。

1. 回到群組清單，選取新群組的核取方塊。必要時，選擇 **Refresh (重新整理)** 以顯示清單中的群組。

1. 選擇**下一頁: Tags (標籤)**。

1. (選用) 藉由附加標籤做為索引鍵/值組，將中繼資料新增至使用者。如需在 IAM 中使用標籤的詳細資訊，請參閱[標記 IAM 實體](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html)中的*IAM 使用者指南*。

1. 選擇**下一頁: 檢閱**，查看要新增至新使用者的群組成員資格清單。準備好繼續時，請選擇 **Create user (建立使用者)**。

您可以使用這個相同的程序建立更多群組和使用者，以及讓使用者能夠存取您的 AWS 帳戶資源。如需了解以政策限制使用者對特定 AWS 資源的許可，請參閱[存取管理](https://docs.aws.amazon.com/IAM/latest/UserGuide/access.html)和[政策範例](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_examples.html)。

**註冊 AWS 並建立管理員帳戶**

1. 如果您尚未擁有 AWS 帳戶，請開啟[https://aws.amazon.com/](https://aws.amazon.com/)。選擇 **Create an AWS Account (建立 AWS 帳戶)**，然後遵循線上說明。

   部分註冊程序需接收來電，並使用電話鍵盤輸入 PIN 碼。

1. 登入 AWS 管理主控台，然後前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在導覽窗格中，選擇 **Groups (群組)**，然後選擇 **Create New Group (建立新群組)**。

1. 針對 **Group Name (群組名稱)**，輸入您群組的名稱，例如 **Administrators**，然後選擇 **Next Step (下一步)**。

1. 在政策清單中，選取 **AdministratorAccess** 政策旁的核取方塊。您可以使用 **Filter (篩選)** 功能表和 **Search(搜尋)** 方塊來篩選政策清單。

1. 選擇 **Next Step (後續步驟)**。選擇 **Create Group (建立群組)**，您的新群組即會顯示在 **Group Name (群組名稱)** 下方。

1. 在導覽窗格中，選擇 **Users (使用者)**，然後選擇 **Create New Users (建立新使用者)**。

1. 在方塊 **1** 中，輸入使用者名稱、清除 **Generate an access key for each user (為每個使用者產生存取金鑰)** 旁邊的核取方塊，然後選擇 **Create (建立)**。

1. 在使用者清單中，選擇您剛建立的使用者名稱 (不是核取方塊)。您可以使用 **Search (搜尋)** 方塊來搜尋使用者名稱。

1. 選擇 **Groups (群組)** 標籤，然後選擇 **Add User to Groups (新增使用者到群組)**。

1. 選取管理員群組旁的核取方塊，然後選擇 **Add to Groups (新增至群組)**。

1. 選擇 **Security Credentials (安全登入資料)** 標籤。在 **Sign-In Credentials (登入資料)** 下，選擇 **Manage Password (管理密碼)**。

1. 選取 **Assign a custom password (指派自訂密碼)**，在 **Password (密碼)** 及 **Confirm Password (確認密碼)** 中輸入密碼，然後選擇 **Apply (套用)**。

## 安裝適用於視窗的 Kinesis 代理程式
<a name="getting-started-installation"></a>

您可以使用三種方式在 Windows 上安裝 Windows 專用 Kinesis 代理程式：
+ 使用 MSI (Windows 安裝程式套件) 進行安裝。
+ 從安裝[AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/)，這是一組管理伺服器和桌面平台的服務。
+ 執行 PowerShell 指令碼。

**注意**  
下列說明偶爾會使用 *KinesisTap* 和 *AWSKinesisTap* 字詞。這些字詞都和代理程式都和 Windows 版 Kinesis 代理程式相同的項目，但您必須在執行這些指示時指定他們。

### 使用 MSI 安裝適用於視窗的 Kinesis 代理程式
<a name="install-msi"></a>

您可以從 Windows MSI 套件下載最新版的 Kinesis 代理程式。[GitHub 上的動態代理程式視窗存儲庫](https://github.com/awslabs/kinesis-agent-windows/releases)。下載 MSI 之後，請使用 Windows 啟動它，並依照安裝程式提示進行。安裝後，您可以像執行任何 Windows 應用程式一樣解除安裝。

或者，您也可以使用[檢查](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec)命令以無訊息方式安裝、開啟記錄並解除安裝，如以下範例所示。Replace`{{AWSKinesisTap.1.1.216.4.msi}} with the appropriate version of Kinesis Agent for Windows for your application.`

**若要以無訊息方式安裝適用於 Windows 的 Kinesis 代理程式：**

```
msiexec /i {{AWSKinesisTap.1.1.216.4.msi}} /q
```

**若要將安裝訊息記錄在名為`{{logfile.log}}`：**

```
msiexec /i {{AWSKinesisTap.1.1.216.4.msi}} /q /L*V {{logfile.log}}
```

**如果要使用命令提示字元解除安裝 Windows 專用的 Kinesis 代理程式：**

```
msiexec.exe /x {ADAB3982-68AA-4B45-AE09-7B9C03F3EBD3} /q
```

### 使用 AWS Systems Manager 安裝適用於視窗的 Kinesis 代理程式
<a name="install-systems-manager"></a>

依照下列步驟，使用 Systems Manager Run Command 來安裝 Windows 適用的 Kinesis 代理程式。如需執行命令的詳細資訊，請參閱[AWS Systems Manager Run Command](https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html)中的*AWS Systems Manager 使用指南*。除了使用 Systems Manager Run Command 之外，您也可以使用 Systems Manager[維護時段](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-maintenance.html)和[狀態管理員](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-state.html)來自動化 Windows 專用 Kinesis 代理程式的部署。

**注意**  
適用於 Windows 版 Kinesis 代理程式的 Systems Manager 安裝可在[AWS Systems Manager](https://docs.aws.amazon.com/general/latest/gr/rande.html#ssm_region)除下列項目外：  
cn-north-1
cn-northwest-1
所有 AWS GovCloud 區域。

**使用 Systems Manager 安裝適用於 Windows 的 Kinesis 代理程式**

1. 確認已在您希望在安裝 Windows 專用 Kinesis 代理程式的執行個體上安裝 SSM 代理程式 2.2.58.0 或更新版本。如需詳細資訊，請參閱「」[在 Windows 執行個體上安裝及設定 SSM 代理程式](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-win.html)中的*AWS Systems Manager 使用指南*。

1. 開啟 AWS Systems Manager 主控台，位於[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)。

1. 從導覽窗格的**節點管理**中，選擇**Run Command**，然後選擇**Run Command**。

1. 從**指令文件**清單中，選取**AWS ConfigureAWSPackage**document.  
![選取 AWS 組態 AWS-AWS-AWSPackage 文件。](http://docs.aws.amazon.com/zh_tw/kinesis-agent-windows/latest/userguide/images/runcommand-document-select.png)

1. DER**命令參數**，用於**名稱**，輸入**智慧型手機**。將其他設定保持為預設值。
**注意**  
離開**版本**空白，以指定 AWSinesiStap 套件的最新版本。或者，您也可以選擇輸入要安裝的特定版本。  
![在 [命令] 參數中指定 AwSkin 套件。](http://docs.aws.amazon.com/zh_tw/kinesis-agent-windows/latest/userguide/images/runcommand-specify-options.png)

1. DER**Targets (目標)**下，指定要執行命令的執行個體。您可以選擇根據與執行處理相關聯的標籤來指定執行處理，也可以手動選擇執行處理，也可以指定包含執行處理的資源群組。

1. 將所有其他設定保持為預設值，並選擇**執行**。

### 為視窗安裝 PowerShell 代理程式
<a name="install-ps"></a>

使用文字編輯器將下列命令複製到檔案中，並儲存為 PowerShell 指令碼。我們使用`InstallKinesisAgent.ps1`在下列範例中。

```
Param(
    [ValidateSet("prod", "beta", "test")]
    [string] $environment = 'prod',
    [string] $version,
    [string] $baseurl
)

# Self-elevate the script if required.
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
    if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
        $CommandLine = '-File "' + $MyInvocation.MyCommand.Path + '" ' + $MyInvocation.UnboundArguments
        Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
        Exit
    }
}

# Allows input to change base url. Useful for testing.
if ($baseurl) {
    if (!$baseUrl.EndsWith("/")) {
        throw "Invalid baseurl param value. Must end with a trailing forward slash ('/')"
    }

    $kinesistapBaseUrl = $baseurl
} else {
    $kinesistapBaseUrl = "https://s3-us-west-2.amazonaws.com/kinesis-agent-windows/downloads/"
}

Write-Host "Using $kinesistapBaseUrl as base url"

$webClient = New-Object System.Net.WebClient

try {
    $packageJson = $webClient.DownloadString($kinesistapBaseUrl + 'packages.json' + '?_t=' + [System.DateTime]::Now.Ticks) | ConvertFrom-Json
} catch {
    throw "Downloading package list failed."
}


if ($version) {
    $kinesistapPackage = $packageJson.packages | Where-Object { $_.packageName -eq "AWSKinesisTap.$version.nupkg" }

    if ($null -eq $kinesistapPackage) {
        throw "No package found matching input version $version"
    }
} else {
    $packageJson = $packageJson.packages | Where-Object { $_.packageName -match ".nupkg" }
    $kinesistapPackage = $packageJson[0]
}

$packageName = $kinesistapPackage.packageName
$checksum = $kinesistapPackage.checksum

#Create %TEMP%/kinesistap if not exists
$kinesistapTempDir = Join-Path $env:TEMP 'kinesistap'
if (![System.IO.Directory]::Exists($kinesistapTempDir)) {[void][System.IO.Directory]::CreateDirectory($kinesistapTempDir)}

#Download KinesisTap.x.x.x.x.nupkg package
$kinesistapNupkgPath = Join-Path $kinesistapTempDir $packageName
$webClient.DownloadFile($kinesistapBaseUrl + $packageName, $kinesistapNupkgPath)
$kinesistapUnzipPath = $kinesistapNupkgPath.Replace('.nupkg', '')

# Calculates hash of downloaded file. Downlevel compatible using .Net hashing on PS < 4
if ($PSVersionTable.PSVersion.Major -ge 4) {
    $calculatedHash = Get-FileHash $kinesistapNupkgPath -Algorithm SHA256
    $hashAsString = $calculatedHash.Hash.ToLower()
} else {
    $sha256 = New-Object System.Security.Cryptography.SHA256CryptoServiceProvider
    $calculatedHash = [System.BitConverter]::ToString($sha256.ComputeHash([System.IO.File]::ReadAllBytes($kinesistapNupkgPath)))
    $hashAsString = $calculatedHash.Replace("-", "").ToLower()
}

if ($checksum -eq $hashAsString) {
	Write-Host 'Local file hash matches checksum.' -ForegroundColor Green
} else {
	throw ("Get-FileHash does not match! Package may be corrupted.")
}

#Delete Unzip path if not empty
if ([System.IO.Directory]::Exists($kinesistapUnzipPath)) {Remove-Item –Path $kinesistapUnzipPath -Recurse -Force}

#Unzip KinesisTap.x.x.x.x.nupkg package
$null = [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
[System.IO.Compression.ZipFile]::ExtractToDirectory($kinesistapNupkgPath, $kinesistapUnzipPath)

#Execute chocolaeyInstall.ps1 in the package and wait for completion.
$installScript = Join-Path $kinesistapUnzipPath '\tools\chocolateyInstall.ps1'
& $installScript

# Verify service installed.
$serviceName = 'AWSKinesisTap'
$service = Get-Service -Name $serviceName -ErrorAction Ignore
if ($null -eq $service) {
    throw ("Service not installed correctly.")
} else {
    Write-Host "Kinesis Tap Installed." -ForegroundColor Green
    Write-Host "After configuring run the following to start the service: Start-Service -Name $serviceName." -ForegroundColor Green
}
```

開啟提高權限執行的命令提示視窗。在下載檔案的目錄中，使用下列命令來執行指令碼：

```
PowerShell.exe -File ".\InstallKinesisAgent.ps1"
```

若要安裝特定版本的 Kinesis 代理程式，請將`-version`選項：

```
PowerShell.exe -File ".\InstallKinesisAgent.ps1" -version "{{version}}"
```

Replace{{version}}使用有效的 Kinesis 代理程式。如需版本資訊，請參閱[GitHub 上的動態代理程式視窗存儲庫](https://github.com/awslabs/kinesis-agent-windows/blob/master/README.md)。

有許多部署工具可遠端執行 PowerShell 指令碼。它們可用來在伺服器或桌面平台叢集上自動化安裝 Windows 專用 Kinesis Agent。

## 設定和啟動視窗的 Kinesis 代理程式
<a name="getting-started-start-service"></a>

在安裝 Windows 專用 Kinesis 代理程式之後，您必須設定及啟動代理程式。之後，並不需要更進一步的操作介入。

**設定及啟動 Windows 版 Kinesis 代理程式**

1. 建立及部署 Windows 組態檔案的 Kinesis 代理程式。此檔案會設定來源、接收和管道，以及其他全域組態項目。

   如需 Windows 專用 Kinesis 代理程式組態的詳細資訊，請參閱[設定適用於微軟視窗的 Amazon Kinesis](configuring-kinesis-agent-windows.md)。

   如需您可以自訂及安裝的完整組態檔案範例，請參閱[適用於視窗設定範例的 Kinesis 代理程式](configuring-kaw-examples.md)。

1. 開啟提高權限執行的 PowerShell 命令提示視窗，然後使用以下 PowerShell 命令啟動適用於 Windows 的 Kinesis 代理程式：

   ```
   Start-Service -Name AWSKinesisTap
   ```