一、PXE系统装机系统构成
需要的服务
DNS服务,为客户机分配主机名
DHCP服务,分配IP地址,定位引导程序
TFTP服务,提供引导程序下载
FTP服务(或HTTP/NFS),提供yum安装源
客户机应具备的条件
网卡ROM必须支持PXE协议
主板支持网络启动
二、PXE装机过程
远程客户端计算机启动,由于BIOS设置了网卡启动,所以网卡PXE ROM中的程序被调入内存执行。首先,客户端在网络中寻找DHCP服务器,然后请求一个IP地址;同时DHCP服务器联系到TFTP服务器为此客户端发送一个bootstrap(引导程序)。客户端收到bootstrap(文件pxelinux.0)后执行,bootstrap会请求TFTP传送bootstrap的配置文件(pxelinux.cfg)。收到后读配置文件。根据配置文件内容和客户情况,客户端请求TFTP传送内核映象文件(vmlinuz)和根文件系统文件(initrd.img)。最后启动内核。这就是一个完整的pxe构建过程。然而要使网卡启动后再继续网络安装系统,则最后还需要FTP或http服务将系统所需安装文件放置FTP相应目录中进行传输安装。
实验拓扑:
-----PXE Server(vmnet1)-------------Client(vmnet1)------
实验一:搭建PXE Server
服务器IP为192.168.10.253,可以给192.168.10.0/24安装RHEL5.9
分别给每台客户端分配主机名,格式如下(1-100)
stationx.tarena.com 192.168.10.x
安装所需要的软件包存放在/data/iso/rhel5.9
前期准备:
1、设置网络参数
[root@localhost ~]# ifconfig eth0 | grep"inetaddr"
inet addr:192.168.10.253 Bcast:192.168.10.255 Mask:255.255.255.0
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=server01.tarena.com
[root@localhost ~]# grep server01 /etc/hosts
192.168.10.253 server01.example.com server01
2、创建YUM源
[root@localhost ~]# mkdir -p /data/iso/rhel5.9
//放入rhel5.9 iso
[root@localhost ~]# cp -rpf /misc/cd/* /data/iso/rhel5.9/
3、配置YUM客户端
[root@localhost ~]# cd /etc/yum.repos.d/
[[email protected]]# cprhel-debuginfo.reporhel5.9.repo
[[email protected]]# cat rhel5.9.repo
[rhel-server]
name=Red Hat Enterprise Linux Server
baseurl=file:///data/iso/rhel5.9/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
实验步骤:
1、配置DHCP(给需要安装系统的主机分配ip)
[root@server01 ~]# rpm -q dhcp //检查是否安装了dhcp
package dhcp is not installed //提示没有安装
[root@server01 ~]# yum -y install dhcp //安装dhcp
[root@server01 ~]# cat /etc/dhcpd.conf //dhcp主配置文件
ddns-update-style interim;
default-lease-time 21600;
max-lease-time 43200;
optionrouters 192.168.10.254; //网关
optiondomain-name "tarena.com"; //域名
option domain-name-servers 192.168.10.253; //DNS
next-server192.168.10.253; //tftp服务器地址
filename"pxelinux.0"; //网卡引导文件名
subnet 192.168.10.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.10.1 192.168.10.100;
}
[root@server01 ~]# service dhcpd restart //开启服务
[root@server01 ~]# chkconfigdhcpd on //开机自启
[root@server01 ~]# netstat -tulnp | grep :67 //查看dhcp端口
udp 0 0 0.0.0.0:67 0.0.0.0:* 5219/dhcpd
2、配置DNS
[root@server01 ~]# rpm -q bind bind-chrootcaching-nameserver
package bind is not installed
package bind-chroot is not installed
package caching-nameserver is not installed
[root@server01 ~]# yum -y install bind bind-chrootcaching- nameserver
[root@server01 ~]# cd /var/named/chroot/etc/
[root@server01 etc]# cp -p named.caching-nameserver.confnamed.conf
[root@server01 etc]# vimnamed.conf
...
15 listen-on port 53 { 192.168.10.253; };
16 // listen-on-v6 port 53 { ::1; };
...
27 allow-query { any; };
28 allow-query-cache { any; };
...
37 match-clients { any; };
38 match-destinations { any; };
[root@server01 etc]# vim named.rfc1912.zones
...
51 zone "tarena.com" IN {
52 type master;
53 file "tarena.com.zone";
54 };
55
56 zone "10.168.192.arpa" IN {
57 type master;
58 file "10.168.192.arpa";
[root@server01 etc]# named-checkconfnamed.conf //检测语法是否出错
[root@server01 etc]# cd /var/named/chroot/var/named/
[root@server01 named]# cp -p named.localtarena.com.zone
[root@server01 named]# cattarena.com.zone
$TTL 86400
@ IN SOA localhost. root.localhost. (
2014061801 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ;Minimum
IN NS server01.tarena.com.
server01 IN A 192.168.10.253
$GENERATE 1-100 station$ IN A 192.168.10.$
[root@localhost named]# cat 10.168.192.arpa
$TTL 86400
@ IN SOA localhost. root.localhost. (
2014061801 ;Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS server01.tarena.com.
253 IN PTR server01.tarena.com.
$GENERATE 1-100 $ IN PTR station$
[root@server01 named]# service named restart
[root@server01 named]# chkconfig named on
3、配置TFTP
[root@server01 ~]# rpm -q tftp-server
tftp-server-0.49-2
[root@server01 ~]# vim /etc/xinetd.d/tftp
...
13 server_args = -s /tftpboot //文件路径
14 disable = no //启用服务
...
[root@server01 ~]# service xinetd restart
[root@server01 ~]# chkconfigxinetd on
[root@server01 ~]# netstat -tulnp | grepxinetd
udp 0 0 0.0.0.0:69 0.0.0.0:* 5842/xinetd
[root@server01 ~]# rpm -qlsyslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@server01 ~]# mkdir /tftpboot/pxelinux.cfg //创建目录
[root@server01 ~]# cp/data/iso/rhel5.9/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default //改名为default
[root@server01 ~]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
[root@server01 ~]# cp /data/iso/rhel5.9/isolinux/vmlinuz /tftpboot/ //内核、镜像到TFTP根目录
[root@server01 ~]# cp/data/iso/rhel5.9/isolinux/initrd.img /tftpboot/
4、配置NFS共享
[root@localhost ~]# cat /etc/exports
/data/iso/rhel5.9 *(ro)
[root@localhost ~]# serviceportmap restart
[root@localhost ~]# servicenfs restart
[root@localhost ~]# chkconfigportmap on
[root@localhost ~]# chkconfignfs on
或者配置FTP
[root@server01 ~]# yum -y install vsftpd
[root@server01 ~]# tail -n 1 /etc/vsftpd/vsftpd.conf
anon_root=/data/iso/rhel5.9
[root@server01 ~]# servicevsftpd restart
[root@server01 ~]# chkconfigvsftpd on
在或者配置HTTP
[root@server01 ~]# yum -y install httpd
[root@server01 ~]# grepDocumentRoot/etc/httpd/conf/httpd.conf | grep -v"^#"
DocumentRoot "/data/iso/rhel5.9"
[root@server01 ~]# grep Indexes/etc/httpd/conf.d/welcome.conf
Options Indexes
[root@server01 ~]# servicehttpd restart
[root@server01 ~]# chkconfig httpd on
实验二:通过Kickstart实现无人值守安装(接着实验一)
[root@localhost ~]# yum -y installsystem-config-kickstart
操作过程见图片
在/root/ks.cfg文件中添加key --skip
[root@localhost ~]# cp /root/ks.cfg /data/iso/rhel5.9/
//将应答文件不是在客户机可以访问的位置
[root@server01 ~]# vim /tftpboot/pxelinux.cfg/default
...
10 label linux
11 kernel vmlinuz
12 appendinitrd=initrd.imgks=http://192.168.10.253/ks.cfg
//修改启动菜单文件,调用应答文件
客户端测试
BIOS-----网卡启动