PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTPtrivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户?)基本软件设置,从而引导预先安装在服务器中的终端操作系统。接下来,就让我们通DHCP+HTTP+TFTP来实现通过PXE安装CentOS 6.5.

1.安装DHCP服务器,使网卡可以获取到IP地址,并且可以找到有安装文件的TFTP服务器,并编辑dhcp服务的配置文件.

[root@localhost ~]# yum install dhcp[root@localhost ~]# rpm -q dhcpdhcp-4.1.1-38.P1.el6.centos.x86_64[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

接着我们启动DHCP服务,并开启一台无操作系统虚拟机,监测网卡是否可以获得IP地址

[root@localhost ~]# service dhcpd start

Starting dhcpd:                                            [  OK  ]

启动虚拟机,可以看到地址获取成功,但是由于我们还没有安装TFTP,所以安装过程也就进不去了

接下来我们就需要配置TFTP服务了.

2.我们需要安装TFTP服务,/etc/xintetd.d/tftp文件中的disable改为no,接着启动xinetd服务,

[root@localhost ~]# yum install tftp-server tftp[root@localhost ~]# rpm -q tftp-server tftp[root@localhost ~]# rpm -q tftp-server tftptftp-server-0.49-7.el6.x86_64tftp-0.49-7.el6.x86_64

通过查看端口,可以看到TFTP69号端口已经打开

3.接下来,我们需要把PXE启动需要的文件和引导内核文件都拷贝到TFTP的工作目录/var/lib/tftproot

#安装syslinux软件包

[root@localhost tftpboot]# yum install syslinux[root@localhost tftpboot]# rpm -q syslinuxsyslinux-4.02-8.el6.x86_64[root@localhost tftpboot]# rpm -ql syslinux |grep 0$/usr/share/syslinux/gpxelinux.0/usr/share/syslinux/pxelinux.0[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./

#复制引导内核文件

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/[root@localhost ~]# cp /mnt/cdrom/p_w_picpaths/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg[root@localhost /]# cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

此时我们应该已经可以进入安装界面,

4.基于HTTPD配置yum软件仓库为PXE提供安装源

[root@localhost /]# rpm -q httpd

httpd-2.2.15-29.el6.centos.x86_64

#通过光盘提供yum仓库

[root@localhost /]# mount --bind /mnt/cdrom/ /var/www/html/cdrom/

#启动服务

[root@localhost /]# service httpd start

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName

                                                           [  OK  ]

#通过浏览器测试源是否可以正常访问

5.提供ks.cfg文件

#安装system-config-kickstart

[root@localhost /]# yum install system-config-kickstart[root@localhost /]# rpm -q system-config-kickstartsystem-config-kickstart-2.8.6.5-1.el6.noarch

#通过xstart运行systm-config-kickatart,生成ks.cfg文件

#ks.kfg文件详细内容

[root@localhost /]# cat ~/ks.cfg #platform=x86, AMD64, or Intel EM64T#version=DEVEL# Firewall configurationfirewall --disabled# Install OS instead of upgradeinstall# Use network installationurl --url="http://172.16.21.250/cdrom"# Root passwordrootpw --iscrypted $1$8kLebhx5$XaCCpB3fvBnQutl9iQW3S1# System authorization informationauth  --useshadow  --passalgo=sha512# Use text mode installtextfirstboot --disable# System keyboardkeyboard us# System languagelang en_US# SELinux configurationselinux --disabled# Installation logging levellogging --level=info # System timezonetimezone  Asia/Chongqing# Network informationnetwork  --bootproto=dhcp --device=eth0 --onboot=on# System bootloader configurationbootloader --location=mbr# Partition clearing informationclearpart --all  # Disk partitioning informationpart / --fstype="ext4" --ondisk=sda --size=8000part /boot --fstype="ext4" --ondisk=sda --size=500part swap --fstype="swap" --size=1000 %packages@chinese-support@ftp-server@internet-browser@web-server %end

6.测试可否通过网络远程自动安装系统

#指定ks文件位置并回车运行

#可以看到系统已经在自动分区

#正在安装软件包,可见yum源配置也没有问题

#系统安装完成