Amazon EC2にgit serverをインストールする [aws][git]

まずは、git データを保存する用のボリュームを EBS で作成します。

% ec2-create-volume --region us-west-1 -z us-west-1b -s 1
VOLUME vol-217b854d 1 us-west-1b creating 2011-05-05T02:31:31+0000
% ec2-attach-volume --region us-west-1 -d /dev/sdb -i i-a2c5efe6 vol-217b854d
ATTACHMENT vol-217b854d i-a2c5efe6 /dev/sdb attaching 2011-05-05T02:33:03+0000
% ec2-describe-volumes --region us-west-1
VOLUME vol-b01ae9da 15 snap-ad7ed5c6 us-west-1a available 2010-11-28T09:24:07+0000
VOLUME vol-ed0af481 15 snap-455e2c2e us-west-1b available 2011-05-05T02:00:53+0000
VOLUME vol-6d09f701 15 snap-455e2c2e us-west-1b available 2011-05-05T02:06:06+0000
VOLUME vol-e505fb89 15 snap-455e2c2e us-west-1b in-use 2011-05-05T02:15:18+0000
ATTACHMENT vol-e505fb89 i-a2c5efe6 /dev/sda1 attached 2011-05-05T02:15:36+0000
VOLUME vol-217b854d 1 us-west-1b in-use 2011-05-05T02:31:31+0000
ATTACHMENT vol-217b854d i-a2c5efe6 /dev/sdb attached 2011-05-05T02:33:10+0000


作成したボリュームをマウントします。

% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-50-18-69-25.us-west-1.compute.amazonaws.com
ubuntu@ip-10-167-9-55:~$ sudo mkfs -t ext3 /dev/sdb
ubuntu@ip-10-167-9-55:~$ sudo mkdir /vol
ubuntu@ip-10-167-9-55:~$ sudo mount /dev/sdb /vol
ubuntu@ip-10-167-9-55:~$ ls /vol
lost+found


gitをインストールし、共有リポジトリを設定します。

ubuntu@ip-10-167-9-55:~$ sudo groupadd gitusers
ubuntu@ip-10-167-9-55:~$ sudo usermod -a -G gitusers <ユーザ名>
ubuntu@ip-10-167-9-55:~$ exit
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-50-18-69-25.us-west-1.compute.amazonaws.com
ubuntu@ip-10-167-9-55:~$ umask 002
ubuntu@ip-10-167-9-55:~$ mkdir -p /vol/pub/repositories/gitusers.git
ubuntu@ip-10-167-9-55:~$ cd /vol/pub/repositories/gitusers.git
ubuntu@ip-10-167-9-55:~$ chgrp gitusers .
ubuntu@ip-10-167-9-55:~$ git --bare init --shared
ubuntu@ip-10-167-9-55:~$ cd $HOME
ubuntu@ip-10-167-9-55:~$ mkdir -p work/git
ubuntu@ip-10-167-9-55:~$ cd work/git
ubuntu@ip-10-167-9-55:~$ git clone /vol/pub/repositories/gitusers.git
ubuntu@ip-10-167-9-55:~$ cd gitusers
ubuntu@ip-10-167-9-55:~$ echo test > test.txt
ubuntu@ip-10-167-9-55:~$ git add test.txt
ubuntu@ip-10-167-9-55:~$ git commit -m "test."
ubuntu@ip-10-167-9-55:~$ git push origin master


https 経由で git リポジトリにアクセスできるようにします。

まずは、apache のインストール。

ubuntu@ip-10-167-9-55:~$ sudo apt-get update
ubuntu@ip-10-167-9-55:~$ sudo apt-get install apache2
ubuntu@ip-10-167-9-55:~$ % cd /etc/apache2/sites-available
ubuntu@ip-10-167-9-55:~$ % sudo cp -a default mysite
ubuntu@ip-10-167-9-55:~$ % sudo a2dissite default
ubuntu@ip-10-167-9-55:~$ % sudo a2ensite mysite
ubuntu@ip-10-167-9-55:~$ % sudo usermod -a -G gitusers www-data
ubuntu@ip-10-167-9-55:~$ % sudo usermod -s /usr/sbin/nologin www-data
ubuntu@ip-10-167-9-55:~$ % sudo service apache2 restart
ubuntu@ip-10-167-9-55:~$ exit
% ec2-authorize --region us-west-1 default -p 80


