1替蔬、PXE環(huán)境安裝所需要用到的軟件:dhcpd秧倾、tftp-server镀钓、http(ftp)、syslinux
2祭务、PXE 執(zhí)行流程:
(1) 設(shè)置擁有pex功能的客戶端主機(jī)開機(jī)啟動(dòng)項(xiàng)為網(wǎng)絡(luò)啟動(dòng)内狗,一般默認(rèn)都此選項(xiàng),如果沒(méi)有可自行設(shè)置bios啟動(dòng)項(xiàng)
(2) 客戶端開機(jī)之后進(jìn)入網(wǎng)絡(luò)啟動(dòng)义锥,此時(shí)客戶端沒(méi)有IP地址需要發(fā)送廣播報(bào)文(pxe網(wǎng)卡內(nèi)置dhcp客戶端程序)柳沙,dhcp服務(wù)器相應(yīng)客戶端請(qǐng)求,分配給客戶端相應(yīng)的IP地址與掩碼等信息
(3) 客戶端得到IP地址之后拌倍,與tftp通信赂鲤,下載pxelinux.0,default文件柱恤,根據(jù)default指定的vmlinuz,initrd.img啟動(dòng)系統(tǒng)內(nèi)核数初,并下載指定的ks.cfg文件
(4) 根據(jù)ks.cfg文件去文件共享服務(wù)器(http/ftp/nfs)上面下載RPM包開始安裝系統(tǒng),注意此時(shí)的文件服務(wù)器是提供yum服務(wù)器的功能的梗顺。
PXE執(zhí)行流程
3泡孩、搭建PXE環(huán)境
實(shí)驗(yàn)環(huán)境背景:
在VMware虛擬機(jī)環(huán)境下搭建
使用linux系統(tǒng):CentOS Linux release 7.6.1810 (Core)
軟件環(huán)境:dhcp、tftp-server寺谤、httpd服務(wù)使用1臺(tái)虛擬機(jī)
使用的網(wǎng)段 :192.168.2.0/24
網(wǎng)關(guān)地址:192.168.2.1
DNS地址:未使用
(1) 下載需要用到的軟件包dhcp仑鸥,tftp-server、httpd变屁、syslinux
yum install dhcp tftp-server httpd syslinux -y
(2) 配置dhcp 服務(wù)
配置dhcp注意事項(xiàng):
dhcp配置文件中眼俊,結(jié)尾要加 “ ;”
必須指明默認(rèn)網(wǎng)關(guān)(option routers ):option routers 192.168.2.1;
必須指明 文件獲取地址: next-server 192.168.2.1;
必須指明要獲取的文件名: filename "pxelinux.0";
[root@node2 ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.10 192.168.2.20;
option routers 192.168.2.1;
filename "pxelinux.0";
next-server 192.168.2.1;
default-lease-time 600;
max-lease-time 7200;
}
[root@node2 ~]# systemctl start dhcpd
[root@node2 ~]# systemctl status dhcpd
(2) 配置tftp-server 服務(wù)
將文件 中的disable = yes 改為no
[root@node2 ~]# cat /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
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
[root@node2 ~]#
(3)復(fù)制用用到的文件到 /var/lib/tftpboot
[root@node2 ~]# mkdir /media/cdrom
[root@node2 ~]# mount /dev/sr0 /media/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@node2 /]# cp -a /media/cdrom/isolinux/{boot.msg,initrd.img,vmlinuz,vesamenu.c32} /var/lib/tftpboot/
[root@node2 /]# cp /media/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@node2 /]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
編輯 vim /var/lib/tftpboot/pxelinux.cfg/default 文件粟关,修改以下4項(xiàng)內(nèi)容 疮胖,其余保持配置不變。
[root@node1 ~]# cat -n /var/lib/tftpboot/pxelinux.cfg/default
1 default linux #在首行添加此信息
2 #default vesamenu.c32 #注釋此行
62 label linux
63 menu label ^Install CentOS 7
64 kernel vmlinuz
65 append initrd=initrd.img ks=http://192.168.2.1/centos7.ks #添加此行內(nèi)容
66 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet #注釋此行內(nèi)容
[root@node1 ~]#
(4)配置httpd 服務(wù)
將系統(tǒng)光盤鏡像掛載至httpd 服務(wù)默認(rèn)路徑的一個(gè)文件夾內(nèi),名字隨意
[root@node2 /]# mkdir /var/www/html/centos7
[root@node2 /]# umount /dev/sr0
[root@node2 /]# mount /dev/sr0 /var/www/html/centos7/
mount: /dev/sr0 is write-protected, mounting read-only
[root@node2 /]#
將kickstart 文件放置在/var/www/html/ 目錄下澎灸,并編輯文件
[root@node2 /var/www/html]# cat centos7.ks
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.2.1/centos7" #此處指向httpd提供鏡像文件的地址
# Use text mode install
text
# Firewall configuration
firewall --disabled
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=eth0 --noipv6 --activate
network --hostname=localhost.localdomain
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$16PXgd.m$C4vE6OJCMGfQVadgm0DSe.
# SELinux configuration
selinux --disabled
# System services
services --enabled="chronyd"
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=1024
part / --asprimary --fstype="ext4" --ondisk=sda --size=10240
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages
@core
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
[root@node2 /var/www/html]#
至此Centos 7 的PXE 環(huán)境就算搭建完成了院塞。
注意:在使用客戶端測(cè)試時(shí),內(nèi)存不能小于2G,否則會(huì)提示 空間不足击孩,切記迫悠。
kickstart 文件生成的兩種方式:
第一種:在擁有desktop環(huán)境的系統(tǒng)下安裝system-config-kisckstart軟件,然后執(zhí)行system-config-kisckstart命令后巩梢,會(huì)出現(xiàn)圖形界面创泄,圖形編輯
第二種方式 :手敲 kickstart文件,參考網(wǎng)站:https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/6/html/installation_guide/s1-kickstart2-options
或者百度查找別人寫好的kickstart文件括蝠,但這不一定適應(yīng)你的電腦環(huán)境鞠抑。