参考链接:

http://www.cnblogs.com/mchina/p/centos-pxe-kickstart-auto-install-os.html


http://grokbase.com/t/centos/centos/0825tedy23/kickstart-stops-with-dialog-about-which-networking-device-how-to-avoid


http://bbs.linuxtone.org/thread-9446-1-1.html


http://www.docin.com/p-208713687.html



一、安装批量部署server端中的软件:


1、准备工作:

1.1、关闭iptables

service iptables stop

查看状态:

service iptables status


1.2、关闭selinux


临时,不用重启修改

#setenforce 0


需要重启的修改:

#vim /etc/sysconfig/selinux
SELINUX=disabled


查看状态:

#sestatus -v



2、安装软件(HTTP、TFTP、DHCP):


2.1 安装HTTP

2.1.1安装http

#yum install httpd –y
#/etc/init.d/httpd start
#chkconfig --level 35 httpd on


2.1.2 加载IOS文件


挂载IOS

PXE kickstart 批量部署 centOS6.5_kickstart


将iso文件挂载至/mnt/cdrom


[root@test ~]#mkdir /mnt/cdrom
[root@test ~]#mount /dev/cdrom /mnt/cdrom
mount:block device /dev/sr0 is write-protected,mounting read-only
[root@test ~]


2.1.3 复制光盘内容至http根目录下

[root@test ~]#cp -r /mnt/cdrom /var/www/html/


2.2 安装TFTP

2.2.1 安装tftp


[root@test ~]#yum -y install tftp-server xinetd

xinetd是tftp服务提供守护进程,将xinetd和tftp都设置为开机启动  


[root@test ~]#chkconfig xinetd on
[root@test ~]#chkconfig tftp on


查看tftp文件,保证:“disable=no”

[root@test ~]# vi /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}


2.2.1 启用tftp


# /etc/init.d/xinetd restart

设置开机启动xinetd

# chkconfig xinetd on


2.3 配置支持PXE的启动程序


2.3.1 安装syslinux,此服务为pxe提供pxelinux.0文件

syslinux是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX是一个小型的Linux操作系统,它的目的是简化首次安装Linux的时间,并建立修护或其它特殊用途的启动盘。

# yum  -y install syslinux


2.3.2 复制pxelinux.0 文件至/var/lib/tftpboot/ 文件夹中

# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

2.3.3 复制iso 镜像中的/p_w_picpath/pxeboot/initrd.img 和vmlinux 至/var/lib/tftpboot/ 文件夹中

# cp /var/www/html/cdrom/p_w_picpaths/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/

