pxe裝機

安裝環境:

一臺已安裝Linux系統的主機作爲PXE Server, 本文中PXE Server使用的系統是CentOS 7;

若干臺待安裝CentOS7的裸主機作爲PXE Client;

PXE Server與所有PXEClient處於同一局域網中;

所有主機支持PXE啓動安裝方式。

PXEServer安裝及配置流程:

\1. 配置 DHCP 服務

\2. 配置 TFTP 服務

\3. 配置http做文件倉庫和修改ks.cfg文件

\4. 相關係統引導文件存儲

\5. 配置default系統啓動文件

\6. 檢查PXEServer的狀態並啓動PXE Client

PXEServer安裝及配置具體步驟:

1. 配置DHCP服務

安裝DHCP

# yum install -y dhcp

當前PXE Server的IP地址爲192.168.0.125,DHCP、TFTP與http均部署在該臺主機上,配置dhcp配置文件**/etc/dhcp/dhcpd.conf**如下

############################

ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;

class “pxeclients”{
match if substring(option vendor-class-identifier,0,9)=“PXEClient”;
filename “pxelinux.0”;
next-server 192.168.0.125;
}

subnet 192.168.0.0 netmask 255.255.255.0{
default-lease-time 216000;
max-lease-time 432000;
option time-offset -18000;
range dynamic-bootp 192.168.0.210 192.168.0.240;
option subnet-mask 255.255.255.0;
option routers 192.168.0.1;
}

############################

啓動並且配置開機啓動dhcpd服務

# systemctl start dhcpd

# systemctl enable dhcpd

2. 配置TFTP服務

安裝tftp的server和client包

# yum install -y tftp*

安裝xinetd守護進程,因爲tftp依賴於xinetd

# yum install -y xinetd

修改tftp配置文件/etc/xinetd.d/tftp,將disable= yes改爲disable=no

關閉並配置開機自動關閉系統防火牆(重要!否則會導致PXE Client無法訪問TFPT服務)

# systemctl stop firewalld

# systemctl disable firewalld

啓動並配置開機自動啓動xinetd進程

# systemctl start xinetd

# systemctl enable xinetd

# systemctl start tftp

3. 配置http做文件倉庫和修改ks.cfg文件

安裝httpd服務

# yum install –y httpd

啓動並且配置開機啓動httpd服務

# systemctl start httpd

# systemctl enable httpd

放入待安裝系統盤,並直接用光盤的package當做安裝倉庫

# mkdir /var/www/html/centos7

# mount /dev/cdrom /var/www/html/centos7/

將當前系統中的ks文件拷貝到/var/www/html/路徑下

# cp /root/anaconda-ks.cfg /var/www/html/ks.cfg

修改ks.cfg配置文件/var/www/html/ks.cfg

ks.cfg的作用是預先指定好需要的安裝選項(包括系統鏡像路徑,安裝組件,系統語言,網絡配置,用戶及密碼等),

當正式安裝時PXE Client將會很據該文件去自動配置安裝,從而避免了大規模部署時的大量重複操作。

主要修改的地方是將

# Use CDROM installation media

cdrom

修改爲

# Use network installation

url --url="http://192.168.0.125/centos7"

從而指定PXE Client從哪裏去獲得鏡像文件,ks.cfg文件修改後如下:

#version=DEVEL

# System authorization information

auth --enableshadow --passalgo=sha512

# Use network installation

url --url=“http://192.168.0.125/centos7”

# Use graphical install

graphical

# Run the Setup Agent on first boot

firstboot --enable

# Keyboard layouts

keyboard --vckeymap=cn --xlayouts=‘cn’

# System language

lang zh_CN.UTF-8

# Network information

network --bootproto=dhcp–device=eno16777736 --ipv6=auto --activate

network --hostname=localhost.localdomain

# Root password

rootpw --iscrypted66qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/

# System timezone

timezone Asia/Shanghai --isUtc

user --groups=wheel --name=pxetest–password=66.hgpJdCAhSMaf7yB$5GKYIAgTkLxfS1JHK5KSpN96LXhkKGFX3FbnQl0hTME3wbF1njxyezmPF/HXAtI9Bp8U6MsF3hRXlFvFfn9Nm/–iscrypted --gecos=“pxetest”

# System bootloader configuration

bootloader --append=" crashkernel=auto"–location=mbr --boot-drive=sda

autopart --type=lvm

# Partition clearing information

clearpart --none --initlabel

%packages

@^infrastructure-server-environment

@base

@compat-libraries

@core

@debugging

@development

@dns-server

@file-server

@ftp-server

@security-tools

@smart-card

kexec-tools

%end

%addon com_redhat_kdump --enable–reserve-mb=‘auto’

%end

4. 相關係統引導文件存儲

安裝syslinux,它是一個功能強大的引導加載程序,而且兼容各種介質。

# yum install -y syslinux

pxelinux.0文件名要和dhcp配置文件內的一致

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

copy光盤目錄中的vmlinuz和initrd.img,這兩個文件相當於系統啓動時/boot目錄下的啓動文件,這個用來引導anacoda而不是根

# cp /mnt/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/

copy pxe引導所需要的配置文件,splash.png:背景圖.boot.msg啓動標語,vesamenu.c32:顯示同行界面用的程序.

# cp /mnt/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.png} /var/lib/tftpboot/

pxe啓動時顯示配置文件信息,和光盤啓動類似.

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

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

5. 配置default系統啓動文件

在default配置文件/var/lib/tftpboot/pxelinux.cfg/default中找到下面標籤

label linux

menu label^Install CentOS 7

kernel vmlinuz

menu default

append initrd=initrd.img inst.stage2=http://192.168.0.125/centos7 inst.ks=http://192.168.0.125/ks.cfg quiet

注意標紅的地方,它的目的是用於告訴PXEClient去哪裏可以找到鏡像文件以及ks.cfg配置文件。

6. 檢查PXE Server的狀態並啓動PXE Client

# service dhcpd status

# service tftp status

# service httpd status

以上三者結果都應該爲active(running)

# service firewalld status

結果都應該爲inactive(dead)

檢查待安裝系統盤是否以及掛載到指定目錄下(/var/www/html/centos7/)

如果以上狀態均正常,可以開始啓動PXEClient,並將啓動方式設置爲網卡啓動。

常見問題:

1、 PXE Server每次啓動後IP地址都不相同?

答:應該講PXE Server設置爲靜態IP,否則每次重啓都需要根據新IP修改配置文件

2、 PXE Server重啓後Client端顯示連接不到TFTP服務器?

答:PXE Server每次重啓後需要重新打開tftp服務

#service tftp start

3、 PXE Server重啓後Client端顯示無法訪問到指定文件?

答:PXE Server每次重啓後需要重新mount光盤到指定路徑

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