git の http 公開設定。

% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-50-18-69-25.us-west-1.compute.amazonaws.com
ubuntu@ip-10-167-9-55:~$ cd /etc/apache2/sites-available
ubuntu@ip-10-167-9-55:~$ sudo vi gitusers.git
<Location /git>
  Options Indexes
  DAV on
  AuthType Basic
  AuthName "Git repository"
  AuthUserFile /etc/apache2/.htpasswd
  Require valid-user
</Location>
ubuntu@ip-10-167-9-55:~$ sudo htpasswd -c /etc/apache2/.htpasswd <ユーザ名>
ubuntu@ip-10-167-9-55:~$ sudo chmod 644 /etc/apache2/.htpasswd
ubuntu@ip-10-167-9-55:~$ sudo a2ensite gitusers.git
ubuntu@ip-10-167-9-55:~$ cd /etc/apache2/mods-available
ubuntu@ip-10-167-9-55:~$ sudo a2enmod dav dav_lock dav_fs
ubuntu@ip-10-167-9-55:~$ cd /vol/pub/repositories/gitusers.git
ubuntu@ip-10-167-9-55:~$ git update-server-info
ubuntu@ip-10-167-9-55:~$ sudo service apache2 restart


以下のコマンドで git clone できるようになりました。

% git clone http://<ユーザ名>@ec2-204-236-137-101.us-west-1.compute.amazonaws.com/git/gitusers.git/


git push もできました。


最後に、これまでに行った設定をスナップショットとして保存しておきます。

% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-50-18-69-25.us-west-1.compute.amazonaws.com sudo umount /vol
% ec2-detach-volume --region us-west-1 vol-217b854d
% ec2-create-image --region us-west-1 i-20d9f364 --name "Ubuntu 10.04 LTS git"

Amazon EC2 でインスタンスを作成する [aws]

Docs: Amazon EC2 (API Version 2010-08-31) を参考に、

OS: Ubuntu 10.04 LTS
Region: us-west-1
arch: 32-bit
root store: ebs
ami: ami-8c0c5cc9
の Micro Instance を作成します。

% ec2-add-keypair ec2-keypair > ~/.ssh/ec2-keypair.pem
% chmod 600 ~/.ssh/ec2-keypair.pem
% ec2-run-instances ami-8c0c5cc9 --instance-type t1.micro --region us-west-1 -k ec2-keypair
Client.InvalidKeyPair.NotFound: The key pair 'ec2-keypair' does not exist

とエラーになってしまいました。

% ec2-add-keypair --region us-west-1 ec2-keypair > ~/.ssh/ec2-keypair.pem
% ec2-run-instances ami-8c0c5cc9 --instance-type t1.micro --region us-west-1 -k ec2-keypair

でうまくいきました。

% ec2-describe-instances --region us-west-1

でインスタンスの状態が確認できます。

ssh で接続してみます。

% ec2-authorize --region us-west-1 default -p 22
GROUP default
PERMISSION default ALLOWS tcp 22 22 FROM CIDR 0.0.0.0/0
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@<external-host-name>

The authenticity of host 'ec2-204-236-160-249.us-west-1.compute.amazonaws.com (204.236.160.249)' can't be established.
RSA key fingerprint is b8:02:c6:a3:6d:6c:f0:ed:c4:29:b6:39:12:36:0e:ff.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-204-236-160-249.us-west-1.compute.amazonaws.com,204.236.160.249' (RSA) to the list of known hosts.
Linux ip-10-160-119-84 2.6.32-309-ec2 #18-Ubuntu SMP Mon Oct 18 21:00:20 UTC 2010 i686 GNU/Linux
Ubuntu 10.04.1 LTS

Welcome to Ubuntu!
 * Documentation: https://help.ubuntu.com/
 
 System information as of Sat Nov 27 06:44:16 UTC 2010
 
 System load: 0.0 Processes: 54
 Usage of /: 4.7% of 14.76GB Users logged in: 0
 Memory usage: 4% IP address for eth0: 10.160.119.84
 Swap usage: 0%

 Graph this data and manage this system at https://landscape.canonical.com/


-----------------------------------------------------------------
At the moment, only the core of the system is installed. To tune the
system to your needs, you can choose to install one or more
predefined collections of software by running the following
command:
                                                             
   sudo tasksel --section server

-----------------------------------------------------------------

0 packages can be updated.
0 updates are security updates.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ip-10-160-119-84:~$


<external-host-name> は ec2-describe-instances コマンドで表示される ec2-xxx-xxx-xxx-xxx.us-west-1.compute.amazonaws.com です。


次に、今起動したマシンを自分用に保存するためにイメージを作成します。

% ec2-create-image --region us-west-1 i-907cf3d4 --name "Ubuntu 10.04 LTS"
IMAGE ami-875505c2


いったん終了し、先ほど作ったイメージで起動します。

% ec2-terminate-instances --region us-west-1 i-907cf3d4
INSTANCE i-907cf3d4 running shutting-down
% ec2-run-instances ami-875505c2 --instance-type t1.micro --region us-west-1 -k ec2-keypair
Client.InvalidAMIID.Unavailable: AMI 'ami-875505c2' is failed, and cannot be run

とエラーになってしまいました。

下記のように AMI 自体は存在しているようなのですが。。
% ec2-describe-images --region us-west-1 ami-875505c2
IMAGE ami-875505c2 477760378464/Ubuntu 10.04 LTS 477760378464 failed private i386
    machine aki-e40c5ca1 ebs paravirtual


ec2-run-instances からやり直して、今度はスナップショットを作成し、スナップショットから AMI を作成し、その AMI からインスタンスを起動してみました。

% ec2-create-snapshot --region us-west-1 vol-d43acbbe
SNAPSHOT snap-a16e1eca vol-d43acbbe pending 2010-11-27T08:06:40+0000 477760378464 15
% ec2-register --region us-west-1 -n "Ubuntu 10.04 vol" -s snap-a16e1eca
IMAGE ami-8f5505ca
% ec2-terminate-instances --region us-west-1 i-4a74fb0e
INSTANCE i-4a74fb0e running shutting-down
% ec2-run-instances ami-8f5505ca --instance-type t1.micro --region us-west-1 -k ec2-keypair
RESERVATION r-e6b20ea2 477760378464 default
INSTANCE i-4872fd0c ami-8f5505ca pending ec2-keypair 0 t1.micro 2010-11-27T08:13:40+0000 us-west-1b monitoring-disabledebs paravirtual

うまくいったようです。

しかし、ssh で接続してみるとタイムアウトしてしまいます。

% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-184-72-23-235.us-west-1.compute.amazonaws.com
ssh: connect to host ec2-184-72-23-235.us-west-1.compute.amazonaws.com port 22: Operation timed out


stop /start で再起動してもダメ。

% ec2-stop-instances --region us-west-1 i-4872fd0c
INSTANCE i-4872fd0c running stopping
% ec2-start-instances --region us-west-1 i-4872fd0c
INSTANCE i-4872fd0c stopped pending
% ec2-describe-instances --region us-west-1
RESERVATION r-64b10d20 477760378464 default
INSTANCE i-4a74fb0e ami-8c0c5cc9 terminated ec2-keypair 0 t1.micro 2010-11-27T08:00:10+0000 us-west-1b aki-e40c5ca1 monitoring-disabled ebs paravirtual
RESERVATION r-e6b20ea2 477760378464 default
INSTANCE i-4872fd0c ami-8f5505ca ec2-204-236-170-23.us-west-1.compute.amazonaws.com ip-10-160-117-65.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-27T08:31:59+0000 us-west-1b monitoring-disabled 204.236.170.23 10.160.117.65 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-2020d14a 2010-11-27T08:13:43.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-204-236-170-23.us-west-1.compute.amazonaws.com
ssh: connect to host ec2-204-236-170-23.us-west-1.compute.amazonaws.com port 22: Operation timed out