2.3.4 复制iso 镜像中的/isolinux/*.msg 至/var/lib/tftpboot/ 文件夹中

# cp /var/www/html/cdrom/isolinux/*.msg /var/lib/tftpboot/

2.3.5 在/var/lib/tftpboot/ 中新建一个pxelinux.cfg目录

# mkdir /var/lib/tftpboot/pxelinux.cfg

2.3.6 将iso 镜像中的/isolinux 目录中的isolinux.cfg复制到pxelinux.cfg目录中,同时更改文件名称为default

# cp /var/www/html/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default


2.3.7 修改default文件

# vim /var/lib/tftpboot/pxelinux.cfg/default
default ks
prompt 1
timeout 6
display boot.msg
#menu background splash.jpg
#menu title Welcome to CentOS 6.5!
#menu color border 0 #ffffffff #00000000
#menu color sel 7 #ffffffff #ff000000
#menu color title 0 #ffffffff #00000000
#menu color tabmsg 0 #ffffffff #00000000
#menu color unsel 0 #ffffffff #00000000
#menu color hotsel 0 #ff000000 #ffffffff
#menu color hotkey 7 #ffffffff #ff000000
#menu color scrollbar 0 #ffffffff #00000000
label linux
  kernel vmlinuz
  append initrd=initrd.img
label text
  kernel vmlinuz
  append initrd=initrd.img text
label ks
  kernel vmlinuz
  append ks=http://192.168.52.135/ks.cfg initrd=initrd.img ksdevice=em1
label local
  localboot 1
label memtest86
  kernel memtest
  append -



2.4 配置DHCP


2.4.1 安装DHCP服务

# yum -y install dhcp


2.4.2 复制配置模板文件到DHCP的配置目录中

# cp -f /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample  /etc/dhcp/dhcpd.conf

2.4.3 修改/etc/dhcp/dhcpd.conf 配置文件,内容如下:

ddns-update-style none;
filename "pxelinux.0";
next-server 192.168.52.136;
subnet 192.168.52.0 netmask 255.255.255.0 {
    option routers     192.168.52.1;
    option subnet-mask  255.255.255.0;
   range dynamic-bootp 192.168.52.200 192.168.52.222;
    default-lease-time 21600;
    max-lease-time 43200;
}


2.4.3 启动DHCP服务

#etc/init.d/dhcpd start


2.5 生成ks.cfg文件


2.5.1 安装kickstart

# yum install system-config-kickstart

2.5.2 在桌面环境下配置kickstart

# system-config-kickstart

(图形界面配置:)


①基本配置:选择默认语言、键盘、时区、root密码、安装完成后是否重启

PXE kickstart 批量部署 centOS6.5_dell_02


②选择安装方法:“执行新安装”,安装方式:HTTP。

PXE kickstart 批量部署 centOS6.5_kickstart_03


③MBR默认

PXE kickstart 批量部署 centOS6.5_kickstart_04


④设置分区:

PXE kickstart 批量部署 centOS6.5_centos_05

PXE kickstart 批量部署 centOS6.5_dell_06


PXE kickstart 批量部署 centOS6.5_centos_07


⑤配置网络

PXE kickstart 批量部署 centOS6.5_kickstart_08


⑥认证配置,(默认)

PXE kickstart 批量部署 centOS6.5_dell_09


⑦selinux、firwall配置

PXE kickstart 批量部署 centOS6.5_centos_10


⑧图形环境配置

PXE kickstart 批量部署 centOS6.5_dell_11


⑨软件包选择(Base System)

PXE kickstart 批量部署 centOS6.5_kickstart_12

PXE kickstart 批量部署 centOS6.5_kickstart_13


10保存

PXE kickstart 批量部署 centOS6.5_dell_14


PXE kickstart 批量部署 centOS6.5_kickstart_15

保存位置为:/var/www/html/ks.cfg


ks.cfg文件内容:

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.52.135/cdrom"
# Root password
rootpw --iscrypted $1$IYQM0iMq$.Y7shkTo.J9V9gWzfS4SF1
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --ondisk=sda --size=200
part swap --fstype="swap" --ondisk=sda --size=500
part / --fstype="ext4" --grow --ondisk=sda --size=1
%packages
@base
@console-internet
@debugging
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime



二、使用虚拟机批量部署


2.1 安装CentOS 6.5

在VMware安装CentOS6.5_x86_64(略)


2.2 修改centOS虚拟网卡连接方式为“桥接”模式


桥接模式虚拟网卡互联示意图:

PXE kickstart 批量部署 centOS6.5_dell_16



2.2.1 设置虚拟交接网卡

在VMware菜单栏中选择“编辑”→“虚拟网络编辑器”

PXE kickstart 批量部署 centOS6.5_dell_17


“添加网络”→“VMnet0”→“选择桥接网络适配器”

PXE kickstart 批量部署 centOS6.5_centos_18


2.2.1 设置CentOS虚拟机虚拟网卡

PXE kickstart 批量部署 centOS6.5_kickstart_19

“设置”→“网络适配器”→“桥接模式”

PXE kickstart 批量部署 centOS6.5_dell_20




2.3 修改CentOS网卡IP地址

此IP地址应该和引导的源URL和DHCP地址池一致

#vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
IPADDR=10.1.1.1
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet


2.4 进行系统安装


2.4.1 连接PC至服务器或与服务器相连的交换机

确保服务器网口与PC在同一vlan下。


2.4.2 服务器开机并选择引导方式(DELL BIOS 2.0.2)

①开机

②选择:<F11> = BIOS Boot Manager

③选择:BIOS Boot Menu

④选择:Integrated NIC 1 BRCM MBA Slot 0100 v16.2.1

PXE kickstart 批量部署 centOS6.5_centos_21


PXE kickstart 批量部署 centOS6.5_centos_22



PXE kickstart 批量部署 centOS6.5_kickstart_23



PXE kickstart 批量部署 centOS6.5_kickstart_24


等待完成安装:

PXE kickstart 批量部署 centOS6.5_dell_25



三、部署问题


3.1 需要选择网卡问题


3.1.1问题:

被安装设备出现选择网卡提示:

You have multiple network devices on this system.

Which would you like to install through?

PXE kickstart 批量部署 centOS6.5_dell_26


3.1.2解决方法:

# vi /var/lib/tftpboot/pxelinux.cfg/default
append ks=http://192.168.52.135/ks.cfg initrd=initrd.img ksdevice=em1

增加网口选项“ksdevice=em1”(DELL服务器)