Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18699
  • 博文数量: 11
  • 博客积分: 400
  • 博客等级: 下士
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-07 13:06
文章存档

2011年(1)

2009年(10)

我的朋友
最近访客

分类: LINUX

2009-09-22 13:29:43

RHEL5下通过PXE+DHCP+TFTP+NFS(FTP|HTTP)+KickStart+(DNS)实现无人值守网络安装系统
一、原理
       客户端通过网卡PXE启动-->连接到DHCP服务器-->获得IP地址-->客户端从TFTP服务器下载pxelinux.0,根据配置文件(default)下载指定的vmlinuz,initrd-->启动系统内核,加载初始化镜像文件(加载参数是否有ks)-->安装初始化完成-->到指定的位置(NFS|FTP|HTTP服务器上)下载软件包进行安装。
    服务器端根据不同的设置,可实现RHEL的手动或自动安装,配置救援模式。还可用于同时安装其他版本的LINUX,如OPEN SUSE LINUX,UBUNTU,Fedora,CentOS等,服务器端配置略有不同。

二、步骤
1、需要一台RHEL5作为安装服务器;
2、安装配置TFTP;
3、安装配置DHCP;
4、安装配置NFS或HTTP,FTP(ubuntu的安装源必须放在HTTP服务器下);
5、 要实现自动安装,需配置KickStart

三、具体实现

     第一步:安装所需的服务和软件包,通过 YUM 和RPM的安装方式都可以,这里以YUM为例。

yum install tftp-server <------安装tftp服务器端        
yum install dhcpd <------安装dhcp服务
yum install nfs-utils portmap <------安装nfs服务器
yum install system-config-netboot <-----安装网络安装目录相关文件,可以不装,但装了方便很多。

第二步:配置相关的服务

DHCP 部分  
vim /etc/dhcpd.conf

# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample  
#
ddns-update-style interim;
ignore client-updates;
allow bootp;  <---这两行允许开机引导DHCP;
allow booting;

subnet 10.1.1.0 netmask 255.255.255.0 {  <---配置好子网段

# --- default gateway
        option routers                  10.1.1.1; <---网关
        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      10.1.1.234; <---如果需要DNS,在这里指定。可以实现客户端指定主机名。

        option time-offset              -18000; # Eastern Standard Time
#       option ntp-servers              192.168.1.1;
#       option netbios-name-servers     192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#       option netbios-node-type 2;
        next-server 10.1.1.234; <------指定自动安装服务器;
        filename "linux-install/pxelinux.0";  <------指定pxelinux.0的位置,为tftp的相对路径;
        range dynamic-bootp 10.1.1.2 10.1.1.254; <------IP地址池;
        default-lease-time 21600;
        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address   <------这一段是为指定的机指定专有IP,不需要就注释掉。
#       host ns {
#               next-server marvin.redhat.com;
#               hardware ethernet 12:34:56:78:AB:CD;
#               fixed-address 207.175.42.254;
#       }
}
~      
TFTP 部分  

vim /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  <------将这里改为no,即使用xinetd来启动tftp
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4

NFS 部分

vim /etc/exports

/isolinux  *(ro,sync)  <------NFS 共享目录,所有网段内的主机只读访问,光盘镜像就放到这里来,NFS在局域网内速度最快,而且不用将ISO解开。

FTP 部分
HTTP 部分
稍后补充

第三部  配置tftp目录和需要的文件

如果像我前面说的安装了system-config-netboot,那么在/tftpboot的目录下自动生成一个linux-install文件夹,我们将所有的文件统一放到这个目录下面,以便需要提供多个系统安装时方便管理。
在linux-install下面,应该存在如下目录和文件
 pxelinux.0  <------ 客户端从服务器上下载下来需要读取defauft配置文件,安装了system-config-netboot即生成,如果没有,则cp /usr/lib/syslinux/pxelinux.0 /tftpboot/linux-install/;
./msgs:  <------放置启动引导介面的图片,可以修改提示信息,安装了system-config-netboot即生成,如果没有,光盘里有;
boot.msg  expert.msg  general.msg  param.msg  rescue.msg  snake.msg

./pxelinux.cfg:
default   <------客户端根据default的设置来确定怎样安装哪一个Linux系统,这个文件默认没有,可以从cp 光盘上的/isolinux/isolinux.cfg /tftpboot/linux-install/pxelinux.cfg/default ,或者 cp /usr/share/system-config-netboot/pxelinux.cfg/default 到这个目录

./rhel5u3:  <------为每一个安装系统新建一个文件夹,方便管理,如/tftpboot/linux-install/rhel5u3
initrd.img  vmlinuz <------ 将对应的系统的内核文件vmlinuz和初始化镜像文件initrd.img拷贝到该目录下,cp 光盘上的/images/pxeboot/initrd.img vmlinuz ./