こんどはボリュームからスナップショットを作成し、スナップショットから AMI を作成し、その AMI からインスタンスを起動してみました。

% ec2-create-snapshot --region us-west-1 vol-f049b99a
SNAPSHOT snap-b1abd8da vol-f049b99a pending 2010-11-28T00:51:18+0000 477760378464 15
% ec2-terminate-instances --region us-west-1 i-3ad55b7e
INSTANCE i-3ad55b7e running shutting-down
% ec2-register --region us-west-1 -n "Ubuntu 10.04 vol2" -s snap-b1abd8da
IMAGE ami-55560610
% ec2-run-instances ami-55560610 --instance-type t1.micro --region us-west-1 -k ec2-keypair
RESERVATION r-6e59e52a 477760378464 default
INSTANCE i-b0d25cf4 ami-55560610 pending ec2-keypair 0 t1.micro 2010-11-28T00:56:14+0000 us-west-1b monitoring-disabledebs paravirtual
% ec2-describe-instances --region us-west-1
RESERVATION r-fa5fe3be 477760378464 default
INSTANCE i-3ad55b7e ami-8c0c5cc9 terminated ec2-keypair 0 t1.micro 2010-11-28T00:41:11+0000 us-west-1a aki-e40c5ca1 monitoring-disabled ebs paravirtual
RESERVATION r-6e59e52a 477760378464 default
INSTANCE i-b0d25cf4 ami-55560610 ec2-184-72-22-188.us-west-1.compute.amazonaws.com ip-10-161-106-242.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T00:56:14+0000 us-west-1b monitoring-disabled 184.72.22.188 10.161.106.242 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-f44fbf9e 2010-11-28T00:56:18.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-184-72-22-188.us-west-1.compute.amazonaws.com
ssh: connect to host ec2-184-72-22-188.us-west-1.compute.amazonaws.com port 22: Operation timed out


AMI 作成時に、--root-device-name を追加してみたが、変わらず。

% ec2-create-snapshot --region us-west-1 vol-48897a22
SNAPSHOT snap-15ff8c7e vol-48897a22 pending 2010-11-28T03:58:24+0000 477760378464 15
% ec2-register --region us-west-1 -n "Ubuntu 10.04 vol" -s snap-15ff8c7e --root-device-name /dev/sda1
IMAGE ami-5f56061a
% ec2-terminate-instances --region us-west-1 i-ece26ca8
INSTANCE i-ece26ca8 running shutting-down
% ec2-run-instances ami-5f56061a --instance-type t1.micro --region us-west-1 -k ec2-keypair
RESERVATION r-b848f4fc 477760378464 default
INSTANCE i-00e06e44 ami-5f56061a pending ec2-keypair 0 t1.micro 2010-11-28T04:07:03+0000 us-west-1b monitoring-disabledebs paravirtual
% ec2-describe-instances --region us-west-1
RESERVATION r-b848f4fc 477760378464 default
INSTANCE i-00e06e44 ami-5f56061a ec2-204-236-159-61.us-west-1.compute.amazonaws.com ip-10-160-117-222.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T04:07:03+0000 us-west-1b monitoring-disabled 204.236.159.61 10.160.117.222 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-e88d7e82 2010-11-28T04:07:12.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-204-236-159-61.us-west-1.compute.amazonaws.com
ssh: connect to host ec2-204-236-159-61.us-west-1.compute.amazonaws.com port 22: Operation timed out


reboot しても変わらず。

