歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Kickstart 全自動安裝部署RHEL 7.0

Kickstart 全自動安裝部署RHEL 7.0

日期:2017/2/28 13:57:42   编辑:Linux教程

一、簡介

1.1 什麼是PXE

PXE(Pre-boot Execution Environment,預啟動執行環境)是由Intel公司開發的最新技術,工作於Client/Server的網絡模式,支持工作站通過網絡從遠端服務器下載映像,並由此支持通過網絡啟動操作系統,在啟動過程中,終端要求服務器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)協議下載一個啟動軟件包到本機內存中執行,由這個啟動軟件包完成終端基本軟件設置,從而引導預先安裝在服務器中的終端操作系統。

嚴格來說,PXE 並不是一種安裝方式,而是一種引導方式。進行 PXE 安裝的必要條件是在要安裝的計算機中必須包含一個 PXE 支持的網卡(NIC),即網卡中必須要有 PXE Client。PXE 協議可以使計算機通過網絡啟動。此協議分為 Client端和 Server 端,而PXE Client則在網卡的 ROM 中。當計算機引導時,BIOS 把 PXE Client 調入內存中執行,然後由 PXE Client 將放置在遠端的文件通過網絡下載到本地運行。運行 PXE 協議需要設置 DHCP 服務器和 TFTP 服務器。DHCP 服務器會給 PXE Client(將要安裝系統的主機)分配一個 IP 地址,由於是給 PXE Client 分配 IP 地址,所以在配置 DHCP 服務器時需要增加相應的 PXE 設置。此外,在 PXE Client 的 ROM 中,已經存在了 TFTP Client,那麼它就可以通過 TFTP 協議到 TFTP Server 上下載所需的文件了。

PXE的工作過程:

1. PXE Client 從自己的PXE網卡啟動,向本網絡中的DHCP服務器索取IP;

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

3. PXE Client 向本網絡中的TFTP服務器索取pxelinux.0 文件;

4. PXE Client 取得pxelinux.0 文件後之執行該文件;

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

6. 進入安裝畫面, 此時可以通過選擇HTTP、FTP、NFS 方式之一進行安裝;

詳細工作流程,請參考下面這幅圖:

1.2 什麼是Kickstart

Kickstart是一種無人值守的安裝方式。它的工作原理是在安裝過程中記錄典型的需要人工干預填寫的各種參數,並生成一個名為ks.cfg的文件。如果在安裝過程中(不只局限於生成Kickstart安裝文件的機器)出現要填寫參數的情況,安裝程序首先會去查找Kickstart生成的文件,如果找到合適的參數,就采用所找到的參數;如果沒有找到合適的參數,便需要安裝者手工干預了。所以,如果Kickstart文件涵蓋了安裝過程中可能出現的所有需要填寫的參數,那麼安裝者完全可以只告訴安裝程序從何處取ks.cfg文件,然後就去忙自己的事情。等安裝完畢,安裝程序會根據ks.cfg中的設置重啟系統,並結束安裝。

PXE+Kickstart 無人值守安裝操作系統完整過程如下:

-----------------------------------分割線--------------------------------------------------

系統環境

實驗環境:VMware Workstation 11

系統平台:RHEL7

網絡模式:LAN區段

DHCP / TFTP IP:192.168.153.130

HTTP / FTP / NFS IP:192.168.153.130

防火牆已關閉/iptables: Firewall is not running.

SELINUX=disabled

-----------------------------------分割線--------------------------------------------------

前期准備

所需要用到的服務:DHCP、TFTP、VSFTP

配置yum倉庫,掛載光盤鏡像

#vim /etc/yum.repos.d/rhel7.repo

[rhel7]

name=rhel7

basurel=file:///mnt

enabled=1

gpgcheck=0

將光盤掛載到/mnt中

#mount /dev/cdrom /mnt

-----------------------------------分割線--------------------------------------------------

配置DHCP

安裝DHCP服務

# yum -y install dhcp

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

subnet 192.168.153.0 netmask 255.255.255.0 { #所屬網段及掩碼;

range 192.168.153.100 192.168.153.120; #IP地址池范圍;

option domain-name "linuxidc.seagate.com";

option routers 192.168.153.130; #路由器IP,可以寫網關IP;

option broadcast-address 192.168.153.255;

next-server 192.168.153.130; #TFTP Server 的IP地址;

filename "pxelinux.0"; #pxelinux 啟動文件位置;

default-lease-time 600;

max-lease-time 7200;

}

啟動DHCP服務

#systemctl enable dhcpd.service

#systemctl start dhcpd.service

-----------------------------------分割線--------------------------------------------------

配置TFTP

安裝TFTP

# yum install tftp-server –y //此步驟會安裝兩個包,一個是tftp-server另一個是xinetd。

修改/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

}

啟動xinetd服務

#systemctl enable xinetd.service

#systemctl start xinetd.service

-----------------------------------分割線--------------------------------------------------

配置vsftp

安裝vsftp

#yum -y install vsftpd

啟動vsftpd服務

#systemctl start vsftpd.service

#systemctl enable vsftpd.service

創建iso文件夾目錄,用來存放光盤軟件包

#mkdir /var/ftp/iso

拷貝光盤中所有文件到iso文件夾中

#cp -rf /mnt/* /var/ftp/iso/

-----------------------------------分割線--------------------------------------------------

配置PXE啟動所需要的文件

#yum -y install syslinux

說明:syslinux是一個功能強大的引導加載程序,而且兼容各種介質。更加確切地說:SYSLINUX是一個小型的Linux操作系統,它的目的是簡化首次安裝Linux的時間,並建立修護或其它特殊用途的啟動盤。

