pxe网络安装服务器的部署

1、pxe介绍

问1:pxe是什么?
答:pxe(Preboot execution Environment)----预执行环境,提供了一种使用网络接口启动计算机的机制,这种机制让计算机的启动可以不依赖本地数据存储设备(如硬盘)或本地已安装的操作系统。可以通过这个网络接口访问系统中的共享资源,从而往自己的系统中安装这些资源
问2:为什么引入pxe?

  1. 你现在有1台电脑需要装系统,那么很简单,你拿上一个U盘安装盘插在这台电脑上,然后从U盘启动,之后就可以手动安装系统了;但如果你现在有100台电脑,如果你在拿着一个U盘安装盘一台台安装,那效率肯定是太低了,这个时候PXE就派上用场了。

  2. 某公司对信息安全要求比较高,需要使用无盘系统(系统不在本地电脑上,而在公司特定的服务器上),这个时候也需要使用PXE。

答:因为服务器上的光盘(光驱)不是必备的,当我们用光盘镜像给主机安装系统时,每台主机都需要做一次安装,要想并行安装,每个系统都需要一个光盘,要么就只能一台主机安装完后另一台主机再安装,在企业中,这些都是不被允许的。
解决方法:通过网络安装服务,但是通过网络安装还有一些问题待解决。

问3:怎样让新买的主机主动去访问共享资源?
答:因为具有共享资源的主机都是被访问的,只有别的主机主动去访问它的资源,而不是它把资源主动推送别人来共享。但是我们新买的主机是没有系统的,没有程序让它们主动去共享安装资源。因此我们怎样才能让这些新买的主机去主动访问共享资源。
解决方法:新买的主机肯定都是有网卡的,我们可以设定这些网卡的工作模式为DHCP的,因此当系统从网卡启动的时候,它会去问网络当中的DHCP服务器索要一个IP,DHCP服务器会给索要IP的主机发送一个数据包,数据包里有IP、dns、gateway这三个信息,我们可以对DHCP服务器进行一些设置,让发送的数据包里再包含一些信息:一个程序(pxelinux.0文件中),该程序的主要作用是让这些新的主机的网卡得到ip以后再去读取pxe程序,然后再由pxe告诉网卡下一步再去读取dhcp服务器系统中的什么资源,我们还可以对资源进行一些设定,让它读取我们的共享资源以及预安装环境之类的信息。

2、PXE服务器搭建实验

1、实验环境
rhel8虚拟机作为服务器:
搭建dhcp服务
用于为需要PXE服务的主机提供IP
搭建vsftp服务
用于为需要PXE服务的主机下载引导程序以及之后的系统,即共享kickstart文件、共享安装源(将镜像挂载到ftp中)
kickstart自动安装脚本
该脚本在rhel8虚拟机中需要手动去写kickstart文件,而在rhel7中可以用图形的方式完成,所以可以在rhel7中用图形的方法做好文件,然后复制到rhel8中,在rhel7中用图形方式完成的方法请参考上一篇博客,但是有些地方需要改动,具体改动的地方如下:
安装源:要通过ftp服务访问rhle8服务器来安装,因为kickstart文件会传到rhel8的ftp服务上
在这里插入图片描述
在这里插入图片描述
安装好系统后的操作:会将yum源自动配置好
在这里插入图片描述
将ks.cfg文件传到rhel8中
在这里插入图片描述
可以看到rhel8服务器上有需要共享的文件
在这里插入图片描述

2、部署pxe环境

查看pxe的部署方法(说明文档)
cd /usr/share/syslinux/
less pxelinux.txt
方法如下:
第一步:在tftp服务器上创建“tftp/boot”目录,并且将pxelinux.0文件和所需要的内核和初始化镜像(即系统启动所有要读取的文件)都放到该目录下
第二步:建立目录:/tftpboot/pxelinux.cfg
在这里插入图片描述
pxelinux.0文件的作用如下,因此我们需要修改default文件的内容

在这里插入图片描述
1、获得pxelinux.0文件(上面所说的程序)

dnf install syslinux-nonlinux-6.04-1.el8.noarch -y ##获得pxelinux.0文件
rpm -ql syslinux-nonlinux-6.04-1.el8.noarch #查看pxelinux.0文件的路径

在这里插入图片描述
2、创建tftp服务器

dnf install tftp-server.x86_64 				#pxelinux.0文件的共享服务器
systemctl start tftp
systemctl enable tftp

在这里插入图片描述
3、将pxelinux.0文件和安装环境所要读取的所有文件放到“tftpboot”目录

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ 	#共享pxelinux.0文件
cp /var/ftp/rhel8/isolinux/* /var/lib/tftpboot/ 	#共享安装环境所要读取的文件

在这里插入图片描述
4、建立目录:/tftpboot/pxelinux.cfg

mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default 
#生成pxelinux.0程序引导的默认读取文件

通过以上四步操作,pxe的环境部署就ok了。接下来,需要配置DHCP服务,让DHCP服务在分配ip信息以后分发pxelinux.0程序

5、dhcpd服务配置分发pxelinux.0

 30 subnet 192.168.0.0 netmask 255.255.255.0 {
 31 range 192.168.0.10 192.168.0.50;
 32 option routers 192.168.0.119;
 33 next-server 192.168.0.119; 	#tftp服务器地址
 34 filename "pxelinux.0"; 	#需要读取的文件名称
 35 }

需要添加的内容如下: 在这里插入图片描述
在这里插入图片描述
5、设置从网络启动(右击开机按钮,然后选择打开电源进入固件)
在这里插入图片描述

6、cd /var/lib/tftpboot/
vim default
看到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 WESTOS INSTALL OS pxe from OLDLEE 	##安装标题
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
menu label ^Install Red Hat Enterprise Linux 8.0.0
menu default 				##设定默认选择标题
kernel vmlinuz
append initrd=initrd.img repo=ftp://192.168.0.119/rhel8 ks=ftp://192.168.0.119/
ksfile/ks.cfg 				##指定安装源和ks文件
label check
menu label Test this ^media & install Red Hat Enterprise Linux 8.0.0
# menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-8-0-0-BaseOS-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 8.0.0 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
Red Hat Enterprise Linux 8.0.0.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-8-0-0-BaseOS-x86_64 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-8-0-0-BaseOS-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

最终会通过网络安装成功,全程不需要手动操作,所有的资源都来自rhel8服务器

注意:
做该网络安装实验时需要将磁盘类型设置为SATA模式,并且分配的内存大小必须大于1024M(1024M会安装失败),否则该系统硬件检测会出错,导致系统安装失败
在这里插入图片描述

结束!!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值