RightScaleのCentOS5 EBS AMIを最新の状態にしてみた
比較的よく使われていると思われるRightScale社提供のCentOS5 EBS AMIを、なるべく好ましい状態で使うためのtipsです。
RightScaleのCentOS5 EBS AMIを使っている方は多いと思いますが、以下のような問題があります。
そのため、参照レポジトリを最新のものとし、pvgrubを使ってCentOSのXenカーネルで起動するようにします。
元となるインスタンスを起動
東京リージョンだと、
- 32bit ami-f0e842f1
- 64bit ami-96e84297
が該当する。今回は64bitを使用しました。
___ _ __ __ ____ __ / _ \ (_)___ _ / / / /_ / __/____ ___ _ / /___ / , _// // _ `// _ \/ __/_\ \ / __// _ `// // -_) /_/|_|/_/ \_, //_//_/\__//___/ \__/ \_,_//_/ \__/ /___/ Welcome to a virtual machine image brought to you by RightScale! [root@ip-10-160-11-15 ~]# cat /etc/redhat-release CentOS release 5.4 (Final) [root@ip-10-160-11-15 ~]# uname -a Linux ip-10-160-11-15 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:34:28 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
AMI作成前の準備 ※超重要な作業です これをやらないと絶対に起動しません
yumのレポジトリ設定を5.4指定ではなく5指定とし(現時点では5.7と等価)、Xenカーネルインストールとパッケージ更新をします。
[root@ip-10-160-11-15 ~]# sed -i "s#/5\.4/#/5/#g" /etc/yum.repos.d/CentOS-Base.repo [root@ip-10-160-11-15 ~]# yum clean all Cleaning up Everything [root@ip-10-160-11-15 ~]# yum -y install kernel-xen : : Installed: kernel-xen.x86_64 0:2.6.18-274.3.1.el5.centos.plus Complete! [root@ip-10-160-11-15 ~]# yum -y update : : Complete!
後々使用するpvgrub用のconfigファイルを置きます
[root@ip-10-160-11-15 ~]# mkdir /boot/grub [root@ip-10-160-11-15 ~]# vi /boot/grub/menu.lst default=0 timeout=3 hiddenmenu title CentOS5 root (hd0) kernel /boot/vmlinuz-2.6.18-274.3.1.el5.centos.plusxen root=/dev/sda1 console=hvc0 initrd /boot/initrd-2.6.18-274.3.1.el5.centos.plusxen.img
仮AMI作成
ここまで出来たら、一度AMI化します。Management ConsoleからCreate Image(EBS AMI)、もしくは ec2-create-image を使います。
$ ec2-create-image i-4312f243 -n centos5_prepare IMAGE ami-6cf94e6d
AMIが作成できたら、pvgrubのAKIを指定して起動してみます(このオプションがない場合には、先ほどと同じカーネルで起動されます)。
>|||
$ ec2-run-instances -k keypair -g default -t m1.large --kernel aki-ee5df7ef ami-6cf94e6d
|
sshログインしてみます。
___ _ __ __ ____ __ / _ \ (_)___ _ / / / /_ / __/____ ___ _ / /___ / , _// // _ `// _ \/ __/_\ \ / __// _ `// // -_) /_/|_|/_/ \_, //_//_/\__//___/ \__/ \_,_//_/ \__/ /___/ Welcome to a managed virtual machine brought to you by RightScale! ******************************************************************** ******************************************************************** *** Your instance is now operational. *** *** All of the configuration has completed. *** *** Please check /var/log/messages for details. *** ******************************************************************** ******************************************************************** [root@ip-10-161-10-214 ~]# cat /etc/redhat-release CentOS release 5.7 (Final) [root@ip-10-161-10-214 ~]# uname -a Linux ip-10-161-10-214 2.6.18-274.3.1.el5.centos.plusxen #1 SMP Wed Sep 7 06:25:54 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
5.7にupdateされ、カーネルもCentOS(plusですが)のカーネルとなりました。
pvgrubを指定したAMIを登録する
pvgrubのAKIを指定し、ephemeralディスクを指定したAMIを作成します。ec2-describe-imagesでsnapshotのIDを確認して、ec2-registerします。
$ ec2-describe-images ami-6cf94e6d IMAGE ami-6cf94e6d 407613804811/centos5_prepare 407613804811 available private x86_64 machine aki-a409a2a5 ari-a009a2a1 ebs paravirtual xen BLOCKDEVICEMAPPING /dev/sda1 snap-d7f63abd 8 $ ec2-register -s snap-d7f63abd -b "/dev/sdb=ephemeral0" -b "/dev/sdc=ephemeral1" -b "/dev/sdd=ephemeral2" -b "/dev/sde=ephemeral3" --kernel aki-ee5df7ef -n "CentOS 5.7 x86_64" -a x86_64 IMAGE ami-9af94e9b $ ec2-run-instances -k keypair -g default -t m1.large ami-9af94e9b
ログインして確かめます。
___ _ __ __ ____ __ / _ \ (_)___ _ / / / /_ / __/____ ___ _ / /___ / , _// // _ `// _ \/ __/_\ \ / __// _ `// // -_) /_/|_|/_/ \_, //_//_/\__//___/ \__/ \_,_//_/ \__/ /___/ Welcome to a managed virtual machine brought to you by RightScale! ******************************************************************** ******************************************************************** *** Your instance is now operational. *** *** All of the configuration has completed. *** *** Please check /var/log/messages for details. *** ******************************************************************** ******************************************************************** [root@ip-10-161-26-122 ~]# cat /etc/redhat-release CentOS release 5.7 (Final) [root@ip-10-161-26-122 ~]# uname -a Linux ip-10-161-26-122 2.6.18-274.3.1.el5.centos.plusxen #1 SMP Wed Sep 7 06:25:54 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
ちゃんとCentOSのカーネルで起動するようになりました。先ほど一時的に使用したAMIはde-registerしておきましょう。