RHEL 7 RCでKickstartを試した

kickstartです。

ネットワーク設定などがうまくいかなかったが、とりあえずOS導入までは出来たので。


こんな感じにESXi上に構築します。

  • 10.1.255.254/16 & 192.168.1.2/23 ... vyattaの内向きと外向きのIP(外向きのIPはeth0とする)
  • 10.1.255.253/16 ... PXEブート用サーバ(DHCP, TFTP, NFS)
  • 10.1.x.x ... kickstartでインストールするマシン

vyattaの導入

過去にちょろっとやってます。
vyattaを触ってみた - 日々量産

今回はVC6.6R1(64bit)を使います。

やる事は同じで、実NW(vSwitch上だけど)と仮想NWを繋ぐための、NATとなるルータを構築するだけです。
NICは2枚設定しておきます。

  • デフォルトのID/Passwordはvyatta/vyatta

vyattaをディスクへインストール。

install image

Welcome to the Vyatta install program. This script
will walk you through the process of installing the
Vyatta image to a local hard drive.
Would you like to continue? (Yes/No) [Yes]: [Enter]
Probing drives: OK
Looking for pre-existing RAID groups...none found.
The Vyatta image will require a minimum 1000MB root.
Would you like me to try to partition a drive automatically
or would you rather partition it manually with parted? If
you have already setup your partitions, you may skip this step

Partition (Auto/Parted/Skip) [Auto]: [Enter]

I found the following drives on your system:
sda 10737MB


Install the image on? [sda]:[Enter]

This will destroy all data on /dev/sda.
Continue? (Yes/No) [No]: Yes

How big of a root partition should I create? (1000MB - 10737MB) [10737]MB: [Enter]

Creating filesystem on /dev/sda1: OK
Mounting /dev/sda1...
What would you like to name this image? [VC6.6R1]:[Enter]
OK. This image will be named: VC6.6R1
Copying squashfs image...
Copying kernel and initrd images...
Done!
I found the following configuration files:
/config/config.boot
/opt/vyatta/etc/config.boot.default
Which one should I copy to sda? [/config/config.boot]:[Enter]

Copying /config/config.boot to sda.
Enter password for administrator account
Enter password for user 'vyatta':任意のパスワード
Retype password for user 'vyatta':任意のパスワード
I need to install the GRUB boot loader.
I found the following drives on your system:
sda 10737MB


Which drive should GRUB modify the boot partition on? [sda]:[Enter]

Setting up grub: OK
Done!

installが終わったら一度再起動

SSHで繋げるための最低限の設定

configure
set service ssh
set interfaces ethernet eth0 address 192.168.1.2/23
set system gateway-address 192.168.1.xxx
set system name-server 192.168.1.xxx
commit
save
exit


SSHに繋いで適当に設定しておく。

configure
# 内向きNWのデフォルトゲートウェイ
set interfaces ethernet eth1 address 10.1.255.254/16

# 内向きNWの名前解決
set service dns forwarding listen-on eth1
set service dns forwarding name-server 192.168.1.xxx

# NAT(eth1 -> eth0)
set nat source rule 1 outbound-interface eth0
set nat source rule 1 source address  10.1.0.0/16
set nat source rule 1 translation address masquerade

# NAT(eth0 -> eth1) 操作用端末からアクセスできたほうが都合がいいので。
set service dns forwarding listen-on eth0
set nat source rule 2 outbound-interface eth1
set nat source rule 2 source address  192.168.0.0/16
set nat source rule 2 translation address masquerade


# NTP設定。外に出れるなら。
set system ntp server ntp.nict.jp

commit
save
exit

# 1回同期しておく。外に出れるなら。
set date ntp ntp.nict.jp

PXE用のサーバの構築

PXEブート用サーバとして、以下を構築する必要があります。

  • DHCP
  • TFTP
  • NFS(Optional. HTTPとかでもよい。)
OS導入

せっかくなのでRHEL 7 RCを使います。

また、縛りとして外からyumを使えない制限を考慮して作業します。

なので、ローカルリポジトリがもてると便利なので、DVD版イメージを使いMinimalインストールします。

http://ftp.riken.jp/Linux/redhat/ftp.redhat.com/rhel/rc/7/Server/x86_64/iso/rhel-server-7.0-x86_64-dvd.iso

以降はrootかAdministratorなユーザで以下のコマンドを実行します。

SSHで作業したいのでまず最低限なNW設定(NICのデバイス名はens32)

