PXE网络装机

实验名称:PXE网络装机实验
实验要求:搭建PXE服务,对裸机进行自动化安装centos7操作系统
实验环境:centos7虚拟机一台,搭建pxe进行网络装机;一台裸机,用于验证
实验步骤:
1),准备环境
配置网络源yum

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir yum.repos.d.bak
[root@localhost yum.repos.d]# mv C* yum.repos.d.bak
[root@localhost yum.repos.d]# vim yum.repo
# CentOS-Base.repo
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.

# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

2),安装配置所需程序
清空yum缓存,重新加载数据,安装yum扩展包

[root@localhost yum.repos.d]# yum clean all										#清空缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up everything
[root@localhost yum.repos.d]# yum makecache								#加载数据
Loaded plugins: fastestmirror, langpacks
base                                                           | 3.6 kB  00:00:00     
extras                                                         | 2.9 kB  00:00:00     
updates                                                        | 2.9 kB  00:00:00     
(1/10): base/7/x86_64/group_gz                                 | 153 kB  00:00:00     
(2/10): base/7/x86_64/primary_db                               | 6.1 MB  00:00:00     
(3/10): base/7/x86_64/other_db                                 | 2.6 MB  00:00:00     
(4/10): base/7/x86_64/filelists_db                                                                                                                      | 7.2 MB  00:00:06     
(5/10): extras/7/x86_64/filelists_db                                                                                                                    | 224 kB  00:00:05     
(6/10): extras/7/x86_64/other_db                                                                                                                        | 134 kB  00:00:00     
(7/10): extras/7/x86_64/primary_db                                                                                                                      | 222 kB  00:00:06     
(8/10): updates/7/x86_64/primary_db                                                                                                                     | 3.7 MB  00:00:01     
(9/10): updates/7/x86_64/other_db                                                                                                                       | 227 kB  00:00:00     
(10/10): updates/7/x86_64/filelists_db                                                                                                                  | 2.1 MB  00:00:01     
Determining fastest mirrors
Metadata Cache Created
[root@localhost yum.repos.d]# yum -y install yum-utils                  			#安装yum扩展程序

安装dhcp服务程序,编辑dhcp的配置文件

[root@localhost yum.repos.d]# yum -y install dhcp     							安装dhcp服务程序
[root@localhost yum.repos.d]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf     #复制文件,强行覆盖 
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@localhost yum.repos.d]# vim /etc/dhcp/dhcpd.conf		配置dhcp
subnet 192.168.22.0 netmask 255.255.255.0 {                       #网段和子网掩码
  range 192.168.22.80  192.168.22.150;                                 #IP地址池
  option domain-name-servers ns1.internal.example.org;       #DNS域名服务器
  option domain-name "internal.example.org";                        #域
  option routers 192.168.22.254;                                             #网关
  option broadcast-address 192.168.22.255;                          #广播
  default-lease-time 600;                                    						#默认组约时间,单位秒
  max-lease-time 7200;                                                        	#最大租约时间
  next-server 192.168.22.100;                                               	#PXE服务器IP
  filename "pxelinux.0";                                							#制定引导文件
}
[root@localhost yum.repos.d]# systemctl start dhcpd			#开启dhcp服务

安装所需程序

[root@localhost yum.repos.d]# yum -y install syslinux  xinetd tftp-server vsftpd       	#安装程序
[root@localhost yum.repos.d]# mkdir /var/ftp/centos7       											#创建镜像存放目录
[root@localhost yum.repos.d]# cp -rf /media/* /var/ftp/centos7/									#复制镜像数据
[root@localhost yum.repos.d]# cd 																				#切换工作目录
[root@localhost ~]# vim /etc/xinetd.d/tftp 																	#进行编辑,关闭配置中自动关闭tftf-server服务,yes为默认关闭  
        disable                 = no 								#把此行yes改为no
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg                                				#创建pxelinux.cfg目录
[root@localhost ~]# cp /media/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default     #复制模板
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/vmlinuz /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/initrd.img /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/vesamenu.c32 /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/boot.msg /var/lib/tftpboot/
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 										编辑配置,进行修改
label linux
  menu label ^Install CentOS Linux 7
  kernel vmlinuz
  append initrd=initrd.img inst.repo=ftp://192.168.22.100/centos7 inst.ks=ftp://192.168.22.100/ks.cfg

label check
  menu label Test this ^media & install CentOS Linux 7
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=ftp://192.168.22.100/yum inst.ks=ftp://192.168.22.100/yum/ks.cfg quiet
[root@localhost ~]# setenforce 0																		#暂时关闭沙河
[root@localhost ~]# systemctl start vsftpd															#开启服务
[root@localhost ~]# systemctl start xinetd															#开启服务

安装使用自动化工具

[root@localhost ~]# yum -y install system-config-kickstart				安装kickstart自动化工具
[root@localhost ~]# system-config-kickstart									启动工具

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

保存后Ctrl+c退出

[root@localhost ~]# vim /root/anaconda-ks.cfg    						#进入复制内容

