在亚马逊EC2 Windows实例自动装载EBS卷 [英] Automount EBS volume in Amazon EC2 Windows Instance

查看:518
本文介绍了在亚马逊EC2 Windows实例自动装载EBS卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何自动挂载弹性块存储(EBS)卷开始时, Windows以亚马逊的弹性计算云 2003实例(EC2)?

Does anyone know how to auto-mount an Elastic Block Storage (EBS) volume when starting a Windows 2003 instance in Amazon's Elastic Compute Cloud (EC2)?

推荐答案

设置:

  • 确保EBS卷被格式化并标记(在例子中,我使用的标注PDrive工具)。
  • 在安装使用Ec2ConfigServiceSettings.exe驱动器映射
  • 在实例中安装Java
  • 安装EC2 API命令行工具
  • 在安装您的证书副本和私钥
  • 在安装curl.exe复印件(开源工具)

您可以使用组策略编辑器来设置这个脚本作为启动脚本。请参见 http://technet.microsoft.com/en-us /library/cc739591(WS.10).aspx 了解更多信息。

You can use the group policy editor to set this script as your startup script. See http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx for more information.

REM @echo off
REM setlocal ENABLEDELAYEDEXPANSION

C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 100 /so AttachEbsBoot /d "Starting attach-ebs-boot.cmd"

REM local variables
REM Make sure you include the directory with curl.exe and the EC2 command line tools in the path
set path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\Utils;C:\ebin\ec2\bin
set JAVA_HOME=c:\java
set EC2_HOME=c:\ebin\ec2
set EC2_CERT=<your_cert>
set EC2_PRIVATE_KEY=<your_private_key>

REM Please note: you should use the Ec2 Config Serive Settings application to ensure
REM that your EBS volume is mapped to a particular drive letter.
REM
REM edit as needed
set EBS_DRIVE=P:
set EBS_DEVICE=xvdp

REM Test to see if the drive is already attached. If it is then we're done.
if exist %EBS_DRIVE%\nul (goto done)

REM get the EBS volume ID from the user data and the instance ID from the meta-data
for /f "delims=" %%a in ('curl http://169.254.169.254/latest/user-data') do (set EBS_VOLUME=%%a)
for /f "delims=" %%b in ('curl http://169.254.169.254/latest/meta-data/instance-id') do (set INSTANCE_ID=%%b)

C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 102 /so AttachEbsBoot /d "Volume == %EBS_VOLUME%"
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 103 /so AttachEbsBoot /d "Instance == %INSTANCE_ID%"

REM attach the volume
REM 
REM Use a series of set command to build the command line
SET COMMAND_LINE=%EBS_VOLUME%
SET COMMAND_LINE=%COMMAND_LINE% -i
SET COMMAND_LINE=%COMMAND_LINE% %INSTANCE_ID%
SET COMMAND_LINE=%COMMAND_LINE% -d
SET COMMAND_LINE=%COMMAND_LINE% %EBS_DEVICE%

C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 104 /so AttachEbsBoot /d "calling ec2attvole %COMMAND_LINE%"

call ec2attvol.cmd %COMMAND_LINE%

:DONE
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 101 /so AttachEbsBoot /d "Exiting attach-ebs-boot.cmd"

REM Events logged in the System event log
REM source === AttachEbsBoot
REM 
REM Event 100 - Script start
REM Event 101 - Script end
REM Event 102 - Volume ID
REM Event 103 - Instance ID
REM Event 104 - Command line for ec2attvol

这篇关于在亚马逊EC2 Windows实例自动装载EBS卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