カメニッキ

カメとインコと釣りの人です

Cobbler使ってみた

Cobbler

Cobblerとは

PXEを簡単にするためのもの。 ネットワークブートでインストールする場合、dhcpd / pxe / tftpd / vsftpdなど配布に必要なサーバを個別に設定する必要があった。 それをCobblerというユーティリティパッケージが簡略化してくれる。

Cobbler Quickstart Guide を元にすすめる。

手順

SELinuxを無効

特にSELinuxのポリシー変更に慣れていない場合、最初から無効にしているほうが良い。

# 確認
[vagrant@cobtes ~]$ sudo getenforce
Enforcing
# 有効(Enforcing)なので無効化
[vagrant@cobtes ~]$ sudo setenforce 0
[vagrant@cobtes ~]$ sudo vi /etc/selinux/config
# 以下のように変更
SELINUX=disabled

iptableを無効

[vagrant@cobtes ~]$ sudo service iptables stop
[vagrant@cobtes ~]$ sudo chkconfig iptables off

EPELインストール

EPEL リポジトリとは、CentOS 標準のリポジトリでは提供されていないパッケージを、yum コマンドでインストールすることを可能にするリポジトリのこと

[vagrant@test1 ~]$ sudo yum install epel-release

Cobblerインストール(dhcpはCobblerのパッケージに含まれていなかったので一緒に)

[vagrant@test1 ~]$ sudo yum install cobbler dhcp

Cobbler設定

サービス起動前に設定していきます。YAMLで書かれたファイルが/etc/cobbler/settingsにあります。

