Pxe+dhcp+nfs+tftp 网络安装 centos

 

一、 介绍
简单原理介绍:无光软驱服务器通过 PXE 网卡启动,从 dhcp 服务器获取 IP 通过 tftp 取到 pxelinux 配置文件,按配置文件进行启动 centos 文件进行引导系统安装。

 

二、环境说明
本文测试环境及用到的软件
Server: centos 5.2  dhcp nfs tftp  ip:192.168.1.251 ( IP 只需要与服务器网卡相连,不管是什么都可以 )

 

三、安装配置过程及基本讲解:
安装相应的软件: yum –y install dhcp* nfs* tftp*
1、  配置 tftp
[code] more /etc/xinetd.d/tftp
# default: off
# de.ion: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
# trad: liuyu
# blog: liuyu.blog.51cto.com
service tftp
{
        disable = no   # 默认是 yes 改为 no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -u nobody -s /tftpboot  # 添加 nobody 可以访问 //-s 表示用/tftpboot作为tftp目录的根目录
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
} [/code]
   重启 xinetd 服务: /etc/init.d/xinetd restart 
   查看 tftp 是否启动: # chkconfig --list |grep tftp
                        tftp:           on

 

2、  配置 nfs
mount /iso/CentOS-5.2-i386-bin-1of6.iso /mnt -o loop  # 我是挂载的镜像文件,你们可以挂载光驱
echo "/tftpboot *(ro,sync)" > /etc/exports 
echo "/mnt *(ro,sync)" > /etc/exports   # 此二步设置共享的目录
exportfs –a   # 使配置生效
/etc/init.d/portmap start  &&/etc/init.d/nfs start    # 重启服务
Showmount –e localhost  # 看查共享的目录
Export list for localhost:
/mnt      *
/tftpboot *

 

  3 、配置 dhcp
直接 copy 我的配置
[code]# more /etc/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
# trad: liuyu
# blog: liuyu.blog.51cto.com

 

ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.1.0 netmask 255.255.255.0 {

 

option routers 192.168.1.251;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.1.251;   # 本地 IP
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.1.12 192.168.1.254;  # 要分区的 IP
default-lease-time 21600;
max-lease-time 43200;
# Group the PXE bootable hosts together
# PXE-specific configuration directives...
next-server 192.168.1.251;
filename "/pxelinux.0";   # 方便查找配置文件
} [/code]

 

/etc/init.d/dhcpd start  启动服务

 

4、  配置 pxe 所需要的文件
[code]
Mkdir /tftpboot/pxelinux.cfg
cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
cp /mnt/isolinux/vmlinuz /tftpboot/
 cp /mnt/isolinux/initrd.img /tftpboot/
cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default  [/code]

 

四、测试
启动服务器,一般是按 F12 选择进入 PXE 网络启动。这时就会自动获取 IP 并进入
Boot: 界面。按 linux text 进入。之后选择 NFS 安装系统。

 

五、配置文件详解
dhcpd.conf 配置的有关说明:
 
parameters (参数):
ddns-update-style
配置 DHCP-DNS 互动更新模式
default-lease-time
指定缺省租赁时间的长度,单位是秒
max-lease-time
指定最大租赁时间长度,单位是秒
hardware
指定网卡接口类型和 MAC 地址
server-name
通知 DHCP 客户服务器名称
get-lease-hostnames flag
检查客户端使用的 IP 地址
fixed-address ip
分配给客户端一个固定的地址
authritative
拒绝不正确的 IP 地址的要求
 
declarations (声明):
shared-network
用来告知是否一些子网络分享相同网络
subnet
描述一个 IP 地址是否属于该子网
range
起始 IP 终止 IP 提供动态分配 IP 的范围
host
主机名称 参考特别的主机
group
为一组参数提供声明
allow unknown-clients
deny unknown-client 是否动态分配 IP 给未知的使用者
allow bootp
deny bootp 是否响应激活查询
allow booting
deny booting 是否响应使用者查询
filename
开始启动文件的名称,应用于无盘工作站
next-server
设置服务器从引导文件中装如主机名,应用于无盘工作站
 
option (选项):
subnet-mask
为客户端设定子网掩码
domain-name
为客户端指明 DNS 名字
domain-name-servers
为客户端指明 DNS 服务器 IP 地址
host-name
为客户端指定主机名称
routers
为客户端设定默认网关
broadcast-address
为客户端设定广播地址
ntp-server
为客户端设定网络时间服务器 IP 地址
time
offset 为客户端设定和格林威治时间的偏移时间,单位是秒。