手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS 7 基于PXE安装系统

[日期:2017-03-29] 来源:Linux社区  作者:wangfeng [字体: ]

一、概念与原理

什么是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)、系统版本

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

123

[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源为系统默认源,
本级网络为
[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服务

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

配置dhcp服务器,使其能够提供172.16.219.50-172.16.219.53的ip地址,子网掩码为255.255.255.0。配置如下
[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的方式提供服务)
[root@localhost ~]# yum install -y httpd

配置如下
[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服务端
[root@localhost ~]# yum install tftp-server xinetd -y

修改xinetd文件

# 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包
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文件
[root@localhost ~]# yum install -y syslinux

准备文件
cd /usr/share/syslinux/
cp pxelinux.0 menu.c32 memdisk mboot.c32 chain.c32 /var/lib/tftpboot/

自定义pxe文件
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)、重启各个服务
systemctl restart xinetd
systemctl restart httpd
systemctl restart dhcpd

将各个服务设置成开机自启动
systemctl enable xinetd
systemctl enable httpd
systemctl enable dhcpd

一切准备就绪,可以开始测试了
10)、测试安装

PXE+Kickstart实现无人值守批量安装Linux  http://www.linuxidc.com/Linux/2015-11/125040.htm

Linux 基础教程:Linux Kickstart 自动安装  http://www.linuxidc.com/Linux/2015-05/117877.htm

使用PXE+DHCP+Apache+Kickstart无人值守安装CentOS5.8 x86_64 http://www.linuxidc.com/Linux/2012-12/76913p4.htm

Linux PXE无人值守安装出现 PXE-E32:TFTP OPen timeout的解决办法 http://www.linuxidc.com/Linux/2014-03/98986.htm

使用PXE结合kickstart 自动安装Linux系统 http://www.linuxidc.com/Linux/2014-03/98014.htm

Linux运维自动化工具 Kickstart  http://www.linuxidc.com/Linux/2016-04/129978.htm

RHCE认证之无人值守安装Linux系统(FTP+TFTP+DHCP+Kickstart+PXE) http://www.linuxidc.com/Linux/2013-10/91013.htm

Kickstart 全自动安装部署RHEL 7.0  http://www.linuxidc.com/Linux/2015-09/123312.htm

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-03/142326.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款