jaws-ug cli #19 lt - vm import by aws cli

46
JAWS-UG CLI #19 LT VM Import by AWS CLI 2015/05/11 Mon Nobuhiro Nakayama

Upload: nobuhiro-nakayama

Post on 06-Aug-2015

374 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: JAWS-UG CLI #19 LT - VM Import by AWS CLI

JAWS-UG CLI #19 LTVM Import by AWS CLI

2015/05/11 Mon

Nobuhiro Nakayama

Page 2: JAWS-UG CLI #19 LT - VM Import by AWS CLI

{

"name":"Nobuhiro Nakayama",

"company":"UCHIDAYOKO CO., LTD.",

"favorite aws services":[

"Storage Gateway",

"Directory Service",

"IAM",

"AWS CLI"

],

"certifications":[

"AWS Certified Solutions Architect-Associate",

"AWS Certified SysOps Administrator-Associate",

"Microsoft Certified Solutions Expert Server Infrastructure",

"Microsoft Certified Solutions Expert SharePoint",

"IPA Network Specialist", "IPA Information Security Specialist"

]

}

Page 3: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Agenda

• VM Importとは

• 動作要件

• インポート手順

• まとめ

2015/5/11 3

Page 4: JAWS-UG CLI #19 LT - VM Import by AWS CLI

はじめに

• このLTではExportについては触れません

• そもそも、使う機会あるの?

• ImportInstance(従来のVM Import)についても触れません• こちらの資料がとても参考になります

• http://www.slideshare.net/Yuryu/aws-vm-import-export

• Linux環境のインポートについては、触れてはいますが動作確認していません

• 2015年5月5日時点の情報です• 最新の情報は公式ドキュメントをご確認ください

• このドキュメントは個人で検証した結果をご紹介するもので、その正確性などを保証するものではありません

• 所属する組織の見解でもありません

2015/5/11 4

Page 5: JAWS-UG CLI #19 LT - VM Import by AWS CLI

VM Importとは

2015/5/11 5

Page 6: JAWS-UG CLI #19 LT - VM Import by AWS CLI

VM Importとは

• オンプレミスの仮想マシンをAWSに移行するサービス

• AWS CLI 1.7.24からec2 import-imageコマンドがサポートされるようになりました• ovaインポートのサポート

• マルチボリュームのサポート

• インポートの結果としてAMIが作成される

• 処理時間の短縮(比較検証はしていません)

• 概要はこちら

• http://aws.typepad.com/aws_japan/2015/04/vm-import-update-faster-and-more-flexible-with-multi-volume-support.html

2015/5/11 6

Page 7: JAWS-UG CLI #19 LT - VM Import by AWS CLI

動作要件

2015/5/11 7

Page 8: JAWS-UG CLI #19 LT - VM Import by AWS CLI

ドキュメントについて

• 日本語のドキュメントの更新が追いついていません(そのうち追いつくかも)

• 諦めて英語を読みましょう

• 要件や前提条件がすごく多いです

•覚悟を決めましょう

2015/5/11 8

Page 9: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Operating System (1)

• Windows (32- and 64-bit)

• Microsoft Windows Server 2012 R2 (Standard, Datacenter)

• Microsoft Windows Server 2012 (Standard, Datacenter)

• Microsoft Windows Server 2008 R2 (Standard, Datacenter, Enterprise)

• Microsoft Windows Server 2008 (Standard, Datacenter, Enterprise)

• Microsoft Windows Server 2003 R2 (Standard, Datacenter, Enterprise)

• Microsoft Windows Server 2003 (Standard, Datacenter, Enterprise) with Service Pack 1 (SP1) or later

• Microsoft Windows 7 (Professional, Enterprise, Ultimate) << ファッ?!

• Note

• VM Import currently supports importing VMs running US English versions of Microsoft Windows 7(Professional, Enterprise, Ultimate). You must have existing licenses with rights to use these licenses in a third-party, multi-tenant cloud like AWS. When importing these operating systems, you must use the BYOL flag with the licenseType parameter.

2015/5/11 9

Page 10: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Operating System (2)

• Linux/Unix (64-bit)

• Red Hat Enterprise Linux (RHEL) 5.1-5.11, 6.1-6.6, 7.0-7.1

• Note

• RHEL 6.0 is unsupported because it lacks the drivers required to run on Amazon EC2.

• VM Import supports license portability for RHEL instances. Your existing RHEL licenses are imported along with their associated RHEL instance. For more information about eligibility for Red Hat Cloud Access, see Eligibility at the Red Hat website

• CentOS 5.1-5.11, 6.1-6.6, 7.0-7.1

• Note

• CentOS 6.0 is unsupported because it lacks the drivers required to run on Amazon EC2.

• Ubuntu 12.04, 12.10, 13.04, 13.10, 14.04, 14.10

• Debian 6.0.0-6.0.8, 7.0.0-7.2.0

2015/5/11 10

Page 11: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Image Formats

• AWS supports the following image formats for importing both disks and VMs into Amazon EC2:

• RAW format for importing disks and VMs.

• Dynamic Virtual Hard Disk (VHD) image formats, which are compatible with Microsoft Hyper-V and Citrix Xen virtualization products. VHDX images are not currently supported.

• Stream-optimized ESX Virtual Machine Disk (VMDK) image format, which is compatible with VMware ESX and VMware vSphere virtualization products.

• Note

• You can only import VMDK files into Amazon EC2 that were created through the OVF export process in VMware.

• Open Virtual Appliance (OVA) image format, which supports importing images with multiple hard disks.

2015/5/11 11

Page 12: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Instance Types

• Linux環境の場合、以下のインスタンスタイプのみサポート• General purpose: t2.micro | t2.small | t2.medium | m3.medium | m3.large | m3.xlarge |

m3.2xlarge

• Compute optimized: c3.large | c3.xlarge | c3.2xlarge | c3.4xlarge | cc2.8xlarge

• Memory optimized: cr1.8xlarge

• Storage optimized: hi1.4xlarge | hs1.8xlarge | i2.xlarge | i2.2xlarge | i2.4xlarge

• GPU: cg1.4xlarge

• Windowsは特に制限なし

2015/5/11 12

Page 13: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Volume Types and File systems

• Windows (32- and 64-bit)

• VM Import/Export supports MBR-partitioned volumes that are formatted using the NTFS filesystem. Guid Partition Table (GPT) partitioned volumes are not supported.

• Linux/Unix (64-bit)

• VM Import/Export supports MBR-partitioned volumes that are formatted using ext2, ext3, ext4, Btrfs, JFS, or XFS filesystem. Guid Partition Table (GPT) partitioned volumes are not supported.

2015/5/11 13

Page 14: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)UEFIとGPTについて

• 比較的新しいWindows&64bit環境ではUEFIをサポートしています

• UEFIファームウェア

• https://msdn.microsoft.com/ja-jp/library/hh824898.aspx

• UEFIを利用する環境では、GPTパーティションからブートすることが可能です。• Windows and GPT FAQ

• https://msdn.microsoft.com/en-us/library/windows/hardware/dn640535(v=vs.85).aspx#gpt_faq_win7_boot

• Hyper-Vの第2世代の仮想マシンではUEFIファームウェアをサポートしているため、移行元の構成に注意が必要• What’s New in Hyper-V for Windows Server 2012 R2

• https://technet.microsoft.com/en-us/library/dn282278.aspx?f=255&MSPPError=-2147217396#bkmk_generation

• VMwareについてはよく知らないので、ご存じの方がいらっしゃいましたら教えてくださいw

2015/5/11 14

Page 15: JAWS-UG CLI #19 LT - VM Import by AWS CLI

VM Import Service Role

