架構師成長之路2.2-PXE+Kickstart安裝部署

點擊返回架構師成長之路html

架構師成長之路2.2-PXE+Kickstart安裝部署

系統測試環境:linux

  • 實驗環境:VMware Workstation 12
  • 系統平臺:CentOS Linux release 7.5.1804 (Core)
  • 網絡模式:NAT模式(共享主機的IP地址)
            DHCP / TFTP IP:192.168.80.128
            HTTP / FTP / NFS IP:192.168.80.128

 1.關閉selinux和firewalld

必定要關閉,不然安裝必定會出問題。ios

vi /etc/selinux/config    #將SELINUX=enforcing改成SELINUX=disabled 設置後須要重啓才能生效

 

firewall-cmd --state    #查看默認防火牆狀態,關閉後顯示not running,開啓後顯示running
systemctl stop firewalld.service    #臨時關閉firewall
systemctl disable firewalld.service #禁止firewall開機啓動

 2. 生成ks.cfg 文件

有使用安裝最小系統,須要此步驟。
生成ks.cfg 文件須要system-config-kickstart 工具,而此工具依賴於X Windows,因此咱們須要安裝X Windows 和Desktop 並重啓系統  。vim

yum groupinstall "X Window System"
yum groupinstall Desktop
reboot

 3. 部署DHCP

yum -y install dhcp  #安裝dhcp軟體

DHCP主要是提供客戶端網絡參數與TFTP的位置,以及boot loader的文件名。centos

同時,咱們僅針對內網來告知TFTP的相關位置,因此能夠編輯/etc/dhcp/dhcpd.conf在subnet的區塊內加入兩個參數便可。服務器

其中PXE上專門爲PXE客戶端下載的boot loader文件名稱爲pxelinux.0。網絡

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcpd.conf

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.1 192.168.0.100;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  default-lease-time 600;
  max-lease-time 7200;       
next-server 192.168.0.128; #告知客戶端TFTP服務器的iPhone地址
file.name "/pxelinux.0" #告知客戶端從TFTP根目錄下載pxelinux.0文件 } # Hosts which require special configuration options can be listed in # host statements. If no address is specified, the address will be # allocated dynamically (if possible), but the host-specific information # will still come from the host declaration. host passacaglia { hardware ethernet 0:0:c0:5d:bd:95; filename "vmunix.passacaglia"; server-name "toccata.fugue.com"; } # Fixed IP addresses can also be specified for hosts. These addresses # should not also be listed as being available for dynamic assignment. # Hosts for which fixed IP addresses have been specified can boot using # BOOTP or DHCP. Hosts for which no fixed address is specified can only # be booted with DHCP, unless there is an address range on the subnet # to which a BOOTP client is connected which has the dynamic-bootp flag # set. host fantasia { hardware ethernet 08:00:07:26:c0:a5; fixed-address fantasia.fugue.com; } # You can declare a class of clients and then do address allocation # based on that. The example below shows a case where all clients # in a certain class get addresses on the 10.17.224/24 subnet, and all # other clients get addresses on the 10.0.29/24 subnet. class "foo" { match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; } shared-network 224-29 { subnet 10.17.224.0 netmask 255.255.255.0 { option routers rtr-224.example.org; } subnet 10.0.29.0 netmask 255.255.255.0 { option routers rtr-29.example.org; } pool { allow members of "foo"; range 10.17.224.10 10.17.224.250; } pool { deny members of "foo"; range 10.0.29.10 10.0.29.230; } }  

重啓dhcp:架構

service dhcpd restart

 

4.部署TFTP

boot loader文件pxelinux.0以及內核相關的配置文件(目錄pxelinux.cfg下)主要都是由TFTP來提供的!app

TFTP的安裝很簡單,直接使用yum便可。不過要告訴客戶端TFTP的根目錄在哪裏,這樣客戶端才能找到相關文件。另外要注意,TFTP是由xinetd這個super daemon所管理的,所以設定好TFTP以後,要啓動的是xinetd。less

yum install tftp-server

yum -y install xinetd

  

默認TFTP服務的根目錄是/var/lib/tftpboot/,爲了少寫些字母,將tftp的根目錄修改成/tftpboot/。修改tftp的配置文件,主要是TFTP的根目錄。

vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot   #重點在這裏!修改tftp的根目錄
        disable                 = no     #由原來yes變成no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

mkdir /tftpboot  # 建立根目錄

systemctl start tftp      #啓動tftp
netstat -tulnp | grep xinetd  # 觀察tftp 

5. 提供pxe的bootloader和相關配置文件

若是要使用PXE的開機引導的話,須要使用CentOS提供的syslinux包,從中copy兩個文件到tftp的根目錄/tftpboot下便可。整個過程以下: 

