SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
オリジナルAMIの作成
   (CentOS)
  suz-lab (AWS+)
黒いブログ(suz-lab)、書いてます。
目次

ext3の空イメージを作成
イメージマウントとデバイスファイル作成
fstabの作成とprocのマウント
yumでCoreグループをインストール
ネットワークの設定ファイルを作成 
再びfstab、に追記
起動時にキー取得の仕込み
Amazon EC2 AMI Tools のインストール
登録用(S3アップロード用)イメージの作成
登録用イメージをS3にアップロード 
AMIとして登録
ext3の空イメージを作成

 全データがNULL(/dev/zero)のファイル(centos.img)を作成。
 サイズは count(1024) x bs(1M) = 1G とする。(最小構成)

# dd if=/dev/zero of=centos.img count=1024 bs=1M

 上記の空イメージに(-F)、ext3ジャーナルを持った(-j)ファイル
 システムを作成。

# mke2fs -F -j centos.img

 このイメージファイルがS3にアップロードされるAMIです。
イメージマウントとデバイスファイル作成

 ループバックデバイス(-o loop)としてイメージをマウント。
 ※ ファイルをブロック型デバイスのように扱う機能

# mkdir fs-centos
# mount -o loop centos.img fs-centos

 イメージにデバイスファイル(fs-centos/dev)を作成します。
   でも、ループの意味とか"-x"とか、よくわかりません...

# mkdir fs-centos/dev
# for i in console null zero; do
# /sbin/MAKEDEV -d fs-centos/dev -x $i;
# done
fstabの作成とprocのマウント

 イメージ中に以下のようにfstabを作成
 (AMI起動時、このイメージの内容は/dev/sda1になります)

 # cat fs-centos/etc/fstab
 /dev/sda1 /           ext3 defaults       11
 none       /dev/pts devpts gid=5,mode=620 0 0
 none       /dev/shm tmpfs defaults        00
 none       /proc      proc defaults      00
 none       /sys       sysfs defaults      00

  procファイルシステムのマウント   
 # mkdir fs-centos/proc
 # mount -t proc none fs-centos/proc
yumでCoreグループをインストール

 Coreグループインストール用のyum設定ファイルを準備。
# cp /etc/yum.conf yum-ami.conf
# cat /etc/yum.repos.d/CentOS-Base.repo >> yum-ami.conf

 しかし、設定ファイル中の$releaseverが展開されない...
[base]
name=CentOS-$releasever - Base
...

 なので、無理やり置換 & インストール。
# sed -i 's/$releasever/5.4/g' yum-ami.conf
# yum -c yum-ami.conf 
# --installroot=/mnt/fs-centos -y groupinstall Core
ネットワークの設定ファイルを作成

 インスタンス起動時に認識されるeth0に対してDHCPの設定。

# cat fs-centos/etc/sysconfig/network
NETWORKING=yes
# cat fs-centos/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
再びfstab、に追記

 インスタンス起動時に割り当てられる、大容量ディスク!?
 (/dev/sda2)とスワップ領域(/dev/sda3)に関して追記。

# cat fs-centos/etc/fstab
/dev/sda1 /          ext3 defaults        11
none       /dev/pts devpts gid=5,mode=620 0 0
none       /dev/shm tmpfs defaults        00
none       /proc     proc defaults       00
none       /sys      sysfs defaults       00

/dev/sda2 /mnt    ext3 defaults          00
/dev/sda3 swap    swap defaults          00
起動時にキー取得の仕込み(その1)

  fs-centos/etc/rc.localに記述
 -------- ここから --------
 #!/bin/sh
touch /var/lock/subsys/local
PUB_KEY_URI=http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
PUB_KEY_FROM_HTTP=/tmp/openssh_id.pub
PUB_KEY_FROM_EPHEMERAL=/mnt/openssh_id.pub
ROOT_AUTHORIZED_KEYS=/root/.ssh/authorized_keys