% ec2-reboot-instances --region us-west-1 i-00e06e44
% ec2-describe-instances --region us-west-1
RESERVATION r-b848f4fc 477760378464 default
INSTANCE i-00e06e44 ami-5f56061a ec2-204-236-159-61.us-west-1.compute.amazonaws.com ip-10-160-117-222.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T04:07:03+0000 us-west-1b monitoring-disabled 204.236.159.61 10.160.117.222 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-e88d7e82 2010-11-28T04:07:12.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-204-236-159-61.us-west-1.compute.amazonaws.com
ssh: connect to host ec2-204-236-159-61.us-west-1.compute.amazonaws.com port 22: Operation timed out


IP 指定でも変わらず。

% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@204.236.159.61
ssh: connect to host 204.236.159.61 port 22: Operation timed out


ec2-register -s ではなく -b /dev/sda1=snap-XXXXXXXX で AMI を作成してみるも、変わらず。

% ec2-register --region us-west-1 -n "Ubuntu 10.04 vol2" --root-device-name /dev/sda1 -b /dev/sda1=snap-15ff8c7e
IMAGE ami-65560620
% ec2-run-instances ami-65560620 --instance-type t1.micro --region us-west-1 -k ec2-keypair
RESERVATION r-0c3c8048 477760378464 defaultINSTANCE i-9ef47ada ami-65560620 pending ec2-keypair 0 t1.micro 2010-11-28T06:17:59+0000 us-west-1a monitoring-disabledebs paravirtual
% ec2-describe-instances --region us-west-1
RESERVATION r-0c3c8048 477760378464 default
INSTANCE i-9ef47ada ami-65560620 ec2-204-236-146-218.us-west-1.compute.amazonaws.com ip-10-162-23-72.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T06:17:59+0000 us-west-1a monitoring-disabled 204.236.146.218 10.162.23.72 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-2cd82b46 2010-11-28T06:18:06.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-204-236-146-218.us-west-1.compute.amazonaws.com
ssh: connect to host ec2-204-236-146-218.us-west-1.compute.amazonaws.com port 22: Operation timed out


telnet は反応せず。

% telnet ec2-204-236-169-246.us-west-1.compute.amazonaws.com 22
Trying 204.236.169.246...
^C


ec2-get-console-output は下記のようになった。

% ec2-get-console-output --region us-west-1 i-78f07e3c
i-78f07e3c
2010-11-28T07:04:21+0000
Linux version 2.6.16-xenU (builder@xenbat.amazonsa) (gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)) #1 SMP Mon May 28 03:41:49 SAST 2007
BIOS-provided physical RAM map:
Xen: 0000000000000000 - 0000000026700000 (usable)
0MB HIGHMEM available.
623MB LOWMEM available.
NX (Execute Disable) protection: active
IRQ lockup detection disabled
Built 1 zonelists
Kernel command line: root=/dev/sda1 ro 4
Enabling fast FPU save and restore... done.
Enabling unmasked SIMD FPU exception support... done.
Initializing CPU#0
PID hash table entries: 4096 (order: 12, 65536 bytes)
Xen reported: 2659.996 MHz processor.
Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
Software IO TLB disabled
vmalloc area: e7800000-f53fe000, maxmem 2d7fe000
Memory: 618496k/637952k available (1958k kernel code, 10960k reserved, 620k data, 144k init, 0k highmem)
Checking if this processor honours the WP bit even in supervisor mode... Ok.
Calibrating delay using timer specific routine.. 5327.88 BogoMIPS (lpj=26639424)
Mount-cache hash table entries: 512
CPU: L1 I cache: 32K, L1 D cache: 32K
CPU: L2 cache: 6144K
Checking 'hlt' instruction... OK.
Brought up 1 CPUs
migration_cost=0
Grant table initialized
NET: Registered protocol family 16
Brought up 1 CPUs
xen_mem: Initialising balloon driver.
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
Initializing Cryptographic API
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
i8042.c: No controller found.
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
Xen virtual console successfully installed as tty1
Event-channel device installed.
netfront: Initialising virtual ethernet driver.
mice: PS/2 mouse device common for all mice
md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: bitmap version 4.39
NET: Registered protocol family 2
Registering block device major 8
IP route cache hash table entries: 32768 (order: 5, 131072 bytes)
TCP established hash table entries: 131072 (order: 8, 1048576 bytes)
TCP bind hash table entries: 65536 (order: 7, 524288 bytes)
TCP: Hash tables configured (established 131072 bind 65536)
TCP reno registered
TCP bic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
NET: Registered protocol family 15
Using IPI No-Shortcut mode
md: Autodetecting RAID arrays.
md: autorun ...
md: ... autorun DONE.
EXT3-fs: INFO: recovery required on readonly filesystem.
EXT3-fs: write access will be enabled during recovery.
kjournald starting. Commit interval 5 seconds
EXT3-fs: recovery complete.
EXT3-fs: mounted filesystem with ordered data mode.
VFS: Mounted root (ext3 filesystem) readonly.
Freeing unused kernel memory: 144k freed
libudev: udev_monitor_new_from_netlink: error getting socket: Invalid argument
mountall:mountall.c:3204: Assertion failed in main: udev_monitor = udev_monitor_new_from_netlink (udev, "udev")
init: mountall main process (595) killed by ABRT signal
modprobe: FATAL: Could not load /lib/modules/2.6.16-xenU/modules.dep: No such file or directory

