实验拓扑:

                   

-----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/

[root@localhostyum.repos.d]# cprhel-debuginfo.reporhel5.9.repo

[root@localhostyum.repos.d]# cat rhel5.9.repo

[rhel-server]

name=Red Hat Enterprise Linux Server

baseurl=file:///data/iso/rhel5.9/Server               //指定yum源路径

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             //开启dhcp服务

[root@server01 ~]# chkconfigdhcpd on               //设置dhcp开机自启

[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   //复制配置文件,注意加-p保留权限

[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    //重启dns服务

[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

在或者配置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下备用。

在/root/ks.cfg文件中添加key  --skip

[root@localhost ~]# cp /root/ks.cfg  /data/iso/rhel5.9/

//将应答文件布置在客户机可以访问的位置

[root@server01 ~]# vim /tftpboot/pxelinux.cfg/default   //编辑default文件

...

 10 label linux   

 11   kernel vmlinuz

 12   appendinitrd=initrd.imgks=http://192.168.10.253/ks.cfg

  //修改启动菜单文件,调用应答文件

客户端测试

BIOS-----网卡启动,自动进行系统安装。