if [ ! -d /root/.ssh ] ; then
     mkdir -p /root/.ssh
     chmod 700 /root/.ssh
fi
起動時にキー取得の仕込み(その2)

curl --retry 3 --retry-delay 0 --silent --fail -o $PUB_KEY_FROM_HTTP $PUB_KEY_URI
if [ $? -eq 0 -a -e $PUB_KEY_FROM_HTTP ] ; then
    if ! grep -q -f $PUB_KEY_FROM_HTTP $ROOT_AUTHORIZED_KEYS
    then
        cat $PUB_KEY_FROM_HTTP >> $ROOT_AUTHORIZED_KEYS
        echo "New key added to authrozied keys file from parameters"|logger -t "ec2"
    fi
    chmod 600 $ROOT_AUTHORIZED_KEYS
    rm -f $PUB_KEY_FROM_HTTP
elif [ -e $PUB_KEY_FROM_EPHEMERAL ] ; then
    if ! grep -q -f $PUB_KEY_FROM_EPHEMERAL $ROOT_AUTHORIZED_KEYS
    then
        cat $PUB_KEY_FROM_EPHEMERAL >> $ROOT_AUTHORIZED_KEYS
        echo "New key added to authrozied keys file from ephemeral store"|logger -t "ec2"
    fi
    chmod 600 $ROOT_AUTHORIZED_KEYS
    chmod 600 $PUB_KEY_FROM_EPHEMERAL
fi
起動時にキー取得の仕込み(その3)

if [ -e /mnt/openssh_id.pub ] ; then
    if ! grep -q -f /mnt/openssh_id.pub /root/.ssh/authorized_keys
    then
        cat /mnt/openssh_id.pub >> /root/.ssh/authorized_keys
        echo "New key added to authrozied keys file from ephemeral store"|logger -t "ec2"
    fi
    chmod 600 /root/.ssh/authorized_keys
fi
 -------- ここまで --------

  上記処理をすることで、sshにて、事前に登録したキーを使った
  rootでのログインが可能になります。

  curlを利用しているので、別途インストール(yum)の必要あり。
      Coreグループには含まれていない
Amazon EC2 AMI Tools のインストール

 その前に依存しているrsyncとrubyをインストール

 # yum install rsync
 # yum install ruby
  RPMの取得 & インストール
  # curl -OL http://s3.amazonaws.com/ec2-downloads/ec2-
  ami-tools.noarch.rpm
  # rpm -Uvh ec2-ami-tools.noarch.rpm
登録用(S3アップロード用)イメージの作成

 まず、fs-centosをアンマウント。
# umount fs-centos

 作成したイメージファイル(centos.img)を指定してアップロード用
 のファイルセットを作成。
# ec2-bundle-image -i centos.img 
# -k pk-XXXXXXXX.pem 
# -c cert-XXXXXXX.pem 
# -u 000000000000

 -k : 鍵ファイル(Access Identifiers ページ!?から取得可能)
 -c : 証明書ファイル(Access Identifiers ページ!?から取得可能)
 -u : Account Number (ハイフンをとったもの)
登録用イメージをS3にアップロード

 ec2-bundle-imageで以下のファイルの作成を確認。
centos.img.manifest.xml
centos.img.part.00
...

 S3のBucket(-b)とmanifest.xml(-m)を指定してアップロード。
# ec2-upload-bundle -b ami.suz-lab.com 
# -m centos.img.manifest.xml 
# -a XXXXXXXX 
# -s XXXXXXXXXXXXXXXX

 -a : アクセスキー(文字列) (Access Identifiers ページに)
 -s : シークレットキー(文字列) (Access Identifiers ページに)
