Kickstart+PXE+DHCP+TFTP+NFS自动安装Centos5

http://5ydycm.blog.51cto.com/115934/344097

 

 

 

网络拓扑:
Kickstart+PXE+DHCP+TFTP+NFS自动安装Centos5

说明:
服务端: Kickstart server
Os:centos5
Software:dhcp,tftp,nfs
Ip:10.10.10.2/255.255.255.0
Gw:none
 
客户端:
只需要支持 pxe 启动既可
 
安装 DHCP TFTP NFS
(1)( CentOS-5.2-x86_64-bin-DVD.iso 的光盘镜像挂载到 /media/CentOS 目录下,命令如: mount 镜像目录 /CentOS-5.2-x86_64-bin-DVD.iso /media/CentOS -o loop )
mount CentOS-5.2-i386-bin-DVD.iso /media/CentOS -o loop
(2) 禁用 /etc/yum.repo.d/CentOS-Base.repo 中的源,激活 /etc/yum.repo.d/CentOS-Media.repo 中的安装源(即禁用联网源,改为使用光盘镜像作为源)。)
yum --disablerepo=\* --enablerepo=c5-media -y install dhcp* nfs* tftp*
(3) 禁用防火墙和 SELINUX
Service iptables stop
SELINUX=disabled
 
配置 DHCP
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 10.10.10.0 netmask 255.255.255.0 {
 
option routers 10.10.10.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 10.10.10.2;
option time-offset -18000;
range dynamic-bootp 10.10.10.100 10.10.10.150;
default-lease-time 21600;
max-lease-time 43200;
# Group the PXE bootable hosts together
# PXE-specific configuration directives...
next-server 10.10.10.2;
filename "/pxelinux.0";
}
配置完成之后,重启 DHCP 服务: service dhcpd restart
DHCP 服务设为开机自动启动: chkconfig dhcpd on
 
配置 TFTP
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -u nobody -s /tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
   配置完成之后,重启 xinet 服务: service xinetd restart
xinetd 设置为开机自动启动: chkconfig xinetd on
 
配置 NFS
echo "/tftpboot *(ro,sync)" >> /etc/exports 
echo "/media/CentOS *(ro,sync)" >> /etc/exports   # 此二步设置共享的目录
exportfs -a   # 使配置生效
/etc/init.d/portmap start  &&/etc/init.d/nfs start    # 重启服务
chkconfig nfs on
showmount –e localhost  # 看查共享的目录
Export list for localhost:
/tftpboot     *
/media/CentOS *
 
配置 pxe 所需要的文件
mkdir /tftpboot/pxelinux.cfg
cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
cp /media/CentOS/isolinux/vmlinuz /tftpboot/
cp /media/CentOS/isolinux/initrd.img /tftpboot/
cp /media/CentOS/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
修改:/tftpboot/pxelinux.cfg/default 内容为:
[root@kickstart tftpboot]# more /tftpboot/pxelinux.cfg/default
default ks
label ks
  kernel vmlinuz
  append initrd=initrd.img ksdevice=eth0 ks=nfs:10.10.10.1:/tftpboot/ks.cfg
 
注: ksdevice=eth0 这一句可以指定由哪一个网卡安装,对于多网卡的机器用。
 
创建/tftpboot/ks.cfg 文件
# Kickstart file automatically generated by anaconda.
 
install
nfs --server=10.10.10.2 --dir=/media/CentOS
lang en_US.UTF-8
keyboard us
network --device eth0 --bootproto dhcp --hostname kickstart
rootpw --iscrypted $1$kE50pGl1$imqt12NcqN6KiJGToKNZo0
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --enforcing
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda
# 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 swap --size=1024
part / --fstype ext3 --size=1 --grow
 
%packages
@development-libs
@core
@base
@development-tools
device-mapper-multipath
imake
 
客户端安装
将客户端设定为从网络启动,启动后将会进入自动安装系统界面。
 
 
注,如果需要自动化安装多种定制系统,可以定制多种 ks.cfg, 那么需要做些稍微的调整,首先:
(1)[root@kickstart tftpboot]# more pxelinux.cfg/default
default ks
prompt 1
timeout 60
display boot.msg  <=cp /media/CentOS/isolinux/boot.msg /tftpboot/
label ks
  kernel vmlinuz
  append initrd=initrd.img ksdevice=eth0 ks=nfs:10.10.10.1:/tftpboot/ks.cfg<= 针对多网卡
label ks1
  kernel vmlinuz
  append initrd=initrd.img ks=nfs:10.10.10.1:/tftpboot/ks1.cfg  <- 针对单网卡
 
(2)boot.msg
^L
^Xsplash.lss
  -  To install first mode, press the <ENTER>   key or type: ks <ENTER> .
 
  -  To install second mode, type: ks1 <ENTER> .
 

Welcome to use kickstart! By-zhuzhengjun

(3)
tftpboot 目录下创建多个 ks.cfg 文件

 

 

 

 

 

====================== 图文笔记pxe引导安装centos6.2

 

 

 

环境介绍
pxe 源服务器: 192.168.30.105
client 服务器: 网卡和 pxe 服务器的网卡接在一个交换机上

[server]

1.安装相应的软件包

yum –y install dhcp* nfs* tftp*

2.配置tftp

vi /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -u nobody -s /tftpboot #设置tftp 根目录
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}

service xinetd restart
检查tftp启动状况
chkconfig --list |grep tftp
tftp: on

3.配置dhcp
vi /etc/dhcp/dhcpd.conf

ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.30.0 netmask 255.255.255.0 {
option routers 192.168.30.105;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.30.105;
option time-offset -18000;
range dynamic-bootp 192.168.30.200 192.168.30.253;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.30.105;
filename "pxelinux.0"; #--关键.让客户端获取ip后读取 tftp根目录下的文件
}

vi /etc/sysconfig/dhcpd
DHCPDARGS=eth1 (这个网卡是我的192.168.30.0 段的网卡)
service dhcpd start

4. iso 文件准备

mkdir /mnt
mkdir -p /tftpboot/pxelinux.cfg
mount /iso/CentOS-6.2-x86_64-bin-DVD1.iso /mnt -o loop
cp /mnt/isolinux/vmlinuz /tftpboot/
cp /mnt/isolinux/initrd.img /tftpboot/
cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
yum -y install syslinux-devel syslinux-tftpboot syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot/

注意:
/tftpboot 目录下是pxe 引导需要的所有东东,也就 4个东东
/mnt 是挂载安装光盘的所有东西,是client端安装时需要的安装文件

整个过程就是:
1.client 通过 tftpboot 下面的东西成功pxe启动,进入安装界面
2. 选择安装文件的路径,进行安装

5.配置nfs
vi /etc/exports

/tftpboot *(ro,sync)
/mnt *(ro,sync)

yum -y install portreserve (这个是替代以前所谓的portmap ; 6.2是叫portreserve)

service nfs start ---启动
service portreserve start

6.客户机器网卡和pxe 源服务器的网卡,要接在一个交换机上面

启动客户机, 设置pxe 启动(bios 自己设置)

就完成pxe引导了,单这刚开始,点击install

进到安装界面了,大功告成

 

 

 

 

 

 

你可能感兴趣的:(centos)