免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1811 | 回复: 0
打印 上一主题 下一主题

Pxe+dhcp+nfs+tftp 网络安装centos(转载修改) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-10 15:17 |只看该作者 |倒序浏览
Pxe+dhcp+nfs+tftp 网络安装centos(转载修改)一、 介绍 简单原理介绍:无光软驱服务器通过PXE网卡启动,从dhcp服务器获取IP 通过tftp 下载pxelinux.0文件找到pxelinux.cfg里的配置文件,按配置文件找着vmlinuz引导centos进入安装界面,之后选择NFS方式安装系统。二、环境说明本文测试环境及用到的软件Server: centos 5.1  dhcp nfs tftp  ip:192.168.1.132 (此IP只需要与服务器网卡相连,不管是什么都可以)三、安装配置过程及基本讲解:安装相应的软件:yum –y install dhcp* nfs* tftp*1、安装完成tftp后,在系统中会自动生成一个配置文件,这个配置文件不需要修改。 配置tftp
  • more /etc/xinetd.d/tftp  
  • service tftp
  • {
  •         disable = no   #默认是yes 改为no
  •         socket_type             = dgram
  •         protocol                = udp
  •         wait                    = yes
  •         user                    = root
  •         server                  = /usr/sbin/in.tftpd
  •         server_args             = -s /tftpboot  #-l -v -c等参数可以自行参开相关的文章
  •         per_source              = 11
  •         cps                     = 100 2
  •         flags                   = IPv4
  • }复制代码重启xinetd服务: /etc/init.d/xinetd restart     查看tftp 是否启动:# chkconfig --list |grep tftp                        tftp:           on2、 配置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我的配置
  • # more /etc/dhcpd.conf
  • 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.1;
  • option subnet-mask 255.255.255.0;
  • option domain-name-servers 192.168.1.251;   #dns网址 可以设为本地机器的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";   #方便查找配置文件
  • }复制代码/etc/init.d/dhcpd start  启动服务4、 配置pxe所需要的文件
  • 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  复制代码四、测试实验
    1.首先需要在本地机器上测试tftp服务的运转
    验证69端口的开启:
    #netstat -nlp | grep udp
    udp        0      0 0.0.0.0:68                  0.0.0.0:*                               3294/dhclient      
    udp        0      0 0.0.0.0:69                  0.0.0.0:*                               1522/xinetd         
    udp        0      0 0.0.0.0:973                 0.0.0.0:*                               1224/rpcbind        
    udp        0      0 0.0.0.0:5353                0.0.0.0:*                               1246/avahi-daemon:  
    udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1224/rpcbind        
    然后验证tftp的运行情况:
    #tftp 192.168.1.132
    >get pxelinux.0
    >q (退出tftp)
    如果系统正常,将在当前目录下获得一个pxelinux.0的文件。tftp的测试是本实践测试的关键所在,必须要通过,不然将会失败。
    在tftp的配置过程中出现问题较多,有时需要修改/tftpboot文件夹的所有者为:chmod -R 777 /tftpboot
    2.检查dhcp, nfs的运行情况
    #service dhcpd status
    #service nfs status
    这个两个服务必须运行起来。
    五. 相关的shell脚本(代码还有待完善,有问题联系hsiung2007@gmail.com)
    #!/bin/sh
    #Author:Peter Hsiung
    #Time:2010.1.10
    #Email:hsiung2007@gmail.com
    ROOT=`whoami`
    if [ $# -lt 1 ]; then
            echo "Please enter the iso file and the mount directory"
            echo "like xx.sh Fedora12.iso /mnt"
            exit 1
    fi
    #mount the iso file
    umount $2
    if mount -o loop $1 $2 ; then   # find a good place to mount the iso file
            echo "mount the os file"
    else
            echo "Can not mount the os file!"
            exit 1
    fi
    #make a directory to export the install files
    if [ $ROOT != "root" ]; then
            echo "You are not root!"
            exit 1
    fi
    if [ ! -e /tftpboot ]; then
            echo "make the tftpboot"
            mkdir /tftpboot
    fi
    if [ ! -e /tftpboot/pxelinux.cfg ]; then
            echo "make the /tftpboot/pxelinux.cfg"
            mkdir /tftpboot/pxelinux.cfg
    fi
    file1="/usr/lib/syslinux/pxelinux.0"
    file2="/$2/isolinux/vmlinuz"
    file3="/$2/isolinux/initrd.img"
    file4="/$2/isolinux/isolinux.cfg"
    #copy the files
    for i in $file1 $file2 $file3
    do
            if [ -e $i ] ; then
                    cp $i /tftpboot/
            else
                    echo "$i does not exist!"
            fi
    done
    if [ -e $file4 ] ; then
            cp -f $file4 /tftpboot/pxelinux.cfg/default
    else
            echo "$file4 does not exist!"
    fi
    #export the directories
    echo "/tftpboot *(ro,sync)" > /etc/exports
    echo "$2 *(ro,sync)" >> /etc/exports
    exportfs -a
    showmount -e localhost
    #start all service and prepare for the network install
    /etc/rc.d/init.d/dhcpd restart
    /etc/init.d/portmap restart
    /etc/init.d/nfs restart
    /etc/init.d/xinetd restart
    六、配置文件详解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 为客户端设定和格林威治时间的偏移时间,单位是秒。
                   
                   
                   
                   

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/110010/showart_2144925.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP