Windows에서 CloudFormation을 사용하여 Amazon EBS 볼륨에 드라이브 문자를 매핑하려면 어떻게 해야 합니까?

4분 분량
0

Windows에서 AWS CloudFormation을 사용하여 Amazon Elastic Block Store(Amazon EBS)에 드라이브 문자를 매핑하고자 합니다.

간략한 설명

부팅 중에 실행되는 사용자 지정 스크립트를 사용하여 Windows에서 CloudFormation을 사용하여 Amazon EBS 볼륨에 드라이브 문자를 매핑할 수 있습니다.

해결 방법

1.    Windows Server 2016 Base 이상에 대한 Amazon Machine Image(AMI)를 사용하여 Windows 인스턴스를 시작합니다.

2.    (선택 사항) D 드라이브를 수동으로 생성한 다음 D 드라이브에 데이터 파일을 저장합니다. 자세한 내용은 Amazon EBS 볼륨을 Windows에서 사용할 수 있도록 만들기를 참조하세요.

3.    ShutDown과 Sysprep 옵션을 함께 사용하여 인스턴스에서 AMI를 생성합니다. 자세한 내용은 EC2Launch를 사용하여 Windows 인스턴스 구성을 참조하세요.

4.    다음 템플릿을 기반으로 CloudFormation 스택을 생성합니다.

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "AWS CloudFormation template AV Group, Launch Config for EC2",
  "Resources": {
    "DBServer": {
      "Type": "AWS::EC2::Instance",
      "Metadata" : {
        "AWS::CloudFormation::Init" : {
          "config" : {
          "files" : {
            "c:\\cfn\\cfn-hup.conf" : {
            "content" : { "Fn::Join" : ["", [
              "[main]\n",
              "stack=", { "Ref" : "AWS::StackId" }, "\n",
              "region=", { "Ref" : "AWS::Region" }, "\n"
              ]]}
            },
            "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" : {
            "content": { "Fn::Join" : ["", [
              "[cfn-auto-reloader-hook]\n",
              "triggers=post.update\n",
              "path=Resources.DBServer.Metadata.AWS::CloudFormation::Init\n",
              "action=cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" },
                " -r DBServer",
                " --region ", { "Ref" : "AWS::Region" }, "\n"
            ]]}
            },
            "c:\\cfn\\hooks.d\\drives.diskpart.txt" : {
              "content": { "Fn::Join" : ["", [
                "select disk 2\n",
                "attributes disk clear readonly\n",
                "clean\n",
                "online disk\n",
                "convert gpt\n",
                "create partition primary\n",
                "format quick fs=ntfs label=","\"","ORATEMP","\"","\n",
                "assign letter=X\n",
                "select disk 3\n",
                "attributes disk clear readonly\n",
                "clean\n",
                "online disk\n",
                "convert gpt\n",
                "create partition primary\n",
                "format quick fs=ntfs label=","\"","ORADATA","\"","\n",
                "assign letter=S\n",
                "select disk 1\n",
                "online disk\n"
              ]]}},
              "c:\\cfn\\hooks.d\\renamedrives.ps1" : {
                "content": { "Fn::Join" : ["", [
                  "diskpart /s c:\\cfn\\hooks.d\\drives.diskpart.txt\n"
              ]]}}
          },
          "commands" : {
            "1-rename-drives" : {
              "command" : "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File c:\\cfn\\hooks.d\\renamedrives.ps1",
              "waitAfterCompletion" : "0"
            },
            "2-signal-success" : {
              "command" : { "Fn::Join" : [ "", [
                "cfn-signal.exe -e %ERRORLEVEL% \"",
                { "Fn::Base64" : { "Ref" : "WindowsServerWaitHandle" }},
                "\""]]
              }
            }
          },
          "services" : {
            "windows" : {
            "cfn-hup" : {
              "enabled" : "true",
              "ensureRunning" : "true",
              "files" : ["c:\\cfn\\cfn-hup.conf", "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"]
            }
            }
          }
          }
        }
      },
      "Properties": {
        "ImageId": "ami-01xxxxxxxxxx",
        "InstanceType": "m4.xlarge",
        "KeyName": "xxxxxxxx",
        "BlockDeviceMappings": [
          {"DeviceName": "xvdg","Ebs":{"VolumeSize":"20"}},
          {"DeviceName": "xvdm","Ebs":{"VolumeSize":"20"}}
        ],
        "Tags": [ {
          "Key": "Name",
          "Value": {"Fn::Join": ["-", ["DB",{"Ref": "AWS::StackName"}]]}
        }],
        "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
          "<powershell>\n",
          "cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" },
          " -r DBServer",
          " --region ", { "Ref" : "AWS::Region" }, "\n",
          "</powershell>"
        ]]}}
      }
    },
    "WindowsServerWaitHandle" : {
      "Type" : "AWS::CloudFormation::WaitConditionHandle"
    },
    "WindowsServerWaitCondition" : {
      "Type" : "AWS::CloudFormation::WaitCondition",
      "DependsOn" : "DBServer",
      "Properties" : {
        "Handle" : {"Ref" : "WindowsServerWaitHandle"},
        "Timeout" : "1800"
      }
    }
  }
}

참고: 이전 템플릿에는 드라이브 문자가 X인 디스크 2와 드라이브 문자가 S인 디스크 3을 생성하는 스크립트가 포함되어 있습니다.

다음 스크립트는 4단계에 나온 템플릿의 일부이며 여기서는 강조를 위해 언급되었습니다. 스크립트는 MBR(마스터 부트 레코드) 파티션 구조로 볼륨을 구성하고, 볼륨을 NTFS 볼륨으로 포맷한 다음, 드라이브 문자를 할당합니다.

"select disk 2\n",
"attributes disk clear readonly\n",
"clean\n",
"online disk\n",
"convert gpt\n",
"create partition primary\n",
"format quick fs=ntfs label=","\"","ORATEMP","\"","\n",
"assign letter=X\n",
"select disk 3\n",
"attributes disk clear readonly\n",
"clean\n",
"online disk\n",
"convert gpt\n",
"create partition primary\n",
"format quick fs=ntfs label=","\"","ORADATA","\"","\n",
"assign letter=S\n",
"select disk 1\n",
"online disk\n"

5.    AWS::CloudFormation::Init의 파일 섹션으로 스크립트를 이동하고 명령 섹션을 사용하여 스크립트를 실행합니다.

참고: Disk0은 항상 루트 볼륨입니다.

팁: Windows 탐색기는 드라이브 시퀀스를 사전순으로 표시합니다. CloudFormation 템플릿에서 디스크 문자에 할당된 디스크 번호를 찾으려면 디스크 관리 유틸리티에서 diskmgmt 명령을 실행합니다.

6.    인스턴스를 배포한 다음 RDP(원격 데스크톱 프로토콜)를 사용하여 인스턴스에 연결합니다.

이 예제에서는 이제 인스턴스에 4개의 드라이브가 있습니다. D 드라이브에는 1단계에서 저장한 데이터 파일이 있습니다.

Drive D          =====> Drive with the data file
Drive S          =====> This is the Disk 3 
Drive X          =====> This is the Disk 2

AWS 공식
AWS 공식업데이트됨 3년 전