• VM Import/Exportのサービスにアクセス権限を委任するロールを作成

• vmie.amazonaws.comに対する信頼関係を設定

• Management Consoleでは設定できない(と思われる)

• Import-imageコマンドでは、ロール名がvmimportのロールをデフォルトで利用

• IAM Roleに対して、必要な権限を設定

• 詳細はドキュメントを確認• http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/VMImportPrerequisites.html

• VM Import Service Roleを参照

2015/5/11 15

Page 16: JAWS-UG CLI #19 LT - VM Import by AWS CLI

IAM Permissions (for IAM User)

• Import-imageコマンド実行するIAMユーザに対して必要な権限を定義する必要がある

• 詳細はドキュメントを確認

• http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/VMImportPrerequisites.html

• IAM Permissionsを参照

2015/5/11 16

Page 17: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Known Limitations for Importing a VMinto Amazon EC2 Using ImportImage (1)

• You can have up to twenty import image or snapshots tasks in progress at the same time per region. To request an increase to this limit, contact AWS Support. Tasks must complete within 7 days of the start date.

• Imported VMs create Amazon EC2 AMIs that use Hardware Virtual Machine (HVM) virtualization. Creating AMIs that use Paravirtual (PV) virtualization using VM Import is not supported. Linux PVHVM drivers are supported within imported instances.

• Imported Red Hat Enterprise Linux (RHEL) instances must use Cloud Access (BYOL) licenses.

• Imported Linux instances must use 64-bit images. Importing 32-bit Linux images is not supported.

• Imported Linux instances should use default kernels for best results. VMs that use custom Linux kernels might not import successfully.

• Typically, you import a compressed version of a disk image; the expanded disk image cannot exceed 1 TiB.

2015/5/11 17

Page 18: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Known Limitations for Importing a VMinto Amazon EC2 Using ImportImage (2)

• Make sure that you have at least 250 MB of available disk space for installing drivers and other software on any VM you want to import into an Amazon EC2 AMI running Microsoft Windows or Linux.

• Multiple network interfaces are not currently supported. When converted and imported, your instance will have a single virtual NIC using DHCP for address assignment.

• Internet Protocol version 6 (IPv6) IP addresses are not supported.

• For vCenter 4.0 and vSphere 4.0 users, remove any attached CD-ROM images or ISOs from the virtual machine.

2015/5/11 18

Page 19: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Known Limitations for Importing a VMinto Amazon EC2 Using ImportImage (3)

• VMs that are created as the result of a P2V conversion are not supported by Amazon EC2 VM import. A P2V conversion occurs when a disk image is created by performing a Linux or Windows installation process on a physical machine and then importing a copy of that Linux or Windows installation into a VM.

• Amazon VM Import does not install the single root I/O virtualization (SR-IOV) drivers except for imports of Microsoft Windows Server 2012 R2 VMs. These drivers are not required unless you plan to use enhanced networking, which provides higher performance (packets per second), lower latency, and lower jitter. To enable enhanced networking on a c3 or i2 instance type after you import your VM, see Enabling Enhanced Networking on Linux Instances in a VPC. For Microsoft Windows Server 2012 R2 VMs, SR-IOV driver are automatically installed as a part of the import process.

2015/5/11 19

Page 20: JAWS-UG CLI #19 LT - VM Import by AWS CLI

Known Limitations for Importing a VMinto Amazon EC2 Using ImportImage (4)

• In connection with your use of your own Microsoft licenses, such as through MSDN, to run Microsoft Software on AWS through a bring your own license (BYOL) model:

• (細かいので、以下省略)

• ドキュメントを確認してください

• ライセンスのことは、ADSJさんや日本マイクロソフトさんもしくはライセンスの販売店さんに確認しましょう

• 思い込みで判断すると火傷する可能性高い、と思います

2015/5/11 20

Page 21: JAWS-UG CLI #19 LT - VM Import by AWS CLI