sudo nmcli con mod ens32 ipv4.addresses "10.1.255.253/16 10.1.255.254"
sudo nmcli con mod ens32 ipv4.dns "10.1.255.254"
sudo nmcli con mod ens32 ipv4.method "manual"
sudo nmcli con mod ens32 connection.autoconnect "yes"
sudo nmcli dev disconnect ens32
sudo nmcli dev connect ens32

バイス名はip addrで確認します。

イメージコピー

イメージをマウントします。
仮想ドライブからCDがEjectされてる状態の可能性もあるので、注意してください。

sudo mount -r /dev/cdrom /mnt
ls -l /mnt

DVDイメージの中身をディレクトリに移します。ディレクトリ名は適当でも良いですが、こんな感じにしておきます。

移し終えたらイメージはお役御免。

sudo mkdir -p /opt/rhel/rc/7/Server/x86_64/os
sudo cp -rp /mnt/* /opt/rhel/rc/7/Server/x86_64/os
sudo umount /mnt
yumリポジトリ設定

まず、RHEL7RC版のyum.repos.dが空っぽなので、適当に追加します。
baseurlの$basearchにはx86_64が入ります。上でコピーしたものがちゃんと入った先であれば何でも良いです。

cat << '__EOF__' | sudo tee /etc/yum.repos.d/Local.repo
[local.rhel-7-rc]
name=Red Hat Enterprise Linux 7 RC - $basearch
baseurl=file:///opt/rhel/rc/7/Server/$basearch/os/
enabled=1
priority=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
__EOF__

yum clean all
yum repolist all

yum repolist all で local.rhel-7-rc/x86_64 がいることを確認します。


外部のリポジトリを使いたいならこうしておきます。

cat << '__EOF__' | sudo tee /etc/yum.repos.d/Base.repo
[rhel-rc]
name=Red Hat Enterprise Linux 7 RC - $basearch
baseurl=http://ftp.redhat.com/pub/redhat/rhel/rc/7/Server/$basearch/os/
enabled=1
priority=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-rc-optional]
name=Red Hat Enterprise Linux 7 RC Optional - $basearch
baseurl=http://ftp.redhat.com/pub/redhat/rhel/rc/7/Server-optional/$basearch/os/
priority=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
__EOF__
NFSの導入

Kickstartでセットアップするマシンから先ほどコピーしたファイルに参照できるようにしてあげます。

NFSなら手っ取り早くできそうです。

sudo yum install -y nfs-utils

公開設定(対象ディレクトリ配下のみReadOnlyとする)

cat << __EOF__ | sudo tee /etc/exports 
/opt/rhel/rc/7/Server/x86_64 10.1.0.0/16 (ro,all_squash)
__EOF__


所有者変更

sudo chown -R nfsnobody:nfsnobody /opt/rhel/rc/7/Server/x86_64


NFSサービス起動

sudo systemctl enable nfs-lock.service nfs-server.service
sudo systemctl start nfs-lock.service nfs-server.service
systemctl status nfs-lock.service nfs-server.service


Firewall設定

sudo firewall-cmd --add-service=nfs --permanent 
sudo firewall-cmd --add-service=mountd --permanent 
sudo firewall-cmd --add-service=rpc-bind --permanent 
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
DHCP導入

DHCPのインストールとNetworkインストール向けブートローダであるpxelinuxの場所を教える設定をしておきます。

今回は全部このマシンにいれるので、next-serverは自分のプライベートIPにします。
ネットワークアドレスは 10.1.0.0/16 なので、subnetとnetmaskにはいる値は"subnet 10.1.0.0 netmask 255.255.0.0"。
デフォルトゲートウェイは10.1.255.254なので、routersは"10.1.255.254"。

sudo yum install -y dhcp

cat << '__EOF__' | sudo tee /etc/dhcp/dhcpd.conf 
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;

subnet 10.1.0.0 netmask 255.255.0.0 {
  option routers 10.1.255.254;
  range 10.1.255.1 10.1.255.250;

  class "pxeclients" {
    match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
    next-server 10.1.255.253;
    filename "/pxelinux/pxelinux.0";
  }
}
__EOF__


DHCPdサービス有効 & 起動 & 確認

sudo systemctl enable dhcpd.service
sudo systemctl start dhcpd.service
systemctl status dhcpd.service


ブートローダ(pxelinux.0)の配備はtftp-serverでやります。

TFTP-Serverの導入
sudo yum install -y tftp-server

xinetdも一緒に入ります。


設定変更

sudo sed -i 's/\(disable[ \t]*=[ \t]*\)yes/\1no/' /etc/xinetd.d/tftp
sudo grep "disable" /etc/xinetd.d/tftp


ブートローダであるpxelinux.0の準備と配備

sudo yum install -y syslinux
ls -l /usr/share/syslinux/pxelinux.0
sudo mkdir /var/lib/tftpboot/pxelinux
sudo cp -p /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux

pxelinux.cfgの配備。今のところはdefault1つのみにしておきます。

もしシステまちっくな事をやるなら、NICに割り当てたMACアドレスを使ったファイル名にする感じになるでしょう。

リポジトリの情報やkickstartの設定ファイルの場所を示す情報を欠いておきます。

また「マシン起動したらOSのインストールまで終わってた状態」になるべく早くするため、timeoutの値は短めにしておきます。

sudo mkdir /var/lib/tftpboot/pxelinux/pxelinux.cfg
cat << '__EOF__' | sudo tee /var/lib/tftpboot/pxelinux/pxelinux.cfg/default
default rhel7rc
prompt 1
timeout 30

display boot.msg

label rhel7rc
  menu label ^Install RHEL 7 RC system
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.repo=nfs:10.1.255.253:/opt/rhel/rc/7/Server/x86_64/os/ inst.ks=nfs:10.1.255.253:/opt/rhel/rc/7/Server/x86_64/kickstart/ks.cfg
__EOF__

pxeboot用イメージを配備

cd /var/lib/tftpboot/pxelinux
sudo cp -p /opt/rhel/rc/7/Server/x86_64/os/images/pxeboot/initrd.img /opt/rhel/rc/7/Server/x86_64/os/images/pxeboot/vmlinuz ./


tftp-server サービス有効 & 起動 & 確認(このtftp.socketも必要だった。なんでや!)

sudo systemctl enable xinetd.service tftp.socket tftp.service
sudo systemctl start xinetd.service tftp.socket tftp.service 
sudo systemctl status xinetd.service tftp.socket tftp.service 


tftp-server向けにfirewall設定

sudo firewall-cmd --add-service=tftp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

publicのservicesにtftpが混ざってて、同一NW(vyattaとか)からcurl tftp://[IP]/pxelinux/pxelinux.0 とかやって参照できればOKです。

KickStartファイルの準備

パスワードを作ります。

# MD5
openssl passwd -1

# sha256 (salt:16文字)
python -c 'import getpass,random,string,crypt; from string import ascii_letters,digits; pw = getpass.getpass(); print crypt.crypt(pw, "$5$"+"".join([random.choice(ascii_letters + digits) for i in range(16)]))'


今回はrootとユーザとしてryozi(wheel所属)を作ります。また、パスワードは上記のワンライナーで作ったSHA-256を使っています。("$5$4gHwfWJMsIHSxI0C$77ZUHITUPfwITixFZGDh9MrkubFaiF1ApvkgQxMK4H4"という箇所。適宜置き換える。)

モジュールは最小構成でcoreのみ入れます。minimalインストールと同等かと思います。(800MB強)

後は言語設定、キーボード設定、タイムゾーン設定とか、ディスクパーティションをOS任せにしたり、ブートローダ入れたりしてます。

sudo -u nfsnobody mkdir /opt/rhel/rc/7/Server/x86_64/kickstart
cat << '__EOF__' | sudo -u nfsnobody tee /opt/rhel/rc/7/Server/x86_64/kickstart/ks.cfg
text
install
nfs --server=10.1.255.253 --dir=/opt/rhel/rc/7/Server/x86_64/os

lang ja_JP.UTF-8
keyboard jp106
timezone Asia/Tokyo
rootpw --iscrypted $5$4gHwfWJMsIHSxI0C$77ZUHITUPfwITixFZGDh9MrkubFaiF1ApvkgQxMK4H4
authconfig --enableshadow --passalgo=-sha256

bootloader --location=mbr --driveorder=sda

selinux --enforcing

clearpart --all
autopart

reboot

user --name=ryozi --groups=wheel --iscrypted --password=$5$4gHwfWJMsIHSxI0C$77ZUHITUPfwITixFZGDh9MrkubFaiF1ApvkgQxMK4H4

%packages --nobase
@core
%end

__EOF__


後は適当にESXiで仮想マシンを作って起動して、PXEブートしてkickstartが良い感じに走るのを観察します。

おしまい

kickstartの設定でnetworkの項目があったけど、RHEL 7ではうまくいかなかった(多分必要なパッケージがないのかも。)

やるとすればscriptでnmcliコマンドを実行する形になるのかなぁ。

関係ないけども、systemctlとかfirewall-cmdを使うのも初めてで、使い方も少し覚えられたのがよかった。(小並感)