[実践編] Ubuntu Serverをスケールアウト型サーバーに配備する(後編)

2014年3月13日(木)
古賀 政純

Ubuntu ServerをHTTP経由で自動インストールするための設定

Ubuntu Severをネットワークインストールするためのプロトコルはいくつか存在しますが、今回はHTTP経由でインストールする管理サーバーを構築してみましょう。WebサービスがUbuntu Server標準の/var/wwwディレクトリで提供されているか確認後、管理サーバーでApache Webサービスを起動します。

# grep "/var/www" /etc/apache2/sites-available/default
        DocumentRoot /var/www
        <Directory /var/www/>
# sysv-rc-conf apaceh2 on
# service apache2 start

Ubuntu ServerのisoイメージをApache Webサービスで提供する/var/www/ubuntusvr120403ltsディレクトリに置き、ループバックマウントします。今回はディレクトリ名を「/var/www/ubuntusvr120403lts」にしました。このディレクトリ名は、上記のdefaultファイル内のpreseed/url=で指定した記述と矛盾がないようにします。

# mkdir -p /var/www/ubuntusvr120403lts/iso
# ls -l /var/www/ubuntusvr120403lts/
total 680964
-rw-r--r-- 1 root root 697303040 Aug 28 15:18 ubuntu-12.04.3-server-amd64.iso
# cd /var/www/html/ubuntusvr120403lts/
# mount -o loop,ro ubuntu-12.04.3-server-amd64.iso iso/

isoディレクトリにマウントされたUbuntu Serverのisoイメージの内容をコピーします。

# mkdir /var/www/ubuntusvr120403lts/dvd
# cd /var/www/ubuntusvr120403lts/iso
# find . ! -type l | cpio -pdum ../dvd/

Packages.gzファイルの処理において、Ubuntu12.04.xの自動インストールが停止する問題を回避する設定を行います。

# cd /var/www/ubuntusvr120403lts/dvd/dists/precise/restricted/binary-amd64
# gunzip Packages.gz
# cp /var/www/ubuntusvr120403lts/iso/dists/precise/restricted/binary-amd64/Packages.gz .
# ls
Packages  Packages.gz  Release

preseed.cfgファイルの記述

Ubuntu Serverを自動インストールための設定ファイルpreseed.cfgを用意します。以下にGPTパーティションに対応したpreseed.cfgファイルの例を示します。