インポート手順

2015/5/11 21

Page 22: JAWS-UG CLI #19 LT - VM Import by AWS CLI

手順

1. IAM User, IAM Roleの作成

2. 移行する仮想マシンの準備

3. 仮想マシンのエクスポート

4. aws s3 cp(仮想マシンをS3にアップロード)

5. aws ec2 import-image(仮想マシンをインポート)

6. Launch(AMIから仮想マシンを起動)

2015/5/11 22

Page 23: JAWS-UG CLI #19 LT - VM Import by AWS CLI

はじめに

• 以下の環境で動作確認を行いました

• 仮想マシンのOSはWindows Server 2012 R2(評価版)

• 移行元の環境はWindows版のVirtual Box(最新版)

• 仮想マシンには仮想ディスクを2つアタッチ

• OVA形式でエクスポートした仮想マシンをインポート

2015/5/11 23

Page 24: JAWS-UG CLI #19 LT - VM Import by AWS CLI

仮想マシンの構成

2015/5/11 24

Page 25: JAWS-UG CLI #19 LT - VM Import by AWS CLI

1.IAM User, IAM Roleの作成

• インポートするイメージのアップロード先となるS3 Bucketに対して権限を付与

• IAM Roleの名前は”vmimport”にしておく• 他の名前でもいいが、import-imageコマンドの実行するにオプションで指定する必要がある

• IAM Roleの作成では、「信頼関係の設定」と「権限設定」を行う必要がある

2015/5/11 25

Page 26: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)IAM Roleの作成(信頼関係の設定)

コマンドaws iam create-role

--role-name vmimport

--assume-role-policy-document

file://trust-policy.json

結果(省略)

2015/5/11 26

Page 27: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考) IAM Roleの作成(信頼関係の設定)

{

"Version":"2012-10-17",

"Statement":[

{

"Sid":"",

"Effect":"Allow",

"Principal":{

"Service":"vmie.amazonaws.com"

},

"Action":"sts:AssumeRole",

"Condition":{

"StringEquals":{

"sts:ExternalId":"vmimport"

}

}

}

]

}

2015/5/11 27

Page 28: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)IAM Roleの作成(信頼関係の設定)

2015/5/11 28

Page 29: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)IAM Roleの作成(権限設定)

{

"Version":"2012-10-17",

"Statement":[

{

"Effect":"Allow",

"Action":[

"s3:ListBucket",

"s3:GetBucketLocation"

],

"Resource":[

"arn:aws:s3:::<disk-image-file-bucket>"

]

},

2015/5/11 29

{

"Effect":"Allow",

"Action":[

"s3:GetObject"

],

"Resource":[

"arn:aws:s3:::<disk-image-file-bucket>/*"

]

},

{

"Effect":"Allow",

"Action":[

"ec2:ModifySnapshotAttribute",

"ec2:CopySnapshot",

"ec2:RegisterImage",

"ec2:Describe*"

],

"Resource":"*"

}

]

}

Page 30: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)IAM Userの作成(権限設定1)

{

"Version": "2012-10-17",

"Statement": [

{

"Effect": "Allow",

"Action": [

"s3:ListAllMyBuckets"

],

"Resource": "*"

},

2015/5/11 30

{

"Effect": "Allow",

"Action": [

"s3:CreateBucket",

"s3:DeleteBucket",

"s3:DeleteObject",

"s3:GetBucketLocation",

"s3:GetObject",

"s3:ListBucket",

"s3:PutObject"

],

"Resource": ["arn:aws:s3:::mys3bucket","arn:aws:s3:::mys3bucket/*"]

},

Page 31: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)IAM Userの作成(権限設定2)

{

"Effect": "Allow",

"Action": [

"ec2:CancelConversionTask",

"ec2:CancelExportTask",

"ec2:CreateImage",

"ec2:CreateInstanceExportTask",

"ec2:CreateTags",

"ec2:DeleteTags",

"ec2:DescribeConversionTasks",

"ec2:DescribeExportTasks",

"ec2:DescribeInstanceAttribute",

"ec2:DescribeInstanceStatus",

"ec2:DescribeInstances",

"ec2:DescribeTags",

2015/5/11 31

"ec2:ImportInstance",

"ec2:ImportVolume",

"ec2:StartInstances",

"ec2:StopInstances",

"ec2:TerminateInstances",

"ec2:ImportImage",

"ec2:ImportSnapshot",

"ec2:DescribeImportImageTasks",

"ec2:DescribeImportSnapshotTasks",

"ec2:CancelImportTask"

],

"Resource": "*"

}

]

}