AMIとして登録

 いろいろ方法があります。
   コマンドライン(EC2 API Tools)
   AWS Management Console
   Elasticfox (Firefoxのアドオン)
      "Images"タブにて、"Machine Images"の領域で右クリッ
      クし、「Register a new AMI」を選択することで登録できま
      す。

 選択時には、下記のようにBucket名からのXMLファイルを指定
 することになります。
 ami.suz-lab.com/centos.img.manifest.xml

Weitere ähnliche Inhalte

Andere mochten auch

Avoid Fraud -- and Secure the Life You Want
Avoid Fraud -- and Secure the Life You Want Avoid Fraud -- and Secure the Life You Want
Avoid Fraud -- and Secure the Life You Want Brian Weatherdon
 
Life Horizons -- Money Can Serve the Life You Want
Life Horizons -- Money Can Serve the Life You WantLife Horizons -- Money Can Serve the Life You Want
Life Horizons -- Money Can Serve the Life You WantBrian Weatherdon
 
Retirement lifestyles -- Money Can Serve the Life You Want
Retirement lifestyles -- Money Can Serve the Life You WantRetirement lifestyles -- Money Can Serve the Life You Want
Retirement lifestyles -- Money Can Serve the Life You WantBrian Weatherdon
 
Pension platforms for Life Income -- Feb2012
Pension platforms for Life Income -- Feb2012Pension platforms for Life Income -- Feb2012
Pension platforms for Life Income -- Feb2012Brian Weatherdon
 
A lifetime of wealth - and how not to lose it
A lifetime of wealth  - and how not to lose itA lifetime of wealth  - and how not to lose it
A lifetime of wealth - and how not to lose itBrian Weatherdon
 
雲(AWS)に願いを!
雲(AWS)に願いを!雲(AWS)に願いを!
雲(AWS)に願いを!Hiroyasu Suzuki
 
Browser Uploads to S3 using HTML POST Forms
Browser Uploads to S3 using HTML POST FormsBrowser Uploads to S3 using HTML POST Forms
Browser Uploads to S3 using HTML POST FormsHiroyasu Suzuki
 
Routine and time expressions -exercises
Routine and time expressions -exercisesRoutine and time expressions -exercises
Routine and time expressions -exercisesHenrique Semeghini
 
CDP キャンペーンサイト編 UPDATE
CDP キャンペーンサイト編 UPDATECDP キャンペーンサイト編 UPDATE
CDP キャンペーンサイト編 UPDATEHiroyasu Suzuki
 
Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...
Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...
Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...Paul G. Huppertz
 
Servicialisation - From Service Identifying to Service Billing V01.02.00
Servicialisation - From Service Identifying to Service Billing V01.02.00Servicialisation - From Service Identifying to Service Billing V01.02.00
Servicialisation - From Service Identifying to Service Billing V01.02.00Paul G. Huppertz
 
AWS+が提供する運用・保守サービス
AWS+が提供する運用・保守サービスAWS+が提供する運用・保守サービス
AWS+が提供する運用・保守サービスHiroyasu Suzuki
 
Servicialisation - Service Specifying: Example E-mailing Service V01.05.00
Servicialisation - Service Specifying: Example E-mailing Service V01.05.00Servicialisation - Service Specifying: Example E-mailing Service V01.05.00
Servicialisation - Service Specifying: Example E-mailing Service V01.05.00Paul G. Huppertz
 
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00Paul G. Huppertz
 

Andere mochten auch (16)

Avoid Fraud -- and Secure the Life You Want
Avoid Fraud -- and Secure the Life You Want Avoid Fraud -- and Secure the Life You Want
Avoid Fraud -- and Secure the Life You Want
 
Life Horizons -- Money Can Serve the Life You Want
Life Horizons -- Money Can Serve the Life You WantLife Horizons -- Money Can Serve the Life You Want
Life Horizons -- Money Can Serve the Life You Want
 
Retirement lifestyles -- Money Can Serve the Life You Want
Retirement lifestyles -- Money Can Serve the Life You WantRetirement lifestyles -- Money Can Serve the Life You Want
Retirement lifestyles -- Money Can Serve the Life You Want
 
