

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

# 新增建置安裝指令碼
<a name="gamelift-build-cli-uploading-install"></a>

為遊戲建置的作業系統 (OS) 建立安裝指令碼：
+ Windows：建立名為 的批次檔案`install.bat`。
+ Linux：建立名為 的 shell 指令碼檔案`install.sh`。

在建立安裝指令碼時，請注意下列資訊：
+ 指令碼無法接受任何使用者輸入。
+ Amazon GameLift Servers 在下列位置的託管伺服器上安裝組建並重新建立組建套件中的檔案目錄：
  + Windows 機群： `C:\game`
  + Linux 機群： `/local/game`
+ 在 Linux 機群的安裝程序中，執行身分使用者對執行個體檔案結構的存取有限。此使用者擁有安裝建置檔案之目錄的完整權限。如果您的安裝指令碼執行需要管理員許可的動作，請使用 指定管理員存取權**sudo**。Windows 機群的執行身分使用者預設具有管理員許可。與安裝指令碼相關的許可失敗會產生事件訊息，指出指令碼有問題。
+ 在 Linux 上， Amazon GameLift Servers支援常見的 shell 解譯器語言，例如 bash。在安裝指令碼的開頭新增 shebang (例如 `#!/bin/bash`)。若要驗證對偏好的 shell 命令的支援，請遠端存取作用中的 Linux 執行個體並開啟 shell 提示。如需詳細資訊，請參閱[連線至機群執行個體](fleets-remote-access.md)。
+ 安裝指令碼無法依賴 VPC 互連連線。在 將建置Amazon GameLift Servers安裝到機群執行個體之前，無法使用 VPC 互連連線。

**Example Windows 安裝 bash 檔案**  
此範例`install.bat`檔案會安裝遊戲伺服器所需的 Visual C\$1\$1 執行期元件，並將結果寫入日誌檔案。指令碼在根目錄的建置套件中包含元件檔案。  

```
vcredist_x64.exe /install /quiet /norestart /log c:\game\vcredist_2013_x64.log
```

**Example Linux 安裝 shell 指令碼**  
此範例`install.sh`檔案在安裝指令碼中使用 bash，並將結果寫入日誌檔案。  

```
#!/bin/bash
echo 'Hello World' > install.log
```
此範例`install.sh`檔案示範如何使用 Amazon CloudWatch 代理程式來收集系統層級和自訂指標，並處理日誌輪換。由於 是在服務 VPC 中Amazon GameLift Servers執行，因此您必須授予代表您擔任 AWS Identity and Access Management (IAM) 角色的Amazon GameLift Servers許可。若要允許 Amazon GameLift Servers 擔任角色，請建立包含 AWS 受管政策 的角色`CloudWatchAgentAdminPolicy`，並在建立機群時使用該角色。  

```
sudo yum install -y amazon-cloudwatch-agent
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install -y collectd
cat <<'EOF' > /tmp/config.json
{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root",
        "credentials": {
            "role_arn": "arn:aws:iam::account#:role/rolename"
        }
    },
    "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "/tmp/log",
                        "log_group_name": "gllog",
                        "log_stream_name": "{instance_id}"
                    }
                ]
            }
        }
    },
    "metrics": {
       "namespace": "GL_Metric",
        "append_dimensions": {
            "ImageId": "${aws:ImageId}",
            "InstanceId": "${aws:InstanceId}",
            "InstanceType": "${aws:InstanceType}"
        },
        "metrics_collected": {
            // Configure metrics you want to collect.
            // For more information, see [Manually create or edit the CloudWatch agent configuration file](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html).
        }
    }
}
EOF
sudo mv /tmp/config.json /opt/aws/amazon-cloudwatch-agent/bin/config.json
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
sudo systemctl enable amazon-cloudwatch-agent.service
```