./ubuntu <------你还可以设置其他的系统网络安装,放在这里即可。

第四部分  配置安装引导文件

vim  /tftpboot/linux-install/pxelinux.cfg/default

default 1    <------默认引导哪一个系统安装 ,与下面的label对应
timeout 300  <------等待选择的超时时间,300表示30秒
prompt 1     
display msgs/boot.msg  <------默认显示哪个启动后图象文件
F1 msgs/boot.msg
F2 msgs/general.msg
F3 msgs/expert.msg
F4 msgs/param.msg
F5 msgs/rescue.msg
F7 msgs/snake.msg
 
 label 0  <------从本地启动
  localboot 1

label 1   <------ 你看,label 1 ,即你在等待符boot:下输入1  ,回车,就引导下面的安装了。当然默认也是它了。
  kernel rhel5u3/vmlinuz
  append initrd=rhel5u3/initrd.img  ramdisk_size=8192 devfs=nomount

label  2 
  kernel rhel5u3/vmlinuz
  append ks=nfs:172.16.100.111:/netinstall/rhel5u3/ks.cfg initrd=rhel5u3/initrd.img  ramdisk_size=8192 devfs=nomount <------将ks文件放到NFS(FTP,HTTP都行)服务器上,就可以实现自动安装了,当然先要配置好ks.cfg ,也可以把这里设为默认启动它。

label 3 <-----内存测试
  kernel memtest
  append -

label 4  <------后面就不写了,根据自己的需要修改
  kernel vmlinuz
  append initrd=initrd.img text






第五部分 修改boot.msg ,添加需要的说明信息

    vim /tftpboot/linux-install/msgs/boot.msg
 
                ^O09Welcome to ^O0cRed Hat Network^O09 Installer!^O07  <-----welcome 信息,下面是一条可爱的蛇形图案
^O0a
                          .-=-.          .--.
              __        .'     '.       /  " )
      _     .'  '.     /   .-.   \     /  .-'^O0c\^O0a
     ( \   / .-.  \   /   /   \   \   /  /    ^O0c^^O0a
      \ `-` /   \  `-'   /     \   `-`  /
       `-.-`     '.____.'       `.____.'
^O07
 
huang.daojin's linux-install <-------说明一下是我的服务器
 
Enter number of the Operation System you wish to install:
 
0.  Local Machine  <-----
1. RHEL5.3     <------提示菜单,要和default里的编号对应
2、 RHEL5.3 AUTO INSTALL
3、memtest
4、。。。。。。
 
nfs:10.1.1.234   iso directroy : /isolinux <------注明安装服务的IP和iso文件的路径

第六部分   制作ks.cfg 文件 (不是必须)

如果你想客户机安装一个和你的服务机差不多系统,那里只有将anaconda-ks.cfg ,mv成ks.cfg ,放到nfs:172.16.100.111:/netinstall/rhel5u3/ks.cfg
比较简单的方法是安装一个kickstart图形配制工具 yum install system-config-kickstart -y
值得注意的是,在RHEL5里面要想使用它,必须配置好本地源,RHEL4不需要。这里不敷述。
当然你也可以手写一个ks.cfg,就像下面那样

install
nfs --server=10.1.1.116 --dir=/root
key --skip
lang zh_CN.UTF-8
keyboard us
xconfig --startxonboot
network --device eth0 --bootproto dhcp --hostname hdaojin.uplooking.com
network --device eth1 --onboot no --bootproto dhcp --hostname hdaojin.uplooking.com
rootpw --iscrypted $1$0myW.dEX$tsXSvEGr0fqmkvu971osj.
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux
#part /boot --fstype ext3 --size=500
#part /home --fstype ext3 --size=50000
#part /tmp --fstype ext3 --size=1024
#part swap --size=2048
#part / --fstype ext3 --size=20480
 
key --skip   <------对于RHEL5,如果你没有安装序列号,就加这一行。否则自动安装过程中会跳出等待输入。

%packages
@office
@editors
@text-internet
@gnome-desktop
@core
@base
@java
@legacy-software-support
@base-x
@chinese-support
@graphics
@admin-tools
@graphical-internet
vim-X11
kexec-tools
fipscheck
device-mapper-multipath
xorg-x11-utils
xorg-x11-server-Xnest
libsane-hpaio
-emacs-leim
-psgml
-emacspeak

第七部分  重启相关的服务

service dhcp restart
service xinetd restart
service portmap restart
service nfs restart
 
阅读(759) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~