Database JUNKY

MySQL,MariaDBを中心としたブログです

cobbler で CENTOS5.7を自動で速攻インストール!!

サーバの台数が増えるたび、OSをいちいち手作業でインストールするのが面倒になってきたため、今回cobblerというものを入れてインストールの作業を楽々にしてみました。

Cobbler(http://www.cafechantant.com/trac/wiki/cobbler_top) 迅速にネットワークインストール環境を構築する為のLinuxのブートサーバです。シンプルな一連のコマンドを使って、PXE、再インストール、XENKVMを使っての仮想化インストールなどのネットワークインストール環境を設定することが出来るサーバです。 巨大なデータセンターの運用、大学の研究所の運用、または単に家庭内ネットワークで手に余るほどのマシンがある、など、これらのどの場合でも、cobblerは迅速なインストールとアップデートの実行の役に立つことが出来ます。

つまり便利なんです!どれくらい便利かというと、サーバの電源入れて、はい、OSのインストールが終わりってくらい便利(笑

cobblerのインストール方法を以下に記載しました。最終目標は、サーバを電源入れてインストールできるところまでです。なので、細かい話にはあまり触れておりません。

・前準備/環境把握

[root@cobblersrv1 ~]# uname -a
Linux cobblersrv1.squad.local 2.6.18-274.3.1.el5 #1 SMP Tue Sep 6 20:13:52 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@cobblersrv1 ~]# cd /usr/local/src/
[root@cobblersrv1 src]# pwd
/usr/local/src
[root@cobblersrv1 src]# wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
* どうもこちらに変わったみたいです
http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

[root@cobblersrv1 src]# rpm -ivh epel-release-5-4.noarch.rpm
[root@cobblersrv1 src]# yum -y install cobbler cobbler-web dhcp

・こんなものがインストールされます

Installed:
cobbler.noarch 0:2.0.11-2.el5                     cobbler-web.noarch 0:2.0.11-2.el5                     dhcp.x86_64 12:3.0.5-29.el5_7.1

Dependency Installed:
Django.noarch 0:1.1.4-1.el5                       PyYAML.x86_64 0:3.08-4.el5                           createrepo.noarch 0:0.4.11-3.el5
httpd.x86_64 0:2.2.3-53.el5.centos.1              libyaml.x86_64 0:0.1.2-3.el5                         mkisofs.x86_64 9:2.01-10.7.el5
mod_python.x86_64 0:3.2.8-3.1                     python-cheetah.x86_64 0:2.0.1-1.el5                  python-devel.x86_64 0:2.4.3-44.el5_7.1
python-netaddr.noarch 0:0.5.2-1.el5               python-simplejson.x86_64 0:2.0.9-8.el5               tftp-server.x86_64 0:0.49-2.el5.centos
xinetd.x86_64 2:2.3.14-13.el5                     yum-utils.noarch 0:1.1.16-16.el5.centos

・2012/5/13 追記 mod_wsgi をインストールする

[root@cobblersrv1 src]#  yum install python26-mod_wsgi

・tftpコンフィグファイルの編集 disable=yes → noに変更する

[root@cobblersrv1 src]# vi /etc/xinetd.d/tftp
---------------------
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
socket_type             = dgram
protocol                = udp
wait                    = yes
user                    = root
server                  = /usr/sbin/in.tftpd
server_args             = -s /tftpboot
disable                 = no
per_source              = 11
cps                     = 100 2
flags                   = IPv4
}
---------------------
[root@cobblersrv1 src]# /sbin/service xinetd restart
xinetd を停止中:                                           [失敗]
xinetd を起動中:                                           [  OK  ]

dhcp設定のバックアップを念のためとっておく

[root@cobblersrv1 src]# cp /etc/dhcpd.conf /etc/dhcpd.conf.default

dhcpの設定をする 環境に併せて変更、基本IPADDRESS部分だけかと思います。

[root@cobblersrv1 src]# cp /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.bak
[root@cobblersrv1 src]# vi /etc/cobbler/dhcp.template
[root@cobblersrv1 src]# diff /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.bak
19,21c19,21
< subnet 192.168.101.0 netmask 255.255.255.0 {
<      option routers             192.168.101.1;
<      option domain-name-servers 192.168.101.1;
---
> subnet 192.168.1.0 netmask 255.255.255.0 {
>      option routers             192.168.1.5;
>      option domain-name-servers 192.168.1.1;
23c23
<      range dynamic-bootp        192.168.101.210 192.168.101.254;
---
>      range dynamic-bootp        192.168.1.100 192.168.1.254;

. pxebootの設定をします、基本下記箇所を削除しただけです。

[root@cobblersrv1 src]# cp /etc/cobbler/pxe/pxedefault.template /etc/cobbler/pxe/pxedefault.template.bak
[root@cobblersrv1 src]# vi /etc/cobbler/pxe/pxedefault.template
[root@cobblersrv1 src]# diff /etc/cobbler/pxe/pxedefault.template /etc/cobbler/pxe/pxedefault.template.bak
7a8,12
> LABEL local
>         MENU LABEL (local)
>         MENU DEFAULT
>         LOCALBOOT 0
>

・cobblerのセッティングを行います。dhcpの設定につきましては、こちらで行います。

[root@cobblersrv1 src]# cp /etc/cobbler/settings /etc/cobbler/settings.bak
[root@cobblersrv1 src]# vi /etc/cobbler/settings
[root@cobblersrv1 src]# diff /etc/cobbler/settings /etc/cobbler/settings.bak
198c198
< manage_dhcp: 1
---
> manage_dhcp: 0
213c213
< next_server: 192.168.101.55
---
> next_server: 127.0.0.1
325c325
< server: 192.168.101.55
---
> server: 127.0.0.1

・/etc/settings での補足 OSインストール時のデフォルトのパスワードはコメントにも書きましたが、cobblerです。このパスワードをはじめから変更したい場合は、以下のような手順で行います

shadow 形式のパスワードのハッシュ値を生成する

[root@cobblersrv1 src]# openssl passwd -1 -salt "cobbler" "mypassword"
$1$cobbler$zBO0ugOBMyDWhTR8MYoa70

上記に入手したパスワードを/etc/settingsの下記部分に置き換える

# vi /etc/settings
------
# cobbler has various sample kickstart templates stored
# in /var/lib/cobbler/kickstarts/.  This controls
# what install (root) password is set up for those
# systems that reference this variable.  The factory
# default is "cobbler" and cobbler check will warn if
# this is not changed.
# default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
default_password_crypted: "$1$cobbler$zBO0ugOBMyDWhTR8MYoa70"
------

・Cobblerの起動をする

[root@cobblersrv1 src]# /etc/init.d/httpd start
httpd を起動中:                                            [  OK  ]
[root@cobblersrv1 src]# /sbin/chkconfig httpd on
[root@cobblersrv1 src]# /etc/init.d/cobblerd start
Starting cobbler daemon:                                   [  OK  ]                            [  OK  ]

[root@cobblersrv1 src]# cobbler sync
task started: 2011-09-27_114459_sync
task started (id=Sync, time=Tue Sep 27 11:44:59 2011)
running pre-sync triggers
cleaning trees
mkdir: /tftpboot/pxelinux.cfg
mkdir: /tftpboot/grub
mkdir: /tftpboot/images
mkdir: /tftpboot/s390x
mkdir: /tftpboot/ppc
mkdir: /tftpboot/etc
removing: /tftpboot/grub/images
copying bootloaders
trying hardlink /usr/lib/syslinux/pxelinux.0 -> /tftpboot/pxelinux.0
trying hardlink /usr/lib/syslinux/menu.c32 -> /tftpboot/menu.c32
trying hardlink /usr/lib/syslinux/memdisk -> /tftpboot/memdisk
copying distros
copying images
generating PXE configuration files
rendering DHCP files
generating /etc/dhcpd.conf
cleaning link caches
generating PXE menu structure
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: /etc/rc.d/init.d/dhcpd restart
received on stdout: dhcpd を起動中: [  OK  ]

received on stderr:
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

[root@cobblersrv1 src]# /etc/init.d/dhcpd start

centosのisoファイルを取得し、任意のディレクトリに保存(例では、/isoに保存しております)

[root@cobblersrv1 src]# ll /iso
合計 4833168
-rwxr-Sr-x 1 root root 4273238016  9月 27 02:57 CentOS-5.7-x86_64-bin-DVD-1of2.iso
-rwxr-Sr-x 1 root root  671086592  9月 27 02:59 CentOS-5.7-x86_64-bin-DVD-2of2.iso

・上記の、CENTOSインストールデータをループバックマウントし

>> マウントポイント作成
[root@cobblersrv1 src]# mkdir /mnt/cdrom

>> DVD一枚目
[root@cobblersrv1 src]# mount -t iso9660 -o loop /iso/CentOS-5.7-x86_64-bin-DVD-1of2.iso /mnt/cdrom
[root@cobblersrv1 src]# mkdir /tmp/centos57
[root@cobblersrv1 src]# shopt -s dotglob
[root@cobblersrv1 src]# cp -rf /mnt/cdrom/* /tmp/centos57/
[root@cobblersrv1 src]# umount /mnt/cdrom

>> DVD2枚目
[root@cobblersrv1 src]# mount -t iso9660 -o loop /iso/CentOS-5.7-x86_64-bin-DVD-2of2.iso /mnt/cdrom
[root@cobblersrv1 src]# cp -rf /mnt/cdrom/* /tmp/centos57/
[root@cobblersrv1 src]# umount /mnt/cdrom

・上記にてコピーしたファイルを、cobblerにインポートする

[root@cobblersrv1 src]# cobbler import --path /tmp/centos57/ --name=centos57

・もう一発同期

[root@cobblersrv1 ~]# cobbler sync
task started: 2011-09-27_144631_sync
task started (id=Sync, time=Tue Sep 27 14:46:31 2011)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos57-xen-x86_64
removing: /var/www/cobbler/images/centos57-x86_64
removing: /tftpboot/pxelinux.cfg/default
removing: /tftpboot/grub/efidefault
removing: /tftpboot/grub/images
removing: /tftpboot/s390x/profile_list
copying bootloaders
copying distros
copying files for distro: centos57-xen-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/xen/vmlinuz -> /tftpboot/images/centos57-xen-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/xen/initrd.img -> /tftpboot/images/centos57-xen-x86_64/initrd.img
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/xen/vmlinuz -> /var/www/cobbler/images/centos57-xen-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/xen/initrd.img -> /var/www/cobbler/images/centos57-xen-x86_64/initrd.img
copying files for distro: centos57-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/pxeboot/vmlinuz -> /tftpboot/images/centos57-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/pxeboot/initrd.img -> /tftpboot/images/centos57-x86_64/initrd.img
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos57-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos57/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos57-x86_64/initrd.img
copying images
generating PXE configuration files
rendering DHCP files
generating /etc/dhcpd.conf
cleaning link caches
generating PXE menu structure
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: /etc/rc.d/init.d/dhcpd restart
received on stdout: dhcpd を停止中: [  OK  ]
dhcpd を起動中: [  OK  ]

received on stderr:
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

・再度レポートを出力する、以下のような出力になっていればOK

[root@cobblersrv1 ~]# cobbler report
distros:
==========
Name                           : centos57-xen-x86_64
Architecture                   : x86_64
Breed                          : redhat
Comment                        : rhel5.7
Initrd                         : /var/www/cobbler/ks_mirror/centos57/images/xen/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos57/images/xen/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos57-xen-x86_64'}
Management Classes             : []
OS Version                     : rhel5
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

Name                           : centos57-x86_64
Architecture                   : x86_64
Breed                          : redhat
Comment                        : rhel5.7
Initrd                         : /var/www/cobbler/ks_mirror/centos57/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos57/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos57-x86_64'}
Management Classes             : []
OS Version                     : rhel5
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

profiles:
==========
Name                           : centos57-xen-x86_64
Comment                        :
DHCP Tag                       : default
Distribution                   : centos57-xen-x86_64
Enable PXE Menu?               : 1
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample.ks
Kickstart Metadata             : {}
Management Classes             : []
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : xenpv

Name                           : centos57-x86_64
Comment                        :
DHCP Tag                       : default
Distribution                   : centos57-x86_64
Enable PXE Menu?               : 1
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample.ks
Kickstart Metadata             : {}
Management Classes             : []
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : qemu

systems:
==========

repos:
==========

images:
==========

・上記までやれば、pxeブートで、cobblerサーバを利用してクライアントは起動と同時に自動的にインストールされるようになります、他にもkickstartを利用することにより、インストールされるマシンに細かい環境設定を行うことができますが、とりあえずここでは割愛します。尚、kickstartのconfigファイルは、/root/anaconda-ks.cfgが参考になりますのでそれを活用してください。

・参考までに、kickstartファイルを、cobblerに登録するコマンドです。

[root@cobblersrv1 ~]# cp /root/anaconda-ks.cfg /etc/cobbler/squad_centos_x86_64.ks
[root@cobblersrv1 ~]# cobbler profile add --name=squad_centos_x86_64 --distro=centos57-x86_64 --kickstart=/etc/cobbler/squad_centos_x86_64.ks
## 上記のプロファイルが登録されたか確認してみます
[root@cobblersrv1 ~]# cobbler report
distros:
==========
Name                           : centos57-xen-x86_64
Architecture                   : x86_64
Breed                          : redhat
Comment                        : rhel5.7
Initrd                         : /var/www/cobbler/ks_mirror/centos57/images/xen/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos57/images/xen/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos57-xen-x86_64'}
Management Classes             : []
OS Version                     : rhel5
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

Name                           : centos57-x86_64
Architecture                   : x86_64
Breed                          : redhat
Comment                        : rhel5.7
Initrd                         : /var/www/cobbler/ks_mirror/centos57/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos57/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos57-x86_64'}
Management Classes             : []
OS Version                     : rhel5
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

profiles:
==========
Name                           : squad_centos_x86_64
Comment                        :
DHCP Tag                       : default
Distribution                   : centos57-x86_64
Enable PXE Menu?               : 1
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /etc/cobbler/squad_centos_x86_64.ks
Kickstart Metadata             : {}
Management Classes             : []
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : xenpv

Name                           : centos57-xen-x86_64
Comment                        :
DHCP Tag                       : default
Distribution                   : centos57-xen-x86_64
Enable PXE Menu?               : 1
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample.ks
Kickstart Metadata             : {}
Management Classes             : []
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : xenpv

Name                           : centos57-x86_64
Comment                        :
DHCP Tag                       : default
Distribution                   : centos57-x86_64
Enable PXE Menu?               : 1
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample.ks
Kickstart Metadata             : {}
Management Classes             : []
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : qemu

systems:
==========

repos:
==========

images:
==========

## ちなみに、profileを削除する方法
## cobbler profile remove --name=squad_centos_x86_64

▼さっそく試してみよう! こちらにはマシンが潤沢にあるわけでないので、VMでインストールできるか試してみました。

・ゲストOSのコンソールを起動し、電源をONにします

pxeブートがかかり、cobblerサーバから、当該ゲストOSにipaddressを割り当て、インストールメニューを表示してきます。ここだけでも感動

・あとは、もう何もしません。自動でOSをインストールしてくれます。CDを入れ替えるとか、ネットワーク設定を行うとかそんなのも自動です

 

いかがでしょうか?サーバ管理者の皆様、これで環境構築の手間を大幅に削減することができますよ!!上記の例ですと、ただ、OSをインストールするだけになってしまいますが、kickstartと組み合わせれば、それこそ、ミドルウェアのインストールや、ldapの設定なんかも自動で行うことができます!!

kickstartの手順、簡単にですが書きました!! http://www.s-quad.com/wordpress/?p=1274