cobblerを使ってみる

今日はcobblerを使ってKickStartを使った自動インストール環境を
作ってみる事にします。

環境

OS : CentOS5.5を使います。

インストール


まず、EPELのリポジトリを使えるようにします。

 # rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm


その後、cobblerをインストールします。

 # yum install cobbler cobbler-web


DHCP, DNSを使う場合は、必要なパッケージをインストールしておきます。

 # yum install dhcp bind caching-nameserver


Apache、cobblerを起動します。今回は自動起動するようにしておくことにします。

# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]
# /etc/init.d/cobblerd start
Starting cobbler daemon:                                   [  OK  ]
# SERVING!

# chkconfig --level 2345 httpd on
# chkconfig --level 2345 cobblerd on

セットアップ


「cobbler check」で指摘された事項を潰していけば良いようです。
手元の環境ではこんな感じでした。

# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : you need to set some SELinux content rules to ensure cobbler serves content correctly in your SELinux environment, run the following: /usr/sbin/semanage fcontext -a -t public_content_t "/tftpboot/.*" && /usr/sbin/semanage fcontext -a -t public_content_t "/var/www/cobbler/images/.*"
4 : you need to set some SELinux rules if you want to use cobbler-web (an optional package), run the following: /usr/sbin/semanage fcontext -a -t httpd_sys_content_rw_t "/var/lib/cobbler/webui_sessions/.*"
5 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
6 : change 'disable' to 'no' in /etc/xinetd.d/tftp
7 : change 'disable' to 'no' in /etc/xinetd.d/rsync
8 : since iptables may be running, ensure 69, 80, and 25151 are unblocked
9 : debmirror package is not installed, it will be required to manage debian deployments and repositories
10 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
11 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.


tftpとrsyncについて、「disable = yes」を「disable = no」として有効にします。

# vi /etc/xinetd.d/tftp
# vi /etc/xinetd.d/rsync 


SELinuxのラベルを修正します。

# semanage fcontext -a -t public_content_t "/tftpboot/.*"
# semanage fcontext -a -t public_content_t "/var/www/cobbler/images/.*"
# semanage fcontext -a -t httpd_sys_content_t "/var/lib/cobbler/webui_sessions/.*"


「cobbler get-loaders」を実行します。

# cobbler get-loaders
task started: 2010-12-19_161240_get_loaders
task started (id=Download Bootloader Content, time=Sun Dec 19 16:12:40 2010)
downloading content required to netboot all arches
downloading http://mdehaan.fedorapeople.org/loaders/README to /var/lib/cobbler/loaders/README
downloading http://mdehaan.fedorapeople.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://mdehaan.fedorapeople.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://mdehaan.fedorapeople.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://mdehaan.fedorapeople.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://mdehaan.fedorapeople.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot
downloading http://mdehaan.fedorapeople.org/loaders/pxelinux.0-3.61 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://mdehaan.fedorapeople.org/loaders/menu.c32-3.61 to /var/lib/cobbler/loaders/menu.c32
*** TASK COMPLETE ***


「/etc/cobbler/settings」を編集します。


「server」「next_server」にcobblerを動かしているホストを指定します。


また、KickStartで構築されるノードの初期パスワード設定を変更します。


opensslコマンドを使いパスワードを生成します。
ここではソルトを「cobbler」パスワードを「password」としています。

# openssl passwd -1 -salt "cobbler" "password"
$1$cobbler$UTIGTKoLfLdeMAPNxROQZ1


表示された値を
「default_password_crypted」の値にします。


「debmirror」「cman」パッケージをインストールします。

# yum install debmirror cman


debmirrorパッケージインストール後、「cobbler check」した所、
以下のメッセージが表示されたので、こちらも対応します。
当該の項目を"#"でコメントアウトします。

comment 'dists' on /etc/debmirror.conf for proper debian support
comment 'arches' on /etc/debmirror.conf for proper debian support


DHCPの設定を行います。
「/etc/cobbler/dhcp.templete」を自分のネットワークに合わせて修正します。

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

