pxe自動化インストールシステム
8364 ワード
pxe自動化インストールシステム
pxe自動化インストール、必要なサービスはdhcpサーバー、tftpサーバー、httpサーバーpxe自動化インストール、必要なパッケージグループと関連インストールファイルはsyslinuxと自動化インストールシステムに必要な応答ファイルselinuxである.
実験の説明:今回の実験は1台のCentOS 7をdhcpサーバーとして、tftpサーバーとして、およびhttpサーバーは本ネットセグメント内のホストに自動化インストールCentOSシステムの準備を提供する:
ホスト
システム
IP
CentOS7
CentOS7
192.168.73.120
実験開始:
一、dhcpサービス、tftp-serverサービス、httpdサービス及びsyslinuxパッケージグループのインストール
[root@centos7 ~]# yum install dhcp tftp-server httpd syslinux -y
二、応答ファイルの作成
1.system-config-kickstartを使用してks 6を生成する.cfg [root@centos7 ~]# system-config-kickstart
[root@centos7 ~]# vim ks6.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.73.120/centos/6/os/x86_64"
# Root password
rootpw --iscrypted $1$6oVXZR1R$QOASc6inirmHCZmQ.W9Hg0
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=1024
%packages
@core
%end
2.ks 6をコピーする.cfgはks 7である.cfg、パラメータの一部を変更[root@centos7 ~]# cp ks6.cfg ks7.cfg
[root@centos7 ~]# vim ks7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.73.120/centos/7/os/x86_64" # url 7 url
# Root password
rootpw --iscrypted $1$6oVXZR1R$QOASc6inirmHCZmQ.W9Hg0
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=ens33 --onboot=on # ens33
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=1024
%packages
@core
%end
三、httpdサービスの構成
1.httpディレクトリの作成[root@centos7 ~]# mkdir -pv /var/www/html/{centos/{6,7}/os/x86_64,ksdir}
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/6’
mkdir: created directory ‘/var/www/html/centos/6/os’
mkdir: created directory ‘/var/www/html/centos/6/os/x86_64’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/7/os’
mkdir: created directory ‘/var/www/html/centos/7/os/x86_64’
mkdir: created directory ‘/var/www/html/ksdir’
2.CentOS 6および7のCDファイルを関連するディレクトリに掛けます(作業中は直接CDミラーをディレクトリにコピーできます)[root@centos7 ~]# lsblk | grep sr
sr0 11:0 1 10G 0 rom /mnt
sr1 11:1 1 3.7G 0 rom
[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only
[root@centos7 ~]# lsblk | grep sr
sr0 11:0 1 10G 0 rom /var/www/html/centos/7/os/x86_64
sr1 11:1 1 3.7G 0 rom /var/www/html/centos/6/os/x86_64
3.準備した応答ファイルをディレクトリにコピーする[root@centos7 ~]# cp ks6.cfg /var/www/html/ksdir
[root@centos7 ~]# cp ks7.cfg /var/www/html/ksdir
4.httpdサービスを起動し、起動自動起動に設定する[root@centos7 ~]# systemctl start httpd
[root@centos7 ~]# systemctl enable httpd
四、tftpサーバーの構成
1.tftp作業ディレクトリの下に関連するファイルディレクトリを作成する[root@centos7 ~]# mkdir -pv /var/lib/tftpboot/{kernel{6,7},pxelinux.cfg}
mkdir: created directory ‘/var/lib/tftpboot/kernel6’
mkdir: created directory ‘/var/lib/tftpboot/kernel7’
mkdir: created directory ‘/var/lib/tftpboot/pxelinux.cfg’
2.centos 6およびcentos 7のカーネルおよび仮想ファイルシステムをtftp作業ディレクトリの対応するkernelディレクトリにコピーする[root@centos7 tftpboot]# cd /var/lib/tftpboot/kernel6
[root@centos7 kernel6]# cp /var/www/html/centos/6/os/x86_64/isolinux/vmlinuz .
[root@centos7 kernel6]# cp /var/www/html/centos/6/os/x86_64/isolinux/initrd.img .
[root@centos7 kernel6]# cd /var/lib/tftpboot/kernel7
[root@centos7 kernel7]# cp /var/www/html/centos/7/os/x86_64/isolinux/vmlinuz .
[root@centos7 kernel7]# cp /var/www/html/centos/7/os/x86_64/isolinux/initrd.img .
3.tftp作業ディレクトリへの起動関連ファイルのコピー[root@centos7 kernel7]# cd /var/lib/tftpboot/
[root@centos7 tftpboot]# cp /usr/share/syslinux/menu.c32 .
[root@centos7 tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
4.ディスク上のメニューファイルを/var/lib/tftpboot/pxelinuxにコピーする.cfgディレクトリの下でdefaultと名前を変更し、このファイルを変更します.[root@centos7 tftpboot]# cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@centos7 tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32 # menu.c32
timeout 600
menu title CentOS install
label linux 6
menu label Install CentOS ^6
kernel kernel6/vmlinuz # centos6
append initrd=kernel6/initrd.img ks=http://192.168.73.120/ksdir/ks6.cfg # KS
label linux 7
menu label Install CentOS ^7
kernel kernel7/vmlinuz # centos7
append initrd=kernel7/initrd.img ks=http://192.168.73.120/ksdir/ks7.cfg # KS
label local
menu label Boot from ^local drive
localboot 0xffff
5.次のディレクトリ構造の表示[root@centos7 tftpboot]#tree
.
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
6.tftpサービスを起動し、起動するように設定する[root@centos7 ~]# systemctl start tftp
[root@centos7 ~]# systemctl enable tftp
五、dhcpサービスの構成
1.dhcpdのデフォルトのプロファイルが空であるため、ここではdhcpdのテンプレートプロファイルをコピーして変更する[root@centos7 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
2.dhcpサービスの構成[root@centos7 ~]# vim /etc/dhcp/dhcpd.conf
# option definitions common to all supported networks...
option domain-name "mylinuxops.com"; #
option domain-name-servers 114.114.114.114; # DNS
default-lease-time 6000;
max-lease-time 72000;
... ...
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
#subnet 10.152.187.0 netmask 255.255.255.0 { #
#} #
# This is a very basic subnet declaration.
subnet 192.168.73.0 netmask 255.255.255.224 {
range 192.168.73.1 192.168.73.100; # dhcp
option routers 192.168.73.254; #
filename "pxelinux.0"; #
next-server 192.168.73.120; # tftp
}
3.dhcpサーバーを起動し、起動自動起動に設定する[root@centos7 ~]# systemctl start dhcpd
[root@centos7 ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
最後に書く
以上はpxe自動化インストールの全過程であり、いくつかの詳細に注意する必要がある:1.すべてのサービスの導入が完了し、テストを行う前に、ネットワークに他のDHCPサービスがないことを確認し、干渉を回避します.2.centos 7は自動インストール時に1 G以上のメモリ容量が必要です.3.物理ディスクのサイズとksファイルのディスクのサイズに注意して、インストールに十分なスペースがあることを確認します.
[root@centos7 ~]# yum install dhcp tftp-server httpd syslinux -y
[root@centos7 ~]# system-config-kickstart
[root@centos7 ~]# vim ks6.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.73.120/centos/6/os/x86_64"
# Root password
rootpw --iscrypted $1$6oVXZR1R$QOASc6inirmHCZmQ.W9Hg0
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=1024
%packages
@core
%end
[root@centos7 ~]# cp ks6.cfg ks7.cfg
[root@centos7 ~]# vim ks7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.73.120/centos/7/os/x86_64" # url 7 url
# Root password
rootpw --iscrypted $1$6oVXZR1R$QOASc6inirmHCZmQ.W9Hg0
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=ens33 --onboot=on # ens33
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=1024
%packages
@core
%end
[root@centos7 ~]# mkdir -pv /var/www/html/{centos/{6,7}/os/x86_64,ksdir}
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/6’
mkdir: created directory ‘/var/www/html/centos/6/os’
mkdir: created directory ‘/var/www/html/centos/6/os/x86_64’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/7/os’
mkdir: created directory ‘/var/www/html/centos/7/os/x86_64’
mkdir: created directory ‘/var/www/html/ksdir’
[root@centos7 ~]# lsblk | grep sr
sr0 11:0 1 10G 0 rom /mnt
sr1 11:1 1 3.7G 0 rom
[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only
[root@centos7 ~]# lsblk | grep sr
sr0 11:0 1 10G 0 rom /var/www/html/centos/7/os/x86_64
sr1 11:1 1 3.7G 0 rom /var/www/html/centos/6/os/x86_64
[root@centos7 ~]# cp ks6.cfg /var/www/html/ksdir
[root@centos7 ~]# cp ks7.cfg /var/www/html/ksdir
[root@centos7 ~]# systemctl start httpd
[root@centos7 ~]# systemctl enable httpd
[root@centos7 ~]# mkdir -pv /var/lib/tftpboot/{kernel{6,7},pxelinux.cfg}
mkdir: created directory ‘/var/lib/tftpboot/kernel6’
mkdir: created directory ‘/var/lib/tftpboot/kernel7’
mkdir: created directory ‘/var/lib/tftpboot/pxelinux.cfg’
[root@centos7 tftpboot]# cd /var/lib/tftpboot/kernel6
[root@centos7 kernel6]# cp /var/www/html/centos/6/os/x86_64/isolinux/vmlinuz .
[root@centos7 kernel6]# cp /var/www/html/centos/6/os/x86_64/isolinux/initrd.img .
[root@centos7 kernel6]# cd /var/lib/tftpboot/kernel7
[root@centos7 kernel7]# cp /var/www/html/centos/7/os/x86_64/isolinux/vmlinuz .
[root@centos7 kernel7]# cp /var/www/html/centos/7/os/x86_64/isolinux/initrd.img .
[root@centos7 kernel7]# cd /var/lib/tftpboot/
[root@centos7 tftpboot]# cp /usr/share/syslinux/menu.c32 .
[root@centos7 tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
[root@centos7 tftpboot]# cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@centos7 tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32 # menu.c32
timeout 600
menu title CentOS install
label linux 6
menu label Install CentOS ^6
kernel kernel6/vmlinuz # centos6
append initrd=kernel6/initrd.img ks=http://192.168.73.120/ksdir/ks6.cfg # KS
label linux 7
menu label Install CentOS ^7
kernel kernel7/vmlinuz # centos7
append initrd=kernel7/initrd.img ks=http://192.168.73.120/ksdir/ks7.cfg # KS
label local
menu label Boot from ^local drive
localboot 0xffff
[root@centos7 tftpboot]#tree
.
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
[root@centos7 ~]# systemctl start tftp
[root@centos7 ~]# systemctl enable tftp
[root@centos7 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@centos7 ~]# vim /etc/dhcp/dhcpd.conf
# option definitions common to all supported networks...
option domain-name "mylinuxops.com"; #
option domain-name-servers 114.114.114.114; # DNS
default-lease-time 6000;
max-lease-time 72000;
... ...
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
#subnet 10.152.187.0 netmask 255.255.255.0 { #
#} #
# This is a very basic subnet declaration.
subnet 192.168.73.0 netmask 255.255.255.224 {
range 192.168.73.1 192.168.73.100; # dhcp
option routers 192.168.73.254; #
filename "pxelinux.0"; #
next-server 192.168.73.120; # tftp
}
[root@centos7 ~]# systemctl start dhcpd
[root@centos7 ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.