拷貝啟動文件到/var/lib/tftpboot裡

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

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

#cd /mnt/isolinux/

#cp -rf initrd.img vmlinuz vesamenu.c32 boot.msg /var/lib/tftpboot/

#cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

檢查

[root@localhost tftpboot]# pwd
/var/lib/tftpboot
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 pxelinux.cfg vesamenu.c32 vmlinuz boot.msg

[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# ls
default

-----------------------------------分割線--------------------------------------------------

生成ks.cfg 文件

ks.cfg是kickstart安裝配置文件,系統就是按照ks.cfg來安裝的。我們將在後面配置他

安裝Kickstart

#yum -y install system-config-kickstart

在桌面環境下配置Kickstart

啟動X Windows 環境

#startx

配置Kickstart

#system-config-kickstart

後面幾項不用管,直接保存

保存在/root/下,後綴不要動

root目錄下有個anaconda-ks.cfg文件,我們進去把安裝軟件腳本拷貝到咱們剛才創建的那個ks.cfg中

#vim /root/anaconda-ks.cfg

........

%packages

@base

@core

@desktop-debugging

@dial-up

@fonts

@gnome-desktop

@guest-agents

@guest-desktop-agents

@input-methods

@internet-browser

@kde-desktop

@multimedia

@print-client

@x11

%end

把anaconda-ks.cfg文件最下方的腳本粘貼到咱們的ks.cfg中

#vim /root/ks.cfg

把上面一串@的所有內容都粘貼進去,包括兩個%哪行。

把ks文件拷貝到/var/ftp/裡面

#cp /root/ks.cfg /var/ftp/

編輯/var/lib/tftpboot/pxelinux.cfg/default文件

添加一個引導選項,最後一行指向ftp應答文件的網絡路徑

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

spacer.gif

wKiom1XlULnRuv0WAACt6ljDh2I570.jpg

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

-----------------------------------分割線--------------------------------------------------

檢查

檢查SELinux是否關閉

#setenforce 0 //關閉SELinux

檢查防火牆,開放dhcp,ftp,tftp服務,或者關閉防火牆

#firewall-cmd --permanent --add-service=dhcp

#firewall-cmd --permanent --add-service=ftp

#firewall-cmd --permanent --add-port=69/udp

#firewall-cmd --reload

返回結果都是“success”

注:這裡也可以通過systemctl stop firewall來關閉防火牆

檢查所有服務是否正常啟動

#systemctl is-active dhcpd

#systemctl is-active vsftpd

返回結果都是“active”

#netstat -tulnp | grep :69

udp 0 0 0.0.0.0:69 0.0.0.0:*

3912/xinetd

spacer.gif

-----------------------------------分割線--------------------------------------------------

default文件

[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 600

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Red Hat Enterprise Linux 7.0
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label rhel //標紅的部分是咱們添加的部分
menu label ^Install RHEL7.0
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=ftp://192.168.153.130/iso inst.ks=ftp://192.168.153.130/ks.cfg quiet

label linux
menu label ^Install Red Hat Enterprise Linux 7.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 quiet

label check
menu label Test this ^media & install Red Hat Enterprise Linux 7.0
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshooting

label vesa
menu indent count 5
menu label Install Red Hat Enterprise Linux 7.0 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
Red Hat Enterprise Linux 7.0.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 xdriver=vesa nomodeset quiet

label rescue
menu indent count 5
menu label ^Rescue a Red Hat Enterprise Linux system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rescue quiet

label memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system's memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtest

menu separator # insert an empty line

label local
menu label Boot from ^local drive
localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
menu label Return to ^main menu
menu exit

menu end

-----------------------------------分割線--------------------------------------------------

ks.cfg文件

[root@localhost ~]# cat /var/ftp/ks.cfg

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$J36yI8p5$UCVRjlL947gD1e5zZR9uR/
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url="ftp://192.168.153.130/iso"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --asprimary --fstype="ext4" --size=10240

%packages //這裡及以後的內容是從/root/anaconda-ks.cfg復制過來的
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@kde-desktop
@multimedia
@print-client
@x11

%end

-----------------------------------分割線--------------------------------------------------

安裝測試

最後測試結果在附件中,壓縮包中是測試視頻,大小為1M多。還有兩個文件,分別是default文件和ks文件,大家可以自行下載並實驗。

最後實驗測試效果視頻 與 default和ks文件下載

百度雲網盤下載:http://pan.baidu.com/s/1sjzJF5b

------------------------------------------分割線------------------------------------------

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /2015年資料/9月/20日/Kickstart 全自動安裝部署RHEL 7.0/

下載方法見 http://www.linuxidc.com/Linux/2013-07/87684.htm

------------------------------------------分割線------------------------------------------

Linux 基礎教程:Linux Kickstart 自動安裝 http://www.linuxidc.com/Linux/2015-05/117877.htm

使用PXE+DHCP+Apache+Kickstart無人值守安裝CentOS5.8 x86_64 http://www.linuxidc.com/Linux/2012-12/76913p4.htm

Linux PXE無人值守安裝出現 PXE-E32:TFTP OPen timeout的解決辦法 http://www.linuxidc.com/Linux/2014-03/98986.htm

使用PXE結合kickstart 自動安裝Linux系統 http://www.linuxidc.com/Linux/2014-03/98014.htm

RHCE認證之無人值守安裝Linux系統(FTP+TFTP+DHCP+Kickstart+PXE) http://www.linuxidc.com/Linux/2013-10/91013.htm

PXE網絡裝機(有人值守與無人值守安裝) http://www.linuxidc.com/Linux/2013-07/87456.htm

更多RedHat相關信息見RedHat 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=10

Copyright © Linux教程網 All Rights Reserved