Pension platforms for Life Income -- Feb2012
Pension platforms for Life Income -- Feb2012Pension platforms for Life Income -- Feb2012
Pension platforms for Life Income -- Feb2012
 
A lifetime of wealth - and how not to lose it
A lifetime of wealth  - and how not to lose itA lifetime of wealth  - and how not to lose it
A lifetime of wealth - and how not to lose it
 
雲(AWS)に願いを!
雲(AWS)に願いを!雲(AWS)に願いを!
雲(AWS)に願いを!
 
Vyatta AWS
Vyatta AWSVyatta AWS
Vyatta AWS
 
Browser Uploads to S3 using HTML POST Forms
Browser Uploads to S3 using HTML POST FormsBrowser Uploads to S3 using HTML POST Forms
Browser Uploads to S3 using HTML POST Forms
 
Routine and time expressions -exercises
Routine and time expressions -exercisesRoutine and time expressions -exercises
Routine and time expressions -exercises
 
CDP キャンペーンサイト編 UPDATE
CDP キャンペーンサイト編 UPDATECDP キャンペーンサイト編 UPDATE
CDP キャンペーンサイト編 UPDATE
 
Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...
Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...
Lecture 'Service Offering - From Service Specifying to Service Cataloguing' V...
 
Servicialisation - From Service Identifying to Service Billing V01.02.00
Servicialisation - From Service Identifying to Service Billing V01.02.00Servicialisation - From Service Identifying to Service Billing V01.02.00
Servicialisation - From Service Identifying to Service Billing V01.02.00
 
AWS+が提供する運用・保守サービス
AWS+が提供する運用・保守サービスAWS+が提供する運用・保守サービス
AWS+が提供する運用・保守サービス
 
Servicialisation - Service Specifying: Example E-mailing Service V01.05.00
Servicialisation - Service Specifying: Example E-mailing Service V01.05.00Servicialisation - Service Specifying: Example E-mailing Service V01.05.00
Servicialisation - Service Specifying: Example E-mailing Service V01.05.00
 
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
 
Routine part 1a
Routine part 1aRoutine part 1a
Routine part 1a
 

Ähnlich wie オリジナルAMIの作成(CentOS)

Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)Pedro Valera
 
Selinux twnic 201008-sa
Selinux twnic 201008-saSelinux twnic 201008-sa
Selinux twnic 201008-saCYJ
 
Symfony2 en pièces détachées
Symfony2 en pièces détachéesSymfony2 en pièces détachées
Symfony2 en pièces détachéesHugo Hamon
 
我的Kissy学习笔记
我的Kissy学习笔记我的Kissy学习笔记
我的Kissy学习笔记satans17
 

Ähnlich wie オリジナルAMIの作成(CentOS) (6)

Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
 
Unix training
Unix trainingUnix training
Unix training
 
FISL11 2010 - Automação de Datacenters
FISL11 2010 - Automação de DatacentersFISL11 2010 - Automação de Datacenters
FISL11 2010 - Automação de Datacenters
 
Selinux twnic 201008-sa
Selinux twnic 201008-saSelinux twnic 201008-sa
Selinux twnic 201008-sa
 
Symfony2 en pièces détachées
Symfony2 en pièces détachéesSymfony2 en pièces détachées
Symfony2 en pièces détachées
 
我的Kissy学习笔记
我的Kissy学习笔记我的Kissy学习笔记
我的Kissy学习笔记
 

Mehr von Hiroyasu Suzuki

VYATTA USERS MEETING Spring 2014
VYATTA USERS MEETING Spring 2014VYATTA USERS MEETING Spring 2014
VYATTA USERS MEETING Spring 2014Hiroyasu Suzuki
 
実践!AWSクラウドデザインパターン
実践!AWSクラウドデザインパターン実践!AWSクラウドデザインパターン
実践!AWSクラウドデザインパターンHiroyasu Suzuki
 
