kichstart+dhcp+tftp+http+pxe批量自动安装centos

1.基本概念

PXE:PXE(Pre-boot Execution Environment)可以使计算机通过网络启动,共同作于Client/Server的网络模式。其中PXE Client在网卡的ROM中,当系统启动时,BIOS把PXE Client调入内存执行,请求IP地址和TFTP服务的地,因而需要DHCP服务器和TFTP服务器。即PXE Client指的是需要安装操作系统的节点。

DHCP Server:安装了DHCPD服务的节点,当收到客户端DHCP请求时,给客户端分配一个IP。

TFTP Server:安装了TFTPD服务的节点,用于传输文件(如pxelinux.cfg里面的default配置文件,/var/lib/tftpboot里面的vmlinuz内核文件和initrd.img等。

HTTP Server:用于共享文件文件,根目录为/var/www/html/。我们用HTPPD服务共享文件,如系统配置文件ks.cfg和系统跟文件系统。另外也可以使用TFTP、FTP、NFS来共享这些文件。

为了方便,可以将DHCP、TFTP和HTTP服务器设置在一台机器上。在下面的流程中,将DHCP、TFTP和HTTP服务配置在VirtualBox里面的CentOS系统上。

 

2.     配置过程

环境:在局域网中一同四台机器,其中一台已经安装好Centos系统作为服务器,另外三台机器是需要安装操作系统。我们将安装在VirtualBox里面的CentOS系统作为服务器,VirtualBox里面的CentOS系统采用桥接方式连入局域网之中。

 

2.1   VirtualBox设置

网络连接方式桥接网卡

 

2.2   设置centos为静态IP

 配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0

修改后文件为:

 

重启网卡驱动:/etc/init.d/network restart

 

2.3 配置DHCPD服务

安装DHCP,yum install dhcp,或者选择rpm安装。

配置DHCP服务,修改文件:/etc/dhcpd.conf,修改的地方如下所示(红色为修改部分)。

ddns-update-style interim;

ignore client-updates;

 

subnet 192.168.1.0 netmask 255.255.255.0 {

 

# --- default gateway

option routers              192.168.1.1;

option subnet-mask   255.255.255.0;

 

option nis-domain         "domain.org";

option domain-name             "domain.org";

option domain-name-servers 192.168.1.1;

next-server                  192.168.1.90;  // tftp服务器的IP地址,虚拟机的IP

filename                      "/pxelinux.0";  //

 

range dynamic-bootp 192.168.1.100 192.168.1.245;

default-lease-time 21600;

max-lease-time 43200;

 

# we want the nameserver to appear at a fixed address

host ns {

        next-server marvin.redhat.com;

        hardware ethernet 12:34:56:78:AB:CD;

        fixed-address 192.168.1.90;

           }

}

 

测试DCHCP服务能否启动:service dhcpd start

 

2.4 安装TFTP-server,并配置TFTP

tftp配置文件:/etc/xinetd.d/conf,红色部分是需要修改或者注意的地方的地方

 

# default: off 默认tftp是关闭的

# description: 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.

 

service tftp

{

       socket_type            = dgram

       protocol         = udp

       wait               = yes

       user               = root

       server         = /usr/sbin/in.tftpd    # tftp服务程序的位置

       server_args  = -s /var/lib/tftpboot  # tftp服务的目录,即文件下载目录

       disable          = no                # 默认是也是yes,改为no

       per_source      = 11

       cps                 = 100 2

       flags                     = IPv4

}

 

2.5 配置HTTP服务

安装软件: yum install httpd。

启动:service httpd start

 

2.6 配置支持PXE启动

1)把需要安装的系统光盘镜像iso文件挂载到一个指定的目录下,比如挂载到/mnt/cdromm目录下:


