一.适用环境: <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1. 需要大规模批量部署 linux 操作系统

2. 客户端无光驱或光驱损坏,需要网络安装 linux 系统

3. 需要隔三差五重复安装 linux 系统,为了减少麻烦,节约时间,提高效率。

二、原理

在服务器端搭建 DHCP tftp nfs 服务并用 kickstart 配置自动安装脚本, DHCP 服务用于向客户端分配 IP,tftp 服务用于传输 bootloader 文件 pxelinux.0 nfs 服务负责传输安装镜像文件,用 kickstart 配置的 ks.cfg 实现无人值守全自动安装。

前提:客户端网卡内置 PXE 芯片,现在一般网卡都支持 pxe 协议。

三.具体操作过程 ( 基于 RHEL)

 
  

 
  
 
  

 

 
  
 
  

 
  
 
  
 
  

 

 

 

#service dhcpd start     //启动服务
4.复制内核相关文件到/tftpboot
  #cd /tftpboot
  #cp  /mnt/isolinux/*  ./      (
实际需要的是 vmlinuz initrd.img *.msg 这几个文件,但为了操作方便,我直接把 isolinux目录下的文件全cp过来 )
  #mkdir pxelinux.cfg
  #mv isolinux.cfg     pxelinux.cfg/
default       (
default 配置文件的作用是告诉主机从哪里去加载操作系统内核 )
  #cp /usr/lib/syslinux/pxelinux.0  ./    (
将启动加载文件拷到/tftpboot)
5. 修改 tftp 参数 并启动tftp服务
# vi /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

            per_source              = 11

            cps                     = 100 2

            flags                   = IPv4

           }

…………………………………………………………………………………………

 

tftpboot 这个参数主要是指定tftp client 客户端从服务器的哪个目录去加载bootloaderpxelinux.0文件。
#service xinetd restart       // 启动服务
或者不改tftp参数直接启动
#chkconfig tftp on
#service xinetd restart
6. 修改/tftpboot/pxelinux.cfg/default文件

#vi /tftpboot/pxelinux.cfg/default
修改第3行,第12.

1 default linux
2 prompt 1
3 timeout
10             // 时间调小点
4 display boot.msg
5 F1 boot.msg
6 F2 options.msg
7 F3 general.msg
8 F4 param.msg
9 F5 rescue.msg
10 label linux
11 kernel vmlinuz
12 append
ks=nfs:192.168.0.20:/pub/ks.cfg   initrd=initrd.img
13 label text
……

7. 安装kickstart配置ks.cfg

 
  
/目录下创建pub目录,将ks.cfg移动到此目录下。
#
chmod 707 /pub/ks.cfg      // 修改ks.cfg权限

ks.cfg 文件,最终配置示例如下:

#Generated by Kickstart Configurator

#platform=x86, AMD64, or Intel EM64T

#System  language

lang en_SG

#Language modules to install

langsupport zh_CN en_US --default=en_SG

#System keyboard

keyboard us

#System mouse

mouse

#Sytem timezone

timezone Asia/Shanghai

#Root password

rootpw --iscrypted $1$2qm1.E7d$/p/NGomGdh00jvBeeIyLR.

#Reboot after installation

reboot

#Install OS instead of upgrade

install

#Use NFS installation Media

nfs --server=192.168.0.20  --dir=/mnt

#System bootloader configuration

bootloader --location=mbr

#Clear the Master Boot Record

zerombr yes

#Partition clearing information

clearpart --all --initlabel

#Disk partitioning information

clearpart --all --initlabel

#Disk partitioning information

part swap --size 512

part /boot --fstype ext3 --size 100

part / --fstype ext3 --size 1 --grow

#System authorization infomation

auth  --useshadow  --enablemd5

#Network information

network --bootproto=dhcp --device=eth0

#Firewall configuration

firewall --disabled

#XWindows configuration information

xconfig --depth=8 --resolution=640x480 --defaultdesktop=GNOME

#Package install information

%packages --resolvedeps

@ base-x                  // 最小化安装  (如果用kickstart不能选择安装包时需要手动添加)

如果是RHEL5需要手动添加一行

key --skip          // 跳过安装序列号

8.配置nfs并启动服务

#vi /etc/exports         //添加两行记录

/mnt    *(ro)

/pub     *(ro)

#service nfs start

9.为保证实验一次成功,将所有服务都重新启动一下

#service dhcpd restart

#service xinetd restart

#service nfs restart

10.在一客户端上进行测试(server在同一局域网内).

提示:客户端在确定domain namehost name时会等几分钟时间请耐心等待

※成功标志:能顺利跳过各项设置到开始自动安装软件包代表服务器配置没问题(客户端只能有个开机动作)