在这里插入图片描述

[root@localhost ~]# vim ks.cfg					添加复制的anaconda-ks.cfg文件中内容 
[root@localhost ~]# mv ks.cfg  /var/ftp/centos7/        #移动

在这里插入图片描述
设置防火墙规则

[root@localhost ~]# firewall-cmd  --add-service=ftp --permanent
success
[root@localhost ~]# firewall-cmd  --add-service=dhcp --permanent
success
[root@localhost ~]# firewall-cmd  --add-port=69/udp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success

3),使用裸机,进行装机
需注意运行内存至少2G,硬盘大小不小于kickstart设置的大小,裸机和PXE服务器位于同一物理网络
在这里插入图片描述
在这里插入图片描述
自动安装
在这里插入图片描述
在这里插入图片描述
【等安装完毕,至此PXE网络安装完成】

  • 9
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
### 回答1: 步骤1:确保PXE服务器上安装了TFTP服务器,NFS服务器和DHCP服务器。步骤2:将CentOS 7 ISO文件复制到TFTP服务器上,并将其路径添加到TFTP服务器中。步骤3:将CentOS 7安装文件复制到NFS服务器上,并将其路径添加到NFS服务器中。步骤4:设置DHCP服务器,为客户端提供IP地址,TFTP服务器和NFS服务器的路径。步骤5:启动客户端,客户端将从PXE服务器上加载CentOS 7 ISO文件,并开始安装CentOS 7。 ### 回答2: CentOS 7的PXE网络装机包括以下步骤: 1. 准备一台安装了CentOS 7的物理机作为PXE服务器。确保该机器有足够的磁盘空间存储安装图像和其他文件。 2. 在PXE服务器上安装并配置DHCP和TFTP服务。DHCP用于向客户端分配IP地址,并提供引导信息;TFTP用于传输引导加载程序和安装图像。 3. 在PXE服务器上创建TFTP根目录,并将CentOS 7的引导加载程序和安装图像复制到该目录下。 4. 进入PXE服务器的DHCP配置文件,配置IP地址范围以及引导加载程序和安装图像的路径。确保引导加载程序的路径正确,并指向TFTP根目录下的文件。 5. 启动PXE服务器上的DHCP和TFTP服务。 6. 在要进行网络安装的客户机上启动,并在BIOS或UEFI设置中将启动顺序设置为网络引导。 7. 客户机通过DHCP请求获得IP地址,然后通过TFTP下载引导加载程序。 8. 引导加载程序从TFTP服务器下载核心安装程序(vmlinuz)和初始化内存磁盘(initrd.img)。 9. 客户机通过TFTP下载完成后,引导加载程序将加载核心安装程序和初始化内存磁盘。 10. 引导加载程序将进入图形化或文本界面,用户可以选择安装类型、分区和其他安装选项。 11. 用户设置完毕后,安装程序将开始自动安装CentOS 7。 12. 最后,系统会重启并进入新安装的CentOS 7操作系统。 以上是CentOS 7的PXE网络装机步骤。根据实际环境和需求的不同,可能需要额外的配置和步骤。请注意,PXE网络装机需要一定的网络和系统管理知识,以确保正确配置和顺利进行安装。 ### 回答3: CentOS 7使用PXE网络装机是一种方便快捷的安装方式。下面是CentOS 7 PXE网络装机的步骤: 1. 首先,需要一台装有CentOS 7的服务器作为PXE服务器。确保服务器上已经连接了网络,并且具备DHCP和TFTP服务。 2. 安装和配置DHCP服务器。DHCP服务器用于为新安装的计算机分配IP地址。在CentOS 7上,可以使用yum命令安装dhcp软件包。安装完成后,在/etc/dhcp/dhcpd.conf文件中编辑DHCP的配置,指定DHCP服务器的相关信息如子网、网关、DNS等,并指定PXE启动器的位置。 3. 安装和配置TFTP服务器。TFTP服务器用于传输启动器和相关的文件。同样可以使用yum命令安装tftp软件包。安装完成后,在/etc/xinetd.d/tftp文件中编辑TFTP服务的配置,指定TFTP服务器的相关信息。 4. 在PXE服务器上准备PXE启动器和相关的文件。PXE启动器是用来引导新安装计算机的程序。首先,将CentOS 7安装光盘镜像文件挂载到一个目录下。然后,将PXE相关的文件复制到TFTP服务器的根目录下,包括pxelinux.0、vmlinuz、initrd.img等。 5. 配置新安装计算机的BIOS。确保新安装计算机的BIOS设置中,启用了PXE启动功能,并将PXE启动设备设置为首选。 6. 开始安装新计算机。在新计算机启动时,它会发送DHCP请求并接收PXE服务器返回的信息。在得到TFTP服务器的响应后,新计算机会下载PXE启动器和相关的文件,并根据启动器的指示进行安装。 通过以上的步骤,就可以实现CentOS 7的PXE网络装机了。这种方式可以大大简化大量计算机的安装过程,提升工作效率。
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值