2)把/mnt/cdrom里面的所有的系统文件复制到/var/www/html文件加里面。

      cp –rf   /mnt/cdrom/*   /var/www/html/

3)进入/var/lib/tftpboot文件家,如果不存在tftpboot文件夹,就新建该文件夹。

4)复制pxelinux.0和vesamenu.c32 到tftpboot中:
   cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot
   cp /usr/share/syslinux/vesamenu.c32  /var/lib/tftpboot
5)复制initrd.img和vmlinux到tftpboot中
   cp /var/www/html/image/pxeboot/initrd.img   /var/lib/tftpboot
   cp /var/www/html/image/pxeboot/vmlinux      /var/lib/tftpboot
6)复制isolinux/*.msg到/tftpboot/中
   cp /var/www/html/isolinux/*.msg   /var/lib/tftpboot

7)在tftpboot中新建一个pxelinux.cfg目录

    mkdir pxelinux.cfg

8)把isolinux.cfg复制到pxelinux.cfg目录中,并同时更改文件名称为default

9)修改default文件

default linux

prompt 1

timeout 600

display boot.msg

F1 boot.msg

F2 options.msg

F3 general.msg

F4 param.msg

F5 rescue.msg

label linux

  kernel vmlinuz

  append initrd=initrd.img ks=http://192.168.1.90/ks.cfg

label text

  kernel vmlinuz

  append initrd=initrd.img text

label ks

  kernel vmlinuz

  append ks initrd=initrd.img

label local

  localboot 1

label memtest86

  kernel memtest

  append -

initrd=initrd.img指定ram disk的引导文件,在引导的过程中挂载一个临时文件系统,用来挂载实际的文件系统。ks=http://192.168.1.90/ks.cfg指定系统的配置文件的共享位置。

10)给/var/lib/tftpboot目录以及下面所有的文件添加权限。

chmod -R 777 /tftpboot/

      

2.7 安装kickstart并进行配置

u  安装kickstart。

u  把/root/anaconda-ks.cfg wen文件拷贝到/var/www/html文件夹里面,并重命名为ks.cfg。

cp/root/anaconda-ks.cfg  /var/www/html/ks.cfg

 

ks.cfg文件内容如下,可以根据自己的需要进行配置。

firewall --disable

 

url --url="http://192.168.1.90/" #系统文件与配置文件的共享位置

 

network --device eth0 --bootproto dhcp

rootpw --iscrypted $1$VGTBJgjN$v2m7VhTGrZSrL/RoQExpG/

firewall --enabled --port=22:tcp

authconfig --enableshadow --enablemd5

selinux --disabled

 

timezone --utc Asia/Hong_Kong

lang en_US

keyboard us

 

bootloader --location=mbr --driveorder=sda --append="centos 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 --all --drives=sda

 

zerombr

clearpart --all --initlabel

 

skipx

install

 

#分区可以自己设定

part /boot --fstype ext3  --size=200

part  swap --fstype swap  --size=2048

part   /   --fstype ext3  --size=470000

#part pv.2 --size=0 --grow --ondisk=sda

#volgroup VolGroup00 --pesize=32768 pv.2

#part  swap --fstype swap  --size=2048

#part   /   --fstype ext3  --size=200000

 

%packages

@base

@core

@dialup

@editors

@gnome-desktop

@games

@graphical-internet

@graphics

@office

@printing

@sound-and-video

@text-internet

@base-x

keyutils

trousers

fipscheck

device-mapper-multipath

libsane-hpaio

xorg-x11-server-Xnesti

 

2.8 必要工作

关闭防火墙:

/etc/init.d/iptables stop

启动或重启服务:

/etc/init.d/dhcpd start(或者service dhcpdstart/restart)

/etc/init.d/xinetd start

/etc/init.d/httpd start  (或者service httpd start/restart

 

2.9 网络引导

启动需要安装系统的机器,选择从网络引导,观察显示器的错误提示,如IP地址不能正常分配,错误会提示timeout;是否能正确读取和引导内核文件vmlinuz;是否能争取读取ks.cfg文件,自动安装;硬盘划分是否正确,超出最大容量,等等,错误提示很明显。

 

 

参考资料:

【1】       http://www.linuxidc.com/Linux/2012-12/75570.htm

【2】       http://blog.csdn.net/silent1/article/details/7635646

【3】       Kickstart+PXE+TFTP+DHCP自动安装CentOS5.2

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值