# vi /var/www/ubuntusvr120403lts/preseed.cfg
d-i debian-installer/locale string en_US
d-i localechooser/supported-locales en_US.UTF-8, ja_JP.UTF-8
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
d-i preseed/run string http://172.16.12.1/netcfg.sh	←固定IPアドレス設定に必要
d-i netcfg/use_autoconfig boolean false
d-i netcfg/disable_autoconfig boolean true
d-i netcfg/choose_interface select eth0
d-i netcfg/disable_dhcp boolean true
d-i netcfg/get_nameservers string 172.16.12.1
d-i netcfg/get_ipaddress string 172.16.255.254 ←管理対象サーバーのIPアドレス
d-i netcfg/get_netmask string 255.255.0.0←管理対象サーバーのネットマスク
d-i netcfg/get_gateway string 172.16.12.1←デフォルトゲートウェイ
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string ubuntusvr254 ←管理対象サーバーのホスト名
d-i netcfg/get_domain string jpn.linux.hp.com←管理対象サーバーのドメイン名
d-i netcfg/wireless_wep string
d-i keyboard-configuration/layoutcode string us←キーボードを指定(例では英語)
d-i keyboard-configuration/modelcode pc105
d-i mirror/country string manual
d-i mirror/http/hostname string 172.16.12.1 ←管理サーバーのIPアドレス
d-i mirror/http/directory string /ubuntusvr120403lts/dvd/←isoイメージのコピー先
d-i mirror/http/proxy string
d-i mirror/suite precise ←Ubuntu 12.04.xではpreciseを指定
d-i clock-setup/utc boolean false←UTCを使用しない
d-i time/zone string Japan
d-i clock-setup/ntp boolean false
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-auto/disk string /dev/sda ←管理対象マシンの内蔵ディスクのデバイス名
d-i partman-auto/method string regular
d-i partman/confirm boolean true
d-i partman-auto/choose_recipe string ProLiant
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/mount_style select traditional
d-i partman-partitioning/default_label string gpt
d-i partman-auto/expert_recipe string ProLiant :: \
1 1 1 free \
$iflabel{ gpt } \
method{ biosgrub } \
. \
boot-root :: \
300 50 300 ext4 \ ←/bootパーティションを300MB確保
$gptonly{ } \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \ ←/bootパーティションをext4で利用
mountpoint{ /boot } \
. \
500 10000 -1 ext4 \ ←残りのディスク全て/パーティションに割り当て
$gptonly{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \←/パーティションをext4で利用
mountpoint{ / } \
. \
4096 600 4096 linux-swap \ ←スワップ領域を4GB確保
$gptonly{ } \
$primary{ } \
method{ swap } format{ } \
.
d-i base-installer/install-recommends boolean true
d-i base-installer/kernel/image string linux-generic
d-i passwd/root-login boolean true ←rootアカウントでログイン可能にする
d-i passwd/make-user boolean false
d-i passwd/root-password password password←rootアカウントのパスワード設定
d-i passwd/root-password-again password password
d-i passwd/user-password password insecure
d-i passwd/user-password-again password insecure
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i apt-setup/use_mirror boolean true
d-i debian-installer/allow_unauthenticated boolean true
tasksel tasksel/first multiselect none
d-i pkgsel/include string openssh-server build-essential
d-i pkgsel/upgrade select none
d-i pkgsel/update-policy select none
popularity-contest popularity-contest/participate boolean false
d-i pkgsel/updatedb boolean true
d-i grub-installer/grub2_instead_of_grub_legacy boolean true ←GRUB2を指定
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/sda ←ブートデバイスを指定
d-i finish-install/reboot_in_progress note

管理対象サーバーに固定のIPアドレスを設定する場合、以下のnetcfg.shスクリプトを管理サーバーに配置します。上記preseed.cfgファイル内で指定していますので、記述方法を確認してみてください。

# vi /var/www/netcfg.sh
#!/bin/sh
killall.sh; netcfg
  • Ubuntu Serverの自動インストールサーバー構築に使用する「preseed」

    『スケールアウト型OSSクラウド基盤に最適なUbuntu Serverをひも解く』 第6回のサンプルファイルです。
日本ヒューレット・パッカード株式会社 プリセールス統括本部 ソリューションセンター OSS・Linux担当 シニアITスペシャリスト

兵庫県伊丹市出身。1996年頃からオープンソースに携わる。2000年よりUNIXサーバーのSE及びスーパーコンピューターの並列計算プログラミング講師を担当。科学技術計算サーバーのSI経験も持つ。2005年、大手製造業向けLinuxサーバー提案で日本HP社長賞受賞。2006年、米国HPからLinux技術の伝道師に与えられる「OpenSource and Linux Ambassador Hall of Fame」を2年連続受賞。日本HPプリセールスMVPを4度受賞。現在は、Linux、FreeBSD、Hadoop等のOSSを駆使したスケールアウト型サーバー基盤のプリセールスSE、技術検証、技術文書執筆を担当。日本HPのオープンソース・Linuxテクノロジーエバンジェリストとして講演活動も行っている。Red Hat Certified Engineer、Red Hat Certified Virtualization Administrator、Novell Certified Linux Professional、EXIN Cloud Computing Foundation Certificate、HP Accredited Systems Engineer Cloud Architect、Red Hat Certified System Administrator in Red Hat OpenStack、Cloudera Certified Administrator for Apache Hadoop認定技術者。HP公式ブログ執筆者。趣味はレーシングカートとビリヤード

連載バックナンバー

Think ITメルマガ会員登録受付中

Think ITでは、技術情報が詰まったメールマガジン「Think IT Weekly」の配信サービスを提供しています。メルマガ会員登録を済ませれば、メルマガだけでなく、さまざまな限定特典を入手できるようになります。

Think ITメルマガ会員のサービス内容を見る

他にもこの記事が読まれています