Kickstart实现CentOS 6.3的网络自动安装

什么是KickStart

KickStart是一种无人职守安装方式。KickStart的工作原理是通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个名为ks.cfg的文件;在其后的安装过程中(不只局限于生成KickStart安装文件的机器)当出现要求填写参数的情况时,安装程序会首先去查找KickStart生成的文件,当找到合适的参数时,就采用找到的参数,当没有找到合适的参数时,才需要安装者手工干预。这样,如果KickStart文件涵盖了安装过程中出现的所有需要填写的参数时,安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中设置的重启选项来重启系统,并结束安装。

PXE + KickStart安装的条件

执行 PXE + KickStart安装需要的设备为:

1.DHCP 服务器

2.TFTP 服务器

3.KickStart所生成的ks.cfg配置文件

4.一台存放系统安装文件的服务器,如 NFSHTTP  FTP 服务器

5.带有一个 PXE 支持网卡的将安装的主机

本文环境介绍:

pxe 源服务器: 192.168.52.139

client 服务器网卡和 pxe 服务器的网卡接在一个交换机上

操作系统 Centos-6.3 -x86_64-bin-DVD1.iso 

CentOS6 ksCentOS5 有点区别,但是不大,详情见本文

一、安装相应的软件包

yum -y install dhcp* httpd* tftp* syslinux*

挂载CentOS6.3DVD光盘,并复制第一张光盘下的所有内容(文件和文件夹)/var/www/html(apache默认网站根目录)

mount /dev/cdrom  /mnt/

cp -rf /mnt/* /var/www/html/

二、配置apache

vim /etc/httpd/conf/httpd.conf

查找deny字段改为:

allow from all

service httpd restart

正在启动 httpdhttpd: apr_sockaddr_info_get() failed for os6

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

vim /etc/httpd/conf/httpd.conf

加一句ServerName 127.0.0.1 即可 

三、配置tftp

vim /etc/xinetd.d/tftp

修改14disable = no

/etc/init.d/xinetd start

四、配置dhcp

vim /etc/dhcp/dhcpd.conf

ddns-update-style interim;

ignore client-updates;

next-server 192.168.52.139;     #PXE服务器IP地址

filename "/pxelinux.0";         #注意此行的位置,写在subnet下面的话会失败                                                                          

subnet 192.168.52.0 netmask 255.255.255.0 {

 

# --- default gateway

           option routers                    192.168.52.254;

           option subnet-mask                255.255.255.0;

 

           option nis-domain                 "example.com";

           option domain-name                "example.com";

           option domain-name-servers        192.168.52.254;

      

           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;

 

           range dynamic-bootp 192.168.52.200 192.168.52.254;

           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.110;

           #}

}

service dhcp start

五、配置支持PXE启动

我已经把第一张光盘的内容复制到/var/www/html目录中了,所以所需要的文件我只需要从/var/www/html目录中复制就行了

1、进入tftpboot文件夹,没有就建一个,有了就不用建了。

cd /var/lib/tftpboot/

2、把pxelinux.0复制到/tftpboot/

cd  /usr/share/syslinux (注:这个目录与redhat5不同。)

cp pxelinux.0 /var/lib/tftpboot

cp vesamenu.c32 /var/lib/tftpboot

3、把Linux第一张安装光盘上/p_w_picpaths/pxeboot/initrd.imgvmlinux复制到/tftpboot/

cp /var/www/html/p_w_picpaths/pxeboot/initrd.img   /var/lib/tftpboot

cp /var/www/html/p_w_picpaths/pxeboot/vmlinux   /var/lib/tftpboot

4、 复制第一张安装光盘上的isolinux/*.msg/tftpboot/

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

5、 在tftpboot中新建一个pxelinux.cfg目录

mkdir pxelinux.cfg 

6、 把Linux第一张安装光盘上isolinux目录中的isolinux.cfg复制到pxelinux.cfg目录中,并同时更改文件名称为default

cd pxelinux.cfg

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

vim /var/lib/tftpboot/pxelinux.cfg/default

timeout 600 改成合理的时间,我这里改为timeout 3

然后把22行注释掉,在下面添加:

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

 

六、修改/var/www/html/ks.cfg文件,指定读取ks.cfg的方法

# Kickstart file automatically generated by anaconda.

install

url --url="http://192.168.52.139/"

lang en_US.UTF-8

keyboard us

#network --device eth0 --bootproto dhcp

network --onboot yes --device eth0 --bootproto dhcp --noipv6

#network --device=eth0 --bootproto static --ip 192.168.217.136 --netmask 255.255.255.0 --gateway 192.168.217.130 --nameserver 8.8.8.8 --onboot=on --hostname test-01

rootpw 123456

firewall --disabled

authconfig --enableshadow --enablemd5

selinux --disabled

timezone Asia/Shanghai

zerombr

bootloader --location=mbr --driveorder=sda --append="crashkernel=auto 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 --initlabel

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

part / --fstype ext3 --size=10000

part swap --size=2048

part /home --fstype ext3 --size=100 --grow

reboot

skipx

%packages

@additional-devel

@base

@chinese-support

@core

@development

@server-policy

pcre-devel

libcap-devel

libXinerama-devel

xorg-x11-proto-devel

perl-Test-Pod

startup-notification-devel

libgnomeui-devel

libbonobo-devel

perl-Test-Pod-Coverage

libXau-devel

libgcrypt-devel

popt-devel

libXrandr-devel

libxslt-devel

e2fsprogs-devel

libglade2-devel

gnutls-devel

fuse-devel

sgpio

mtools

expect

cmake

imake

-java-1.6.0-openjdk-devel

-mysql-devel

%end

%post

# Disable service

#!/bin/bash

for i in `chkconfig --list | awk '{print $1}'`

do

          chkconfig --level 3 $i off

done

chkconfig --level 3 atd on

chkconfig --level 3 crond on

chkconfig --level 3 irqbalance on

chkconfig --level 3 microcode_ctl on

chkconfig --level 3 network on

chkconfig --level 3 sshd on

chkconfig --level 3 rsyslog on

chkconfig --level 3 udev-post on

chkconfig --level 3 NetworkManager on

chkconfig --level 3 postfix on

七、设置服务开机自启动:

chkconfig httpd on

chkconfig xinetd on

chkconfig dhcpd on

最后,启动客户机设置pxe 启动(bios 自己设置)重新引导安装就可以了。以上是我的配置步骤,如果没有出入的话,是一定可以成功的!