modprobe: FATAL: Could not load /lib/modules/2.6.16-xenU/modules.dep: No such file or directory

modprobe: FATAL: Could not load /lib/modules/2.6.16-xenU/modules.dep: No such file or directory

modprobe: FATAL: Could not load /lib/modules/2.6.16-xenU/modules.dep: No such file or directory

modprobe: FATAL: Could not load /lib/modules/2.6.16-xenU/modules.dep: No such file or directory

modprobe: FATAL: Could not load /lib/modules/2.6.16-xenU/modules.dep: No such file or directory

init: console-setup main process (598) terminated with status 1
General error mounting filesystems.
A maintenance shell will now be started.
CONTROL-D will terminate this shell and reboot the system.
Give root password for maintenance
(or type Control-D to continue):


Ubuntu Official のインスタンスを起動する際に -b /dev/sda1=::false でボリュームを永続化して、AMI は Web GUI から作成すると ssh 接続できた。

% ec2-run-instances ami-8c0c5cc9 --instance-type t1.micro --region us-west-1 -k ec2-keypair -b /dev/sda1=::false
RESERVATION r-d834889c 477760378464 default
INSTANCE i-988d03dc ami-8c0c5cc9 pending ec2-keypair 0 t1.micro 2010-11-28T08:06:20+0000 us-west-1a aki-e40c5ca1 monitoring-disabled ebs paravirtual

Web の AWS Management Console の Instances から右クリックして、AMI を作成します。