yum -y install syslinux    
cp -a /usr/share/syslinux/{menu.c32,vesamenu.c32,pxelinux.0}  /tftpboot/
mkdir /tftpboot/pxelinux.cfg 

menu.c32      # 提供圖形化菜單功能
pxelinux.0    # boot loader文件
pxelinux.cfg  # 開機的菜單設定在這裏
vesamenu.c32  # 也是提供圖形化菜單功能,但界面和menu.c32不一樣
  • pxelinux.cfg是個目錄,能夠放置默認的開機選項,也能夠針對不一樣的客戶端主機提供不一樣的開機選項。通常來講,能夠在pxelinux.cfg目錄內創建一個名爲default的文件來提供默認選項。
  • 若是沒有menu.c32或vesamenu.c32時,菜單會以純文字模式一行一行顯示。
  • 若是使用menu.c32或vesamenu.c32時,就會有相似反白效果出現,此時可使用上下鍵來選擇選項,而不須要看着屏幕去輸入數字鍵來選擇開機選項。通過測試,使用vesamenu.c32比menu.c32更加好看些。
  • 這部分設定完畢後,就是內核相關的設定了。

6.從安裝鏡像獲取Linux內核文件

要安裝Linux系統,必須提供內核文件,這裏以64位版本的CentOS 7.5爲例。
這裏計劃將內核相關文件放在/tftpboot/centos7.5/目錄下。
既然要從安裝鏡像中獲取內核相關文件,首先得要掛載鏡像。

mkdir /test 
mount /dev/cdrom /test

 

mkdir /tftpboot/CentOS7.5
cp /test/isolinux/{vmlinuz,initrd.img} /tftpboot/CentOS7.5
cp /test/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

 

其實僅須要vmlinuz和initrd.img兩個文件便可,不過這裏還將isolinux.cfg這個文件拷貝出來了,主要這個文件裏提供了開機選項,能夠以它做爲修改開機選項和菜單的模板。

7.設置開機菜單並提供系統安裝文件

修改開機配置文件isolinux.cfg。因爲拷貝它的時候重命名爲default,因此修改default便可。

cat /tftpboot/pxelinux.cfg/default 
default vesamenu.c32   #這是必須項,或者使用menu.c32。。。。默認啓動lable vesamenu.c32中標記的啓動內核
timeout 600            #超時等待時間,60s內不曹組將自動選擇默認的菜單來加載

display boot.msg      # 顯示某個文件的內容,注意文件的路徑。默認在/var/lib/tftpboot 目錄

# 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 CentOS 7          #大標題
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 linux  #lable指定你在「boot:」提示符下輸入關鍵字 好比boot:linux[ENTER]這個會啓動「lable linux」標記下的kernel和initrd.img文件
  menu label ^Install CentOS 7   # 菜單文字
  kernel vmlinuz  #kernel參數指定要啓動的內核,注意相對路徑是從tftp的根路徑/tftpboot,因此要改爲「./CentOS7.5/vmlinux」
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet 
#append指定追加給內核的參數,其中的initrd路徑要改爲「./CentOS7.5/initrd.img」
#stage2的路徑放在ftp的路徑下,改爲inst.stage2=ftp://192.168.0.128 quiet
label check
  menu label Test this ^media & install CentOS 7
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_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 CentOS 7 in ^basic graphics mode
  text help
	Try this option out if you're having trouble installing
	CentOS 7.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a CentOS 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=CentOS\x207\x20x86_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  

主要修改:

8 從網卡安裝系統——開機測試

設置Bios從網卡啓動。
關閉客戶機——〉在VMware的界面菜單上點擊「虛擬機」——〉電源——〉打開電源時進入固件。

設置從網卡啓動。將首先搜索DHCP服務器,找到DHCP後搜索bootloader文件,啓動菜單設置文件等,而後進入啓動菜單等待選擇要啓動的項。
以下:

 如下圖示爲以前同事測試存檔記錄:

8.1 因爲到這裏他以前尚未提供Linux的安裝文件,因此選擇URL從互聯網來獲取系統安裝。

 

因爲要從互聯網上獲取系統安裝文件,因此須要設置IP等網絡參數,但要注意,這裏的網絡參數和前面設置的PXE網絡參數是無關的,這裏設置的IP僅是爲了聯上互聯網。因爲已經配置了DHCP,因此這裏選擇DHCP。

設置一個獲取Linux系統的站點。上圖設置的是163的站點。

若是沒什麼問題,到這裏就開始進行安裝直到完成了。如下是進度圖片。

 

8.2 經過http/ftp/nfs來提供系統安裝文件

 

而後就會進入安裝畫面,可是這樣仍是有些地方須要手動指定的。

沒法實現非交互時無人值守的方式安裝。

下節介紹kickstart實現無人值守的方式。

.........

相關文章
相關標籤/搜索