博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos7 基于pxe安装系统
阅读量:7046 次
发布时间:2019-06-28

本文共 4602 字,大约阅读时间需要 15 分钟。

一、概念与原理

什么是PXE

   严格来说,PXE 并不是一种安装方式,而是一种引导的方式。进行 PXE 安装的必要条件是要安装的计算机中包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。PXE (Pre-boot Execution Environment,直译为启动前的执行环境)协议使计算机可以通过网络启动。协议分为 client 和 server 端,PXE client 在网卡的 ROM 中,当计算机引导时,BIOS 把 PXE client 调入内存执行,由 PXE client 将放置在远端的文件通过网络下载到本地运行。运行 PXE 协议需要设置 DHCP 服务器和 TFTP 服务器。DHCP 服务器用来给 PXE client(将要安装系统的主机)分配一个 IP 地址,由于是给 PXE client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的 PXE 设置。此外,在 PXE client 的 ROM 中,已经存在了 TFTP Client。PXE Client 通过 TFTP 协议到 TFTP Server 上下载所需的文件。

什么是KickStart

   KickStart是一种无人职守安装方式。KickStart的工作原理是通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个名为ks.cfg的文件;在其后的安装过程中(不只局限于生成KickStart安装文件的机器)当出现要求填写参数的情况时,安装程序会首先去查找KickStart生成的文件,当找到合适的参数时,就采用找到的参数,当没有找到合适的参数时,才需要安装者手工干预。这样,如果KickStart文件涵盖了安装过程中出现的所有需要填写的参数时,安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中设置的重启选项来重启系统,并结束安装。

二、环境说明

  执行pxe+kickstart来批量安装系统,需要的环境为

  1.DHCP服务器

  2.TFTP服务器

  3.httpd服务器或者ftp服务器或nfs服务器等能提供文件访问的服务器

  4.ks.cfg文件

  5.syslinux服务提供的pxelinux.0文件

  6.一台带有支持pxe协议的网卡的主机

  7.为确保实验可用性,请将防火墙和selinux关闭

三、安装步骤

1)、系统版本

1
2
[root@localhost ~]# uname -r
3.10.0-327.el7.x86_64

1
2
3

[root@localhost ~]# uname -a

Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


2)、配置网络环境以及yum源

本处使用的yum源为系统默认源,

本级网络为

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost dhcp]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    
link
/loopback 
00:00:00:00:00:00 brd 00:00:00:00:00:00
    
inet 127.0.0.1
/8 
scope host lo
       
valid_lft forever preferred_lft forever
    
inet6 ::1
/128 
scope host
       
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    
link
/ether 
00:0c:29:cc:38:86 brd ff:ff:ff:ff:ff:ff
    
inet 172.16.219.136
/24 
brd 172.16.219.255 scope global dynamic eno16777736
       
valid_lft 1353sec preferred_lft 1353sec
    
inet6 fe80::20c:29ff:fecc:3886
/64 
scope link
       
valid_lft forever preferred_lft forever

    3)、安装DHCP服务

1
[root@localhost ~]
# yum install -y dhcp

 配置dhcp服务器,使其能够提供172.16.219.50-172.16.219.53的ip地址,子网掩码为255.255.255.0。配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
[root@localhost ~]
# vi /etc/dhcp/dhcpd.conf
 
ddns-update-style interim;
 
ignore client-updates;
 
authoritative;
 
allow booting;
 
allow bootp;
 
allow unknown-clients;
 
# A slightly different configuration for an internal subnet.
 
subnet 172.16.219.0 netmask 255.255.255.0 {
    
range 172.16.219.50 172.16.219.53;
    
default-lease-
time 
600;
    
max-lease-
time 
7200;
 
 
next-server 172.16.219.136; 
#  DHCP server ip
 
filename 
"pxelinux.0"
;
 
}

4)、安装httpd服务(本文通过http的方式提供服务)

1
[root@localhost ~]
# yum install -y httpd

配置如下

1
2
3
4
5
6
7
8
[root@localhost ~]
# vi /etc/httpd/conf.d/pxeboot.conf
Alias 
/centos7_x64 
/var/lib/tftpboot/centos7_x64/
 
<Directory 
/var/lib/tftpboot/centos7_x64
>
Options Indexes FollowSymLinks
Require ip 127.0.0.1 172.16.219.0
/24
<
/Directory
>
~

5)、安装tftp-server服务端

1
[root@localhost ~]
# yum install tftp-server xinetd -y

修改xinetd文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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
}

把siabled的yes改为no

6)、准备所需要的rpm包

1
2
3
4
mount 
-o loop 
/root/CentOS-XX
.iso 
/mnt/
mkdir 
/var/lib/tftpboot/centos7_x64
cp 
-fr 
/mnt/
/var/lib/tftpboot/centos7_x64/
chmod 
-R 755 
/var/lib/tftpboot/centos7_x64/

7)、准备tftpboot下的文件

安装syslinux,此服务为pxe提供pxelinux.0文件

1
[root@localhost ~]
# yum install -y syslinux

准备文件

1
2
cd 
/usr/share/syslinux/
cp 
pxelinux.0 menu.c32 memdisk mboot.c32 chain.c32 
/var/lib/tftpboot/

自定义pxe文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mkdir 
/var/lib/tftpboot/pxelinux
.cfg
default menu.c32
prompt 0
timeout 300
ONTIMEOUT 
local
 
menu title 
########## PXE Boot Menu ##########
 
label 1
menu label ^1) Install CentOS 7
kernel centos7_x64
/images/pxeboot/vmlinuz
append initrd=centos7_x64
/images/pxeboot/initrd
.img method=http:
//172
.16.219.136
/centos7_x64 
devfs=nomount
 
label 2
menu label ^2) Boot from 
local 
drive localboot

9)、重启各个服务

1
2
3
systemctl restart xinetd
systemctl restart httpd
systemctl restart dhcpd

将各个服务设置成开机自启动

1
2
3
systemctl 
enable 
xinetd
systemctl 
enable 
httpd
systemctl 
enable 
dhcpd

一切准备就绪,可以开始测试了

10)、测试安装

本文转自wangfeng7399 51CTO博客,原文链接:http://blog.51cto.com/wangfeng7399/1911145,如需转载请自行联系原作者

你可能感兴趣的文章
POJ1023 The Fun Number System
查看>>
第 41 章 TokyoCabinet/Tyrant
查看>>
8.4. whiptail - display dialog boxes from shell scripts
查看>>
Educational Codeforces Round 21 D.Array Division(二分)
查看>>
Android 中文API (32) —— TimePicker.OnTimeChangedListener
查看>>
如何修改路由器的登录IP地址?
查看>>
外观(Facade)模式
查看>>
Building Android Apps 30条建议
查看>>
【Spring实战】—— 13 AspectJ注解切面
查看>>
Java 集合并交补
查看>>
16.4. jstat - Java Virtual Machine Statistics Monitoring Tool
查看>>
一脸懵逼学习KafKa集群的安装搭建--(一种高吞吐量的分布式发布订阅消息系统)...
查看>>
[Everyday Mathematics]20150209
查看>>
Python图片处理库之PIL
查看>>
(转)基于深度学习的物体检测
查看>>
利用java代码和web拦截器轻松实现一个app抓包工具
查看>>
数制系统
查看>>
cmd连接mysql操作命令
查看>>
“2017最受欢迎中国开源软件”奖TOP 20揭晓 阿里中间件4大项目连续霸榜!
查看>>
Log4j 配置 的webAppRootKey参数问题
查看>>