CDP(キャンペーンサイト編)
CDP(キャンペーンサイト編)CDP(キャンペーンサイト編)
CDP(キャンペーンサイト編)Hiroyasu Suzuki
 
Amazon Web Services(AWS)とcloudpack について
Amazon Web Services(AWS)とcloudpack についてAmazon Web Services(AWS)とcloudpack について
Amazon Web Services(AWS)とcloudpack についてHiroyasu Suzuki
 
AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析Hiroyasu Suzuki
 
RDS(MySQL)の利用と注意点
RDS(MySQL)の利用と注意点RDS(MySQL)の利用と注意点
RDS(MySQL)の利用と注意点Hiroyasu Suzuki
 
cloudpack(AWS運用事業)一周年でわかってきたこと
cloudpack(AWS運用事業)一周年でわかってきたことcloudpack(AWS運用事業)一周年でわかってきたこと
cloudpack(AWS運用事業)一周年でわかってきたことHiroyasu Suzuki
 
AWSでスケールアウト&スケールアップ
AWSでスケールアウト&スケールアップAWSでスケールアウト&スケールアップ
AWSでスケールアウト&スケールアップHiroyasu Suzuki
 
AWSのcloudpack流フルマネージメント
AWSのcloudpack流フルマネージメントAWSのcloudpack流フルマネージメント
AWSのcloudpack流フルマネージメントHiroyasu Suzuki
 
AWS+でスケールアウト&スケールアップ
AWS+でスケールアウト&スケールアップAWS+でスケールアウト&スケールアップ
AWS+でスケールアウト&スケールアップHiroyasu Suzuki
 

Mehr von Hiroyasu Suzuki (13)

VYATTA USERS MEETING Spring 2014
VYATTA USERS MEETING Spring 2014VYATTA USERS MEETING Spring 2014
VYATTA USERS MEETING Spring 2014
 
実践!AWSクラウドデザインパターン
実践!AWSクラウドデザインパターン実践!AWSクラウドデザインパターン
実践!AWSクラウドデザインパターン
 
cdp-night-01
cdp-night-01cdp-night-01
cdp-night-01
 
CDP in NAGOYA
CDP in NAGOYACDP in NAGOYA
CDP in NAGOYA
 
AWS & cloudpack & CDP
AWS & cloudpack & CDPAWS & cloudpack & CDP
AWS & cloudpack & CDP
 
CDP(キャンペーンサイト編)
CDP(キャンペーンサイト編)CDP(キャンペーンサイト編)
CDP(キャンペーンサイト編)
 
Amazon Web Services(AWS)とcloudpack について
Amazon Web Services(AWS)とcloudpack についてAmazon Web Services(AWS)とcloudpack について
Amazon Web Services(AWS)とcloudpack について
 
AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析
 
RDS(MySQL)の利用と注意点
RDS(MySQL)の利用と注意点RDS(MySQL)の利用と注意点
RDS(MySQL)の利用と注意点
 
cloudpack(AWS運用事業)一周年でわかってきたこと
cloudpack(AWS運用事業)一周年でわかってきたことcloudpack(AWS運用事業)一周年でわかってきたこと
cloudpack(AWS運用事業)一周年でわかってきたこと
 
AWSでスケールアウト&スケールアップ
AWSでスケールアウト&スケールアップAWSでスケールアウト&スケールアップ
AWSでスケールアウト&スケールアップ
 
AWSのcloudpack流フルマネージメント
AWSのcloudpack流フルマネージメントAWSのcloudpack流フルマネージメント
AWSのcloudpack流フルマネージメント
 
AWS+でスケールアウト&スケールアップ
AWS+でスケールアウト&スケールアップAWS+でスケールアウト&スケールアップ
AWS+でスケールアウト&スケールアップ
 

オリジナルAMIの作成(CentOS)