[vagrant@cobtes ~]$ sudo vi /etc/cobbler/settings
  • 配信先rootパスワード変更

    生成された値を「default_password_crypted」に設定する

 # 任意のパスフレーズで作成
    [vagrant@cobtes ~]$ openssl passwd -1
    Password:
    Verifying - Password:
    $1$byEXZ6J1$Tab3VoUQyRDK.rb/uX3Du0
  • 配信元IPの設定

    サーバの固定IPを指定する

 next_server: 192.168.11.2
    server: 192.168.11.2
    manage_dhcp: 1
  • dhcp.templateの設定
 [vagrant@cobtes ~]$ sudo vi /etc/cobbler/dhcp.template
    [vagrant@cobtes ~]$ diff /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.org
    21,23c21,23
    < subnet 192.168.11.0 netmask 255.255.255.0 {
    <      option routers             192.168.11.2;
    <      option domain-name-servers 192.168.11.2;
    ---
    > subnet 192.168.1.0 netmask 255.255.255.0 {
    >      option routers             192.168.1.5;
    >      option domain-name-servers 192.168.1.1;
    25c25
    <      range dynamic-bootp        192.168.11.100 192.168.11.254;
    ---
    >      range dynamic-bootp        192.168.1.100 192.168.1.254;
  • xinetd配下のrsyncとtftpのdisabledをnoに
 [vagrant@cobtes ~]$ sudo vi /etc/xinetd.d/rsync
    [vagrant@cobtes ~]$ sudo vi /etc/xinetd.d/tftp
 # cobblerd
    [vagrant@cobtes ~]$ sudo service cobblerd start
    [vagrant@cobtes ~]$ sudo chkconfig cobblerd on
    
    # httpd
    [vagrant@cobtes ~]$ sudo service httpd start    [vagrant@cobtes ~]$ sudo chkconfig httpd on
    
    # xinetd
    [vagrant@cobtes ~]$ sudo service xinetd start
    [vagrant@cobtes ~]$ sudo chkconfig xinetd on
  • ここまでで一旦cobblerの状態チェック(cobbler checkコマンドで、他にやることが表示できる)
 [vagrant@cobbler-test ~]$ sudo cobbler check
    The following are potential configuration items that you may want to fix:

    1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
        https://github.com/cobbler/cobbler/wiki/Selinux
        
            ★SELinuxが有効になってる。無効化したつもりが、もう一度実施して消えた
    2 : service dhcpd is not running
    3 : 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.
    4 : debmirror package is not installed, it will be required to manage debian deployments and repositories
    5 : ksvalidator was not found, install pykickstart
    6 : 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.
  • 「2 : service dhcpd is not running」の対応

    少しはまった。 今回使用したVMはeth0:NATとeth1:内部ネットワークがあり、定義したサブネットがどのNICに対してなのか判別できず問題になっていた。 今回はeth1を使用したいので、以下のように。ちなみに、NICごとにサブネットの定義を行ってもOK

 $ sudo vi /etc/sysconfig/dhcpd
    「DHCPDARGS=eth1」を追記
  • 「3 : some network boot-loaders」の対応
 [vagrant@cobbler-test ~]$ sudo cobbler get-loaders
  • 「 4 : debmirror package is not installed, it will be required to manage debian deployments and repositories」
 [vagrant@cobbler-test ~]$ sudo yum install debmirror
  • 「 5 : ksvalidator was not found, install pykickstart」
 [vagrant@cobbler-test ~]$ sudo yum install pykickstart
  • 「 6 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them」

    オプションの電源管理を使うときは必要らしいが、今回は特に使わない

  • 配信用のメディアをインポート

 [vagrant@cobbler-test ~]$ sudo mkdir /mnt/centos
    [vagrant@cobbler-test ~]$ sudo mount -t iso9660 -o loop /vagrant/CentOS-7-x86_64-Minimal-1503-01.iso /mnt/centos/
    [vagrant@cobbler-test ~]$ sudo cobbler import --name=CentOS6.6 --path /mnt/centos/
    task started: 2015-05-25_040350_import
    task started (id=Media import, time=Mon May 25 04:03:50 2015)
    Found a candidate signature: breed=redhat, version=rhel6
    Found a candidate signature: breed=redhat, version=rhel7
    Found a matching signature: breed=redhat, version=rhel7
    Adding distros from path /var/www/cobbler/ks_mirror/CentOS6.6:
    creating new distro: CentOS6.6-x86_64
    trying symlink: /var/www/cobbler/ks_mirror/CentOS6.6 -> /var/www/cobbler/links/CentOS6.6-x86_64
    creating new profile: CentOS6.6-x86_64
    associating repos
    checking for rsync repo(s)
    checking for rhn repo(s)
    checking for yum repo(s)
    starting descent into /var/www/cobbler/ks_mirror/CentOS6.6 for CentOS6.6-x86_64
    processing repo at : /var/www/cobbler/ks_mirror/CentOS6.6
    need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS6.6
    looking for /var/www/cobbler/ks_mirror/CentOS6.6/repodata/*comps*.xml
    Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS6.6/repodata
    *** TASK COMPLETE ***
  • 再度チェック&設定反映
 [vagrant@cobbler-test ~]$ sudo cobbler check
    [vagrant@cobbler-test ~]$ sudo cobbler sync

感想

手でPXEのあれこれやるより、ずいぶん楽だと思った。 また、はじめてKickstartを使用した(Cobblerが用意してくれたデフォルトだが)ところ、何も手を動かさなくて最後まで行ってくれて感動した。

前回PXEではFTPサーバを立てて、OSのパッケージを配置し、そこからインストールさせたがものすごく遅かった。

今回はどうやら「/var/www/cobbler/ks_mirror/CentOS6.6/」にCobblerがmirrorを作っていて、そこから持っていってるみたいだが、ものすごい速さで完了して、一体何が違うのか見てみようと思う。

追記

dhcpdnsに「dnsmasq」を使う

  • dnsmasqセットアップ
 # isc dhcpdは念のためとめておく
    [vagrant@cobbler-test ~]$ sudo service dhcpd stop
    # dnsmasq install
    [vagrant@cobbler-test ~]$ sudo yum install dnsmasq
    # cobbler/modules.conf修正
    [vagrant@cobbler-test ~]$ sudo vi /etc/cobbler/modulse.conf
        [dns]
        module = manage_dnsmasq
        
        [dhcp]
        module = manage_dnsmasq
    [vagrant@cobbler-test ~]$ sudo vi /etc/cobbler/dnsmasq.template
    [vagrant@cobbler-test cobbler]$ diff /etc/cobbler/{dnsmasq.template.org,dnsmasq.template}
    11c11,15
    < dhcp-range=192.168.1.5,192.168.1.200
    ---
    > dhcp-range=192.168.11.100,192.168.11.200
    > # This option if you want to apply the restriction by Mac address, to enable
    > # dhcp-ignore=tag:!known
    > dhcp-option=option:router,192.168.11.2
    > dhcp-option=option:dns-server,192.168.11.2,8.8.8.8
  • クライアントの定義追加(dhcp-ignore=tag:!known)を指定しなければ不要
 ★指定されたMACアドレスに対し、どのprofileでインストールするか定義できる。指定可能なprofileは「sudo cobbler profile list」で確認した
  • DNS動作確認用にdnsmasqで使用する名前解決のリスト追加
 [vagrant@cobbler-test cobbler]$ sudo vi /etc/hosts
    # cobbelrhostで自マシンIPを返すエントリ
    cobblerhost 192.168.11.2
  • 起動
 [vagrant@cobbler-test ~]$ sudo service dnsmasq start
    [vagrant@cobbler-test ~]$ sudo cobbler sync
  • ↑だけではだめで、/etc/cobbler/settingをいじった場合、cobblerdサービスリスタートが必要だった。

    設定が反映されずつまった

 [vagrant@cobbler-test cobbler]$ sudo service cobblerd restart

eth0のMacアドレスが08:00:27:74:0B:10のゲストに、CentOS6.6が自動でインストールされた&dnsmasqをつかって名前解決された