Page 32: JAWS-UG CLI #19 LT - VM Import by AWS CLI

2.移行する仮想マシンの準備(共通)

• Disable any antivirus or intrusion detection software on your VM. These services can be re-enabled after the import process is complete.

• Uninstall the VMware Tools from your VMware VM.

• Disconnect any CD-ROM drives (virtual or physical).

• Set your network to DHCP instead of a static IP address. If you want to assign a static private IP address, be sure to use a non-reserved private IP address in your VPC subnet. Amazon Virtual Private Cloud (Amazon VPC) reserves the first four private IP addresses in a VPC subnet.

• Shut down your VM before exporting it from your virtualization environment.

2015/5/11 32

Page 33: JAWS-UG CLI #19 LT - VM Import by AWS CLI

2.移行する仮想マシンの準備 (Windows) (1)

• Enable Remote Desktop (RDP) for remote access.

• Make sure that your host firewall (Windows firewall or similar), if configured, allows access to RDP. Otherwise, you will not be able to access your instance after the import is complete.

• Make sure that the administrator account and all other user accounts use secure passwords. All accounts must have passwords or the importation might fail.

• Make sure that your Windows VM has .NET Framework 3.5 or later installed, as required by Amazon Windows EC2Config Service.

• You can run System Preparation (Sysprep) on your Windows Server 2008 or Windows Server 2012 VM images before or after they are imported. If you run Sysprep before importing your VM, the importation process adds an answer file (unattend.xml) to the VM that automatically accepts the End User License Agreement (EULA) and sets the locale to EN-US. If you choose to run Sysprep after importation, we recommend that you use the Amazon EC2 Config service to run Sysprep.

2015/5/11 33

Page 34: JAWS-UG CLI #19 LT - VM Import by AWS CLI

2.移行する仮想マシンの準備 (Windows) (2)

• Disable Autologon on your Windows VM.

• Make sure that there are no pending Microsoft updates, and that the computer is not set to install software when it reboots.

• Apply the following hotfixes:

• You cannot change system time if RealTimeIsUniversal registry entry is enabled in Windows

• https://support.microsoft.com/ja-jp/kb/2922223

• High CPU usage during DST changeover in Windows Server 2008, Windows 7, or Windows Server 2008 R2

• https://support.microsoft.com/ja-jp/kb/2800213

• Enable the RealTimeIsUniversal registry.

2015/5/11 34

Page 35: JAWS-UG CLI #19 LT - VM Import by AWS CLI

2.移行する仮想マシンの準備 (Linux)

• Enable Secure Shell (SSH) for remote access.

• Make sure that your host firewall (such as Linux iptables) allows access to SSH. Otherwise, you will not be able to access your instance after the import is complete.

• Make sure that you have configured a non-root user to use public key-based SSH to access your instance after it is imported. The use of password-based SSH and root login over SSH are both possible, but not recommended. The use of public keys and a non-root user is recommended because it is more secure. VM Import will not configure an ec2-user account as part of the import process.

• Make sure that your Linux VM uses GRUB (GRUB legacy) or GRUB 2 as its bootloader.