% ec2-describe-instances --region us-west-1
RESERVATION r-d23f8396 477760378464 default
INSTANCE i-78f07e3c ami-65560620 terminated ec2-keypair 0 t1.micro 2010-11-28T07:00:58+0000 us-west-1a monitoring-disabledebs paravirtual
RESERVATION r-d834889c 477760378464 default
INSTANCE i-988d03dc ami-8c0c5cc9 ec2-204-236-140-6.us-west-1.compute.amazonaws.com ip-10-162-145-24.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T08:06:20+0000 us-west-1a aki-e40c5ca1 monitoring-disabled 204.236.140.6 10.162.145.24 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-3c3ecd56 2010-11-28T08:06:29.000Z
% ec2-run-instances ami-6b56062e --instance-type t1.micro --region us-west-1 -k ec2-keypair
RESERVATION r-d0318d94 477760378464 default
INSTANCE i-6a87092e ami-6b56062e pending ec2-keypair 0 t1.micro 2010-11-28T09:02:20+0000 us-west-1b aki-e40c5ca1 monitoring-disabled ebs paravirtual
% ec2-describe-instances --region us-west-1
RESERVATION r-d23f8396 477760378464 default
INSTANCE i-78f07e3c ami-65560620 terminated ec2-keypair 0 t1.micro 2010-11-28T07:00:58+0000 us-west-1a monitoring-disabledebs paravirtual
RESERVATION r-d834889c 477760378464 default
INSTANCE i-988d03dc ami-8c0c5cc9 ec2-204-236-140-6.us-west-1.compute.amazonaws.com ip-10-162-145-24.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2
010-11-28T08:06:20+0000 us-west-1a aki-e40c5ca1 monitoring-disabled 204.236.140.6 10.162.145.24 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-3c3ecd56 2010-11-28T08:06:29.000Z
RESERVATION r-d0318d94 477760378464 default
INSTANCE i-6a87092e ami-6b56062e ec2-184-72-25-130.us-west-1.compute.amazonaws.com ip-10-161-29-181.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T09:02:20+0000 us-west-1b aki-e40c5ca1 monitoring-disabled 184.72.25.130 10.161.29.181 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-a412e1ce 2010-11-28T09:02:22.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-184-72-25-130.us-west-1.compute.amazonaws.com
The authenticity of host 'ec2-184-72-25-130.us-west-1.compute.amazonaws.com (184.72.25.130)' can't be established.
RSA key fingerprint is d7:f9:c9:fc:88:9f:4b:ca:29:e9:82:dd:47:ea:8f:1b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-184-72-25-130.us-west-1.compute.amazonaws.com,184.72.25.130' (RSA) to the list of known hosts.
Linux ip-10-161-29-181 2.6.32-309-ec2 #18-Ubuntu SMP Mon Oct 18 21:00:20 UTC 2010 i686 GNU/Linux
Ubuntu 10.04.1 LTS
  
Welcome to Ubuntu!
 * Documentation: https://help.ubuntu.com/
  
  System information as of Sun Nov 28 09:03:37 UTC 2010
    
  System load: 0.3 Processes: 73
  Usage of /: 4.7% of 14.76GB Users logged in: 0
  Memory usage: 4% IP address for eth0: 10.161.29.181
  Swap usage: 0%
    
  Graph this data and manage this system at https://landscape.canonical.com/


-----------------------------------------------------------------
At the moment, only the core of the system is installed. To tune the
system to your needs, you can choose to install one or more
predefined collections of software by running the following
command:
  
   sudo tasksel --section server

-----------------------------------------------------------------

0 packages can be updated.
0 updates are security updates.
  
Last login: Sun Nov 28 08:10:39 2010 from softbank218138246252.bbtec.net
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
  
ubuntu@ip-10-161-29-181:~$ ls
hoge
ubuntu@ip-10-161-29-181:~$ exit
logout
logout
Connection to ec2-184-72-25-130.us-west-1.compute.amazonaws.com closed.


元のインスタンスが起動したままだったので終了してみても大丈夫でした。

% ec2-describe-instances --region us-west-1
RESERVATION r-d834889c 477760378464 default
INSTANCE i-988d03dc ami-8c0c5cc9 ec2-204-236-140-6.us-west-1.compute.amazonaws.com ip-10-162-145-24.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2
010-11-28T08:06:20+0000 us-west-1a aki-e40c5ca1 monitoring-disabled 204.236.140.6 10.162.145.24 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-3c3ecd56 2010-11-28T08:06:29.000Z
RESERVATION r-d0318d94 477760378464 default
INSTANCE i-6a87092e ami-6b56062e ec2-184-72-25-130.us-west-1.compute.amazonaws.com ip-10-161-29-181.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T09:02:20+0000 us-west-1b aki-e40c5ca1 monitoring-disabled 184.72.25.130 10.161.29.181 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-a412e1ce 2010-11-28T09:02:22.000Z
% ec2-terminate-instances --region us-west-1 i-988d03dc
INSTANCE i-988d03dc running shutting-down
% ec2-describe-instances --region us-west-1
RESERVATION r-d834889c 477760378464 default
INSTANCE i-988d03dc ami-8c0c5cc9 terminated ec2-keypair 0 t1.micro 2010-11-28T08:06:20+0000 us-west-1a aki-e40c5ca1 monitoring-disabled ebs paravirtual
RESERVATION r-d0318d94 477760378464 default
INSTANCE i-6a87092e ami-6b56062e ec2-184-72-25-130.us-west-1.compute.amazonaws.com ip-10-161-29-181.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T09:02:20+0000 us-west-1b aki-e40c5ca1 monitoring-disabled 184.72.25.130 10.161.29.181 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-a412e1ce 2010-11-28T09:02:22.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-184-72-25-130.us-west-1.compute.amazonaws.com
Linux ip-10-161-29-181 2.6.32-309-ec2 #18-Ubuntu SMP Mon Oct 18 21:00:20 UTC 2010 i686 GNU/Linux
Ubuntu 10.04.1 LTS

