centos7 搭建PXE服務器批量安裝centos


安裝環境:

源地址:https://blog.csdn.net/Filter_CPH/article/details/52711558

 

一台已安裝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 --iscrypted$6$qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/

# System timezone

timezone Asia/Shanghai --isUtc

user --groups=wheel --name=pxetest--password=$6$.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光盤到指定路徑

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM