使用PXE+DHCP+Apache+Kickstart批量安装CentOS5.4 x86_64

量安装一般都用在大批量部署新服务器时可以用到。

1. 什么是PXE

严格来说,PXE 并不是一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE ClientPXE Pre-boot Execution Environment)协议可以使计算机通过网络启动。此协议分为 Client端和 Server 端,而PXE Client则在网卡的 ROM 中。当计算机引导时,BIOS 把 PXE Client 调入内存中执行,然后由 PXE Client 将放置在远端的文件通过网络下载到本地运行。运行 PXE 协议需要设置 DHCP 服务器和 TFTP 服务器。DHCP 服务器会给 PXE Client(将要安装系统的主机)分配一个 IP 地址,由于是给 PXE Client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的 PXE 设置。此外,在 PXE Client 的 ROM 中,已经存在了 TFTP Client,那么它就可以通过 TFTP 协议到 TFTP Server 上下载所需的文件了。

2. 什么是Kickstart

Kickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为 ks.cfg的文件。如果在安装过程中(不只局限于生成Kickstart安装文件的机器)出现要填写参数的情况,安装程序首先会去查找 Kickstart生成的文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便需要安装者手工干预了。所以,如果Kickstart文件涵盖了安装过程中可能出现的所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启系统,并结束安装。

3. PXE + Kickstart的安装条件和详细步骤

执行PXE+Kickstart安装需要的设备为:

DHCP 服务器。

TFTP 服务器。

Kickstart所生成的ks.cfg配置文件。

一台存放系统安装文件的服务器,如 NFSHTTP 或 FTP 服务器。

一个带有 PXE 支持网卡的主机。


一,系统环境介绍如下:

服务器系统为CentOS5.4 x86_64IP192.168.11.29(此服务器并非一定要限定为CentOS5.4 x86_64系统),由于是最小化安装的,我们在后面要用到system-config-kickstart工具,它必须依赖于X windows,所以我们要提前安装好X windowsgnome并重启系统,步骤如下所示:

先装X windowsGNOME桌面环境,命令如下所示:

yum -y groupinstall 'X Window System'

yum -y groupinstall 'GNOME Desktop Environment'

完成上述的准备工作后,PXE+DHCP+Apache+Kickstart无人值守安装CentOS5.8安装的步骤如下:

#yum -y install httpd*  tftp-server* dhcp*

#mount /dev/cdrom /mnt


#cp -rf /mnt/* /var/www/html/

二,配置tftp

#vim /etc/xinetd.d/tftp

service tftp

{

       socket_type             = dgram

       protocol                = udp

       wait                    = yes

       user                    = root

       server                  = /usr/sbin/in.tftpd

       server_args             = -s /tftpboot

       disable                 = no

#yes改成no

       per_source              = 11

       cps                     = 100 2

       flags                   = IPv4

}

三,配置pxe

#mkdir -p /tftpboot

#cp /usr/lib/syslinux/pxelinux.0 /tftpboot

6.0系列的系统可能需要安装syslinux,并路径跟之前不一样

#cp /usr/share/syslinux/pxelinux.0 /tftpboot  如果没有,则需要yum -y install syslinux 针对6.0的系统

#cp /var/www/html/pxeboot/initrd.img /tftpboot

#cp /var/www/html/pxeboot/vmlinux /tftpboot

#cp /var/www/html/isolinux/*.msg /tftpboot

#mkdir  /tftpboot/pxelinux.cfg

#cd /tftpboot/pxelinux.cfg

#cp /var/www/html/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

四,配置dhcp

cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

# vim /etc/dhcpd.conf

ddns-update-style interim;

ignore client-updates;

next-server 192.168.1.16;

filename "/pxelinux.0";


subnet 192.168.1.0 netmask 255.255.255.0 {


option routers192.168.1.1;

option subnet-mask255.255.255.0;


option nis-domain"flybird.com";

option domain-name"flybird.com";

option domain-name-servers192.168.1.1;


option time-offset-18000;# Eastern Standard Time


range dynamic-bootp 192.168.1.128 192.168.1.254;

default-lease-time 21600;

max-lease-time 43200;

}

五,配置kickstart

#yum -y install system-config-kickstart

在图形环境下,打开终端,并输入system-config-kickstart

160918836.jpg

160927785.jpg

161004839.jpg

161012139.jpg

161013387.jpg

如果这里选择静态IP,表示这安装完机器的IP将是这个。

161016612.jpg

161017260.jpg

161022804.jpg

161245621.jpg

161133689.jpg

161042479.jpg


六,将ks.cfg复制到/var/www/html/

#vim  /var/www/html/ks.cfg

#platform=x86, AMD64, or Intel EM64T

# System authorization information

auth  --useshadow  --enablemd5

# System bootloader configuration

bootloader --location=mbr

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Use graphical install

graphical

# Firewall configuration

firewall --disabled

# Run the Setup Agent on first boot

firstboot --disable

#redhat系统需要添加

key --skip

# System keyboard

keyboard us

# System language

lang en_US

# Installation logging level

logging --level=info

# Use network installation

url --url=http://192.168.1.16/

# Network information

network --bootproto=dhcp --device=eth0 --onboot=on

# Reboot after installation

reboot

#Root password

rootpw --iscrypted $1$cHBy8eWZ$xvB4dr7o4kHmY9rF2mYOS1


# SELinux configuration

selinux --disabled

# Do not configure the X Window System

skipx

# System timezone

timezone --isUtc Asia/Chongqing

# Install OS instead of upgrade

install

# Disk partitioning information

part /boot --asprimary --bytes-per-inode=4096 --fstype="ext3" --size=100

part / --bytes-per-inode=4096 --fstype="ext3" --size=30000

part swap --bytes-per-inode=4096 --fstype="swap" --size=20000

part /data --bytes-per-inode=4096 --fstype="ext3" --grow  --size=1


%packages

@base

@development-libs

@development-tools

七,启动服务

#service httpd start

#chkconfig httpd on

#service dhcpd start

#chkconfig dhcpd on

#service xinetd restart

此时客户端选择网卡启动,会自动开始安装系统