subnet 192.168.xxx.0 netmask 255.255.255.0 {
     option routers             192.168.xxx.xxx;
     option domain-name-servers 192.168.xxx.xxx;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.xxx.xxx 192.168.xxx.254;
     filename                   "/pxelinux.0";
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
}


設定の同期を取ります。

# cobbler sync
task started: 2010-12-19_165246_sync
task started (id=Sync, time=Sun Dec 19 16:52:46 2010)
running pre-sync triggers
cleaning trees
removing: /tftpboot/pxelinux.cfg/default
removing: /tftpboot/s390x/profile_list
copying bootloaders
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/menu.c32 -> /tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/yaboot -> /tftpboot/yaboot
copying: /usr/lib/syslinux/memdisk -> /tftpboot/memdisk
copying distros
copying images
generating PXE configuration files
rendering DHCP files
generating /etc/dhcpd.conf
rendering Rsync files
generating PXE menu structure
running post-sync triggers
running: dhcpd -t -q
returned: 0
running: /etc/rc.d/init.d/dhcpd restart
Starting dhcpd:                                            [  OK  ]
returned: 0
*** TASK COMPLETE ***


インストールメディアのデータをインポートします。

# mount /dev/cdrom /mnt
mount: block device /dev/cdrom is write-protected, mounting read-only
# cobbler import --path=/mnt --name=CentOS5


インポート結果を確認します。

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

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


profiles:
==========
Name                           : CentOS5-xen-i386
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS5-xen-i386
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                           : CentOS5-i386
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS5-i386
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:
==========


あとは、インストールしようとしているマシンを起動したときに、
以下のような画面が出てくればOKです。KickStart設定ファイルに基づき、
自動でOSがインストールされます。

今後、他の設定も試してみようと思います。
今日はこんな所で。

おまけ:SELinux関係


今回、SELinuxを有効にしていました。
cobblerインストール後、Apacheを起動したところ、
以下のような拒否ログが出て動きませんでした。

type=AVC msg=audit(1292789225.943:167): avc:  denied  { name_connect } for  pid=2684 comm="httpd" dest=25151 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1292789225.943:167): arch=40000003 syscall=102 success=no exit=-13 a0=3 a1=bfc8f5b0 a2=aca1c8 a3=8f8d650 items=0 ppid=2682 pid=2684 auid=1000 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=2 comm="httpd" exe="/usr/sbin/httpd" subj=user_u:system_r:httpd_t:s0 key=(null)


対処として、「setsebool」コマンドを発行しました。

# getsebool httpd_can_network_connect
httpd_can_network_connect --> off

# setsebool -P httpd_can_network_connect 1

# getsebool httpd_can_network_connect
httpd_can_network_connect --> on


また、クライアントのマシンの電源ON時、
インストールするOSを選択する選択画面から先に進まないという事象がありました。
ログを確認した所、SELinuxが原因でした。


こっちは「audit2allow」で対処しました。

type=AVC msg=audit(1292800690.601:77): avc:  denied  { read } for  pid=2846 comm="in.tftpd" name="vmlinuz" dev=dm-0 ino=1048580 scontext=system_u:system_r:tftpd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
# audit2allow -a -M local
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i local.pp

# cat local.te 

module local 1.0;

require {
	type httpd_sys_content_t;
	type tftpd_t;
	class file read;
}

#============= tftpd_t ==============
allow tftpd_t httpd_sys_content_t:file read;
type=AVC msg=audit(1292800790.846:80): avc:  denied  { getattr } for  pid=2883 comm="in.tftpd" path="/images/CentOS5-i386/vmlinuz" dev=dm-0 ino=1048580 scontext=system_u:system_r:tftpd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
# audit2allow -a -M local2
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i local2.pp

# cat local2.te 

module local2 1.0;

require {
	type httpd_sys_content_t;
	type tftpd_t;
	class file { read getattr };
}

#============= tftpd_t ==============
allow tftpd_t httpd_sys_content_t:file { read getattr };
# semodule -i local2.pp