RHEL6 (64bits)系統上利用PXE+DHCP+TFTP+KickStart批量安裝系統

 由於考慮到公司以後會批量進行部署服務器,所以想去架構一個基於PXE的快速、批量安裝系統的架構服務,後來在網絡上搜索了一遍,但都是關於RHEL5的配置文檔,但是其配置和在RHEL6上有很大的出入,所以決定自己摸索着把相關配置過程進行一遍,先把其配置過程發佈出來,以供自己和各位linux愛好者查看、使用!其中寫的不對的地方,還望各位大神指出~~謝謝!

一、PXE的介紹

PXE當初是作爲Intel的有線管理體系的一部分,Intel 和 Systemsoft於1999年9月20日公佈其規格(版本2.1)。通過使用像網際協議(IP)、用戶數據報協議(UDP)、動態主機設定協定(DHCP)、小型文件傳輸協議(TFTP)等幾種網絡協議和全局唯一標識符(GUID)、通用網絡驅動接口(UNDI)、通用唯一識別碼(UUID)的概念並通過對客戶機(通過PXE自檢的電腦)固件擴展預設的API來實現目的。

   PXE 客戶機(client)這個術語是指機器在PXE啓動過程中的角色。一個PXE 客戶機(client)可以是一臺服務器、桌面級電腦、筆記本電腦或者其他裝有PXE啓動代碼的機器。

二、PXE的工作過程

   1.客戶機從自己的PXE網卡啓動,向本網絡中的DHCP服務器索取IP

   2.DHCP服務器返回分給客戶機IP以及bootstrap文件的放置位置(該文件一般是放在一臺TFTP服務器上)

   3.客戶機向本網絡中的TFTP服務器索取bootstrap文件

   4.客戶機取得bootstrap文件後之執行該文件

   5.根據bootstrap的執行結果,通過TFTP服務器加載內核和文件系統

   6.進入安裝畫面, 此時可以通過選擇FTP,HTTP,NFS方式之一進行安裝 從這裏我們不難得到實現PXE網絡安裝必需的4個要素

   1.客戶機的網卡必須爲PXE網卡

   2.網絡中必須要有DHCP和TFTP服務器,當然這兩個服務器可以是同一臺物理主機

   3.所安裝的操作系統必須支持網絡安裝,即必須提供自己的bootstrap

   4.必須要有FTP,HTTP,NFS至少一個服務器,當然也可以和DHCP和TFTP服務器同爲一臺物理主機

三、RHEL6-64bits基於PXE的實例實現

20130603093949313.png

1、配置相關環境,這裏使用yum安裝,把本地的磁盤做成yum源

    本機IP設置

DEVICE="eth0"
BOOTPROTO="static"
IPADDR="192.168.7.1"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"


service network restart   #重啓網絡服務,使配置的IP地址生效!www.it165.net

yum配置

[root@localhost ~]# vim /etc/yum.repos.d/server.repo 增加yum配置文件,添加如下內容: 
[base] 
name=base 
baseurl=file:///media/Server 
gpgcheck=0
enabled=1
[HighAvailability] 
name=HighAvailability 
baseurl=file:///media/HighAvailability 
gpgcheck=0
enabled=1
[LoadBalancer] 
name=LoadBalancer 
baseurl=file:///media/LoadBalancer 
gpgcheck=0
enabled=1
[ResilientStorage] 
name=ResilientStorage 
baseurl=file:///media/ResilientStorage 
gpgcheck=0
enabled=1
[ScalableFileSystem] 
name=ScalableFileSystem 
baseurl=file:///media/ScalableFileSystem 
gpgcheck=0
enabled=1
掛載光盤到指定的掛載點 
[root@localhost ~]# mount /dev/cdrom /media

2、安裝所需的軟件包

[root@localhost ~]#  yum -y install dhcp tftp-server nfs-utils syslinux vsftpd

3、配置dhcpd服務器

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf  添加如下內容 
default-lease-time 600; 
max-lease-time 7200; 
allow booting; 
allow bootp; 
authoritative; 
subnet 192.168.7.0 netmask 255.255.255.0 { 
        range 192.168.7.80 192.168.7.90; 
        next-server 192.168.7.1;  #tftp服務器 
        filename "pxelinux.0";    #PXE客戶端訪問時候的文件 
} 
[root@localhost ~]# service dhcpd start #啓動HDCP服務