Welcome to Ubuntu!


Ubuntu Official のインスタンスを起動する際に -b /dev/sda1=::false でボリュームを永続化して、AMI は Web GUI からではなく、ec2-create-image で作成しても ssh 接続できた。

% ec2-run-instances ami-8c0c5cc9 --instance-type t1.micro --region us-west-1 -k ec2-keypair -b /dev/sda1=::false
RESERVATION r-36338f72 477760378464 default
INSTANCE i-64850b20 ami-8c0c5cc9 pending ec2-keypair 0 t1.micro 2010-11-28T09:24:03+0000 us-west-1a aki-e40c5ca1 monitoring-disabled ebs paravirtual
% ec2-create-image --region us-west-1 i-64850b20 --name "Ubuntu 10.04 LTS"
IMAGE ami-71560634
% ec2-run-instances ami-71560634 --instance-type t1.micro --region us-west-1 -k ec2-keypair
RESERVATION r-862d91c2 477760378464 default
INSTANCE i-d0830d94 ami-71560634 pending ec2-keypair 0 t1.micro 2010-11-28T09:49:22+0000 us-west-1b aki-e40c5ca1 monitoring-disabled ebs paravirtual
% ec2-describe-instances --region us-west-1
RESERVATION r-36338f72 477760378464 default
INSTANCE i-64850b20 ami-8c0c5cc9 ec2-204-236-160-211.us-west-1.compute.amazonaws.comip-10-162-249-121.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T09:24:03+0000 us-west-1a aki-e40c5ca1 monitoring-disabled 204.236.160.211 10.162.249.121 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-b01ae9da 2010-11-28T09:24:07.000Z
RESERVATION r-862d91c2 477760378464 default
INSTANCE i-d0830d94 ami-71560634 ec2-204-236-160-131.us-west-1.compute.amazonaws.comip-10-160-59-242.us-west-1.compute.internal running ec2-keypair 0 t1.micro 2010-11-28T09:49:22+0000 us-west-1b aki-e40c5ca1 monitoring-disabled 204.236.160.131 10.160.59.242 ebs paravirtual
BLOCKDEVICE /dev/sda1 vol-7c07f416 2010-11-28T09:49:28.000Z
% ssh -i ~/.ssh/ec2-keypair.pem ubuntu@ec2-204-236-160-131.us-west-1.compute.amazonaws.com
The authenticity of host 'ec2-204-236-160-131.us-west-1.compute.amazonaws.com (204.236.160.131)' can't be established.
RSA key fingerprint is 2a:8f:9f:f5:51:36:df:d0:a9:39:0b:4d:c6:70:ab:54.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-204-236-160-131.us-west-1.compute.amazonaws.com,204.236.160.131' (RSA) to the list of known hosts.
Linux ip-10-160-59-242 2.6.32-309-ec2 #18-Ubuntu SMP Mon Oct 18 21:00:20 UTC 2010 i686 GNU/Linux
Ubuntu 10.04.1 LTS
  
Welcome to Ubuntu!

いちいち --region us-west-1 を指定するのは面倒くさいので、デフォルトリージョンを指定できないのか?