• Make sure that your Linux VM uses a root filesystem is one of the following: EXT2, EXT3, EXT4, Btrfs, JFS, or XFS.

2015/5/11 35

Page 36: JAWS-UG CLI #19 LT - VM Import by AWS CLI

3.仮想マシンのエクスポート

2015/5/11 36

Page 37: JAWS-UG CLI #19 LT - VM Import by AWS CLI

4.aws s3 cp(仮想マシンをS3にアップロード)

• ovaをS3にアップするだけでOK

• アップロード先は、IAM UserおよびIAM Roleで指定したBucket

• 次のimport-imageコマンドでBucket名およびKeyを指定するので控えておく

2015/5/11 37

Page 38: JAWS-UG CLI #19 LT - VM Import by AWS CLI

5.aws ec2 import-image(仮想マシンをインポート)

• --Disk-containers以外は任意っぽい

• --Disk-containersはjson形式で指定する必要がある• --generate-cli-skeletonで出力したフォーマットを利用するのが楽

• “S3Bucket”, ”S3Key”を最低限指定すればOK(とりあえず試したいとき)

• イメージをアップロードしたBucketおよびファイル名

2015/5/11 38

Page 39: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)import-imageコマンドを実行

コマンドaws ec2 import-image

--cli-input-json file://********.json

結果{

"Status": "active",

"Progress": "2",

"SnapshotDetails": [

{

"UserBucket": {

"S3Bucket": "nnakayama-import-by-cli",

"S3Key": "import.ova"

},

"DiskImageSize": 0.0

}

],

"StatusMessage": "pending",

"ImportTaskId": "import-ami-fh9o3may"

}

2015/5/11 39

タスクの進捗を確認するために必要

Page 40: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)--cli-input-jsonで指定するjsonの例

{

"DiskContainers": [

{

"UserBucket": {

"S3Bucket": “<s3bucket-name>",

"S3Key": “******.ova"

}

}

]

}

2015/5/11 40

Page 41: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)インポートタスクの進捗を確認

コマンドaws ec2 describe-import-image-tasks

--import-task-ids import-ami-********

結果(長いので省略)

2015/5/11 41

Page 42: JAWS-UG CLI #19 LT - VM Import by AWS CLI

6.Launch(AMIから仮想マシンを起動)

• AMIとして見えていればimportプロセス自体は成功

• Launchして、動作に問題が無ければ作業は完了• FirewallやAnti-Virusの設定を戻すことを忘れずに有効化(無効化していた場合)

• Windowsの場合、必要に応じてSysprepを実行

• EC2-Config-Serviceを最新版にアップデート

2015/5/11 42

Page 43: JAWS-UG CLI #19 LT - VM Import by AWS CLI

(参考)結果

2015/5/11 43

Page 44: JAWS-UG CLI #19 LT - VM Import by AWS CLI

まとめ

2015/5/11 44

Page 45: JAWS-UG CLI #19 LT - VM Import by AWS CLI

まとめ

• 全体的にありがたい機能が追加された

• マルチボリュームに対応

• AMIとしてのインポート

• インポート時のパラメータがかなり減った

• ただし、制約事項や手順は相変わらず多い

• 個人的にはあまりおすすめしません• やっぱり、きれいな状態の環境を構築した方がいい(今後も長期的に運用するならなおさら)

• 試行錯誤不可避、トラブルシュート大変

• OEMのライセンスが適用された仮想マシンのインポートやSysprepの応答ファイルで嵌ったり・・

• 失敗時の原因がよく分からない時がある・・

• しかし、必要な時もある• インストールメディアが無い/再入手できない・・・(´・ω・`)

• 構築手順・データ移行手順が分からない/知ってる人が退職・・・(´・ω・;`)

• 再構築する時間が無い/忙しい・・・(´;ω;`)

2015/5/11 45

Page 46: JAWS-UG CLI #19 LT - VM Import by AWS CLI

No more秘伝のタレ2015/5/11 46