Frage

Wer weiß, wie man Auto-Mount ein Elastic Block Storage (EBS) Volumen beim Start eine Instanz von Windows 2003 in Amazon Elastic Compute Cloud (EC2)?

War es hilfreich?

Lösung

Setup:

  • Stellen Sie sicher, dass die EBS-Datenträger formatiert und markiert (im Beispiel verwendete ich das Etikett PDRIVE).
  • Setup eine Laufwerkszuordnung mit Ec2ConfigServiceSettings.exe
  • Installieren Java auf der Instanz
  • Installieren der EC2-API-Kommandozeilen-Tools
  • Installieren Sie eine Kopie Ihres cert und privaten Schlüssel
  • Installieren Sie eine Kopie von curl.exe (Open-Source-Tool)

Sie können die Gruppenrichtlinien-Editor verwenden dieses Skript als Startskript zu setzen. Siehe http://technet.microsoft.com/en- us / library / cc739591 (WS.10) aspx für weitere Informationen.

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

Andere Tipps

ich den folgenden Ruby-Code in http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/ mit freundlicher Genehmigung von Carson McDonald. Es ist für Linux / Unix, aber vielleicht können Sie dies für Ruby on Windows 2003 erneut swizzle oder haben es als Modell dienen für sie in einer anderen Skriptsprache zu tun.

Beachten Sie, dass Sie die Dinge in Ihr Bild als Benutzerdaten wie das ECS EBS Volume-ID und dem Gerätenamen (zum Beispiel / dev / SDH- im folgenden Beispiel oder was auch immer es in Windows für Ihren Fall wäre) passieren könnte. Sie können die Benutzerdaten von der Instanz zugreifen, sich als Meta-Daten wie etwa unten getan wird, um die Instanz-ID zu bekommen. Genauer gesagt, würden Sie Zugriff auf http://169.254.169.254/1.0/user-data an die Benutzer-Daten zu erhalten.

#!/usr/bin/ruby

require 'rubygems'
require 'right_aws'
require 'net/http'

url = 'http://169.254.169.254/2008-02-01/meta-data/instance-id'
instance_id = Net::HTTP.get_response(URI.parse(url)).body

AMAZON_PUBLIC_KEY='your public key'
AMAZON_PRIVATE_KEY='your private key'
EC2_LOG_VOL='the volume id'

ec2 = RightAws::Ec2.new(AMAZON_PUBLIC_KEY, AMAZON_PRIVATE_KEY)

vol = ec2.attach_volume(EC2_LOG_VOL, instance_id, '/dev/sdh')
puts vol

# It can take a few seconds for the volume to become ready.
# This is just to make sure it is ready before mounting it.
sleep 20

system('mount /dev/sdh /mymountpoint')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top