4、配置tftp服務,此處使用xinetd超級進程來管理tftp服務

[root@localhost ~]# vim /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 #只需把此處修改爲no即可 
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4 
} 
[root@localhost ~]#  service xinetd restart #重啓服務,使其配置生效

5、設置tftp服務,並設置安裝系統的磁盤掛載目錄

[root@localhost ~]# vim /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 #只需把此處修改爲no即可 
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4 
} 
[root@localhost ~]#  service xinetd restart #重啓服務,使其配置生效

提供kickstart文件

20130603093949734.png

提供ks.cfg文件

[root@localhost tftpboot]# cp /root/anaconda-ks.cfg /var/ftp/pub/ks.cfg

這是使用的本機的anaconda-ks.cfg文件,當然,如果我們需要自己定製,可用安裝yum install system-config-kickstart軟件包,然後利用命令system-config-kickstart啓動一個gui界面進行相關的配置生成kickstart配置文件,這裏使用本機的kickstart文件進行測試了~

   其配置文件詳細命令如下

# Firewall configuration 
firewall --enabled --ssh 
# Install OS instead of upgrade 
install 
# Use network installation 
url --url="ftp://192.168.7.1/pub/rhel6"
# Root password 
rootpw --iscrypted $6$bgA6iounYImIucBq$8xtCdixNgcLPBsLOrFmtmrfPezUd.DAgDPBJDYzKYCegvj2oxUF3UGRWWXPaEitnPyckBInZ.RJXG4Vj.uTZd1 
# System authorization information 
auth  --useshadow  --passalgo=sha512 
# System keyboard 
keyboard us 
# System language 
lang en_US 
# SELinux configuration 
selinux --disabled 
# Do not configure the X Window System 
skipx 
# Installation logging level 
logging --level=info 
# Reboot after installation 
reboot 
# System timezone 
timezone --isUtc 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 --asprimary --fstype="ext4" --size=256
part swap --asprimary --fstype="swap" --size=2048
part / --asprimary --fstype="ext4" --size=10000
part /data --asprimary --fstype="ext4" --size=20000
%packages 
@base 
@chinese-support 
%end

注意:需要給其文件增加權限:

   chmod 644 /var/ftp/pub/ks.cfg

   然後複製PXE的cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/目錄下,到處我們的配置已經完成!重啓相關服務即可:

service vsftpd restart 
service dhcpd restart 
service xinetd restart

6、新建一個虛擬機,讓其使用PXE進行安裝系統,測試如下

20130603093950191.png

20130603093950951.png

20130603093950951.png

20130603093951549.png

20130603093952557.png

 

   在我們部署的時候還有基於http、nfs等方式的架構,其大致內容都是相似的,只是在指定kickstart的配置文件的時候不同而已~

   最後把一鍵配置所用功能的腳本分享給大家~只需在PXE和kickstart服務器上執行以下這個腳本,就可以自動完成上面的所有配置,具體如下:

#!/bin/bash 
#NAME:pxeinstallos.rhel6.1.sh 
#DESCRIPTION:NULL 
#AUTHOR:Beck 
#VERSION:0.0.1
#DATATIME:2013-05-17 18:24:37
#USAGE:pxeinstallos.rhel6.1.sh 
pxeip="192.168.2.30"
vsftpip="192.168.2.30"
dhcpip="192.168.2.30"
subnetip="192.168.2"
rangeip="192.168.2.50 192.168.2.60"
#準備工作需將rhel6的安裝光盤放進光驅 
mount /dev/cdrom /media 
cat > /etc/yum.repos.d/localcdrom.repo << EOF 
[base] 
name=base 
baseurl=file:///media/Server 
gpgcheck=0
enabled=1
[HighAvailability] 
name=HighAvailability 
baseurl=file:///media/HighAvailability 
gpgcheck=0
enabled=1
[LoadBalancer] 
name=LoadBalancer 
baseurl=file:///media/LoadBalancer 
gpgcheck=0
enabled=1
[ResilientStorage] 
name=ResilientStorage 
baseurl=file:///media/ResilientStorage 
gpgcheck=0
enabled=1
[ScalableFileSystem] 
name=ScalableFileSystem 
baseurl=file:///media/ScalableFileSystem 
gpgcheck=0
enabled=1
EOF 
yum clean all && yum repolist 
yum -y install dhcp tftp-server syslinux vsftpd system-config-kickstart.noarch 
func_tftp() { 
sed -i "s@disable.*@disable                 = no@" /etc/xinetd.d/tftp 
cp -a /media/isolinux/* /var/lib/tftpboot 
mkdir /var/lib/tftpboot/pxelinux.cfg 
#cp -a /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
#vim /var/lib/tftpboot/pxelinux.cfg/default
cat > /var/lib/tftpboot/pxelinux.cfg/default << EOF 
default vesamenu.c32 
#prompt 1
timeout 5
display boot.msg 
menu background splash.jpg 
menu title Welcome to Red Hat Enterprise <a href="http://www.it165.net/os/oslin/" target="_blank" class="keylink">Linux</a> 6.4! 
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 
  menu label ^Install or upgrade an existing system 
  menu default
  kernel vmlinuz 
  append initrd=initrd.img ks=ftp://$pxeip/ks.cfg 
label vesa 
  menu label Install system with ^basic video driver 
  kernel vmlinuz 
  append initrd=initrd.img xdriver=vesa nomodeset 
label rescue 
  menu label ^Rescue installed system 
  kernel vmlinuz 
  append initrd=initrd.img rescue 
label local 
  menu label Boot from ^local drive 
  localboot 0xffff
label memtest86 
  menu label ^Memory test 
  kernel memtest 
  append - 
EOF 
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot 
service xinetd restart 
} 
func_dhcp() { 
mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak 
cat > /etc/dhcp/dhcpd.conf <<EOF 
ddns-update-style interim; 
ignore client-updates; 
next-server $pxeip; 
filename "pxelinux.0"; 
subnet $subnetip.0 netmask 255.255.255.0 { 
        option routers  $pxeip; 
        option subnet-mask  255.255.255.0; 
        option nis-domain   "beckli.com"; 
        option domain-name  "beckli.com"; 
        option domain-name-servers  $pxeip; 
        option ntp-servers  $pxeip; 
                option time-offset  -18000; # Eastern Standard Time 
        allow bootp; 
        allow booting; 
                range dynamic-bootp $rangeip; 
                default-lease-time 21600; 
                max-lease-time 43200; 
} 
EOF 
service dhcpd restart 
} 
func_vsftp() { 
service vsftp restart 
umount /media 
mkdir /var/ftp/rhel6 
mount /dev/cdrom /var/ftp/rhel6 
cat > /var/ftp/ks.cfg <<EOF 
#platform=x86, AMD64, or Intel EM64T 
#version=DEVEL 
# Firewall configuration 
firewall --enabled --ssh 
# Install OS instead of upgrade 
install 
# Use network installation 
url --url="ftp://$pxeip/rhel6"
# Root password 
rootpw --iscrypted $6$bgA6iounYImIucBq$8xtCdixNgcLPBsLOrFmtmrfPezUd.DAgDPBJDYzKYCegvj2oxUF3UGRWWXPaEitnPyckBInZ.RJXG4Vj.uTZd1 
# System authorization information 
auth  --useshadow  --passalgo=sha512 
# System keyboard 
keyboard us 
# System language 
lang en_US 
# SE<a href="http://www.it165.net/os/oslin/" target="_blank" class="keylink">Linux</a> configuration 
selinux --disabled 
# Do not configure the X Window System 
skipx 
# Installation logging level 
logging --level=info 
# Reboot after installation 
reboot 
# System timezone 
timezone --isUtc 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 --asprimary --fstype="ext4" --size=256
part swap --asprimary --fstype="swap" --size=2048
part / --asprimary --fstype="ext4" --size=10000
part /data --asprimary --fstype="ext4" --size=20000
                              
%packages 
@base 
@chinese-support 
                              
%end 
EOF 
} 
func_tftp 
func_vsftp 
func_dhcp

源地址:http://www.it165.net/os/html/201306/5331.html#comment_iframe

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章