当前位置: 移动技术网 > 网络运营>服务器>Linux > 荐 Linux中使用PXE及 Kickstart高效批量网络装机

荐 Linux中使用PXE及 Kickstart高效批量网络装机

2020年07月15日  | 移动技术网网络运营  | 我要评论
文章目录前言一、部署PXE远程安装服务1.1PXE概述1.2配置PXE装机服务器1.2.1基本部署过程1.2.2PXE自动部署步骤1.3PXE自动装机实验二、Kickstart概述2.1应答文件的来源2.2PXE与kickstart结合使用实验前言PXE相关概念PXE不是一种安装方式,是一种引导的方式。pxe方式要求安装的计算机中必须包含一个 支持PXE 的网卡,且主板支持网络引导,PXE (Pre-boot Execution Environment)协议使计算机可以通过网络启动。 PXE协议分为

前言

PXE相关概念
PXE不是一种安装方式,是一种引导的方式。pxe方式要求安装的计算机中必须包含一个 支持PXE 的网卡,且主板支持网络引导,PXE (Pre-boot Execution Environment)协议使计算机可以通过网络启动。 PXE协议分为 client 和 server 端,PXE client 在网卡Rom中,当计算机引导时,cpu通过加载bios映射到内存中的片段,然后检查计算机的健康状况(如cpu风扇,网卡等)继而 把网卡Rom中的PXE client 调入内存引导执行,由 PXE client 将放置在远端的文件通过网络下载到本地运行。PXE 协议需要设置 DHCP 服务器 和 TFTP 服务器。DHCP 服务器用来给 PXE client分配一个 IP 地址,由于是给 PXE client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的设置。在 PXE client 的 ROM 中,已经存在了 TFTP Client。PXE Client 通过 TFTP 协议到 TFTP Server 上下载所需的文件。一方面tftp可以达到32M,对于系统内核,引导程序等小文件,足以达到,另一方面tftp使用udp协议69号端口,速度也快足以满足要求速度也可以,何乐而不为。

Kickstart简介:kickstart是一个利用Anconda工具实现服务器自动化安装的方法;通过生成的kickstart配置文件ks.cfg,服务器安装可以实现从裸机到全功能服务的的非交互式(无人值守式)安装配置。

一、部署PXE远程安装服务

1.1PXE概述

  • PXE批量部署的优点
    • 规模化:同时装配多台服务器
    • 自动化:安装系统、配置各种服务
    • 远程实现:不需要光盘、U盘等安装介质
  • PXE (Preboot eXcution Environment)
    预启动执行环境,在操作系统之前运行
  • 服务端
    • 运行DHCP服务,用来分配地址、定位引导程序
    • 运行TFTP服务,提供引导程序下载
  • 客户端
    • 网卡支持PXE协议
    • 主板支持网络引导

1.2配置PXE装机服务器

1.2.1基本部署过程

  • 准备CentOS 7安装源(YUM仓库)
  • 安装并启用TFTP服务
  • 提供Linux内核、PXE引导程序等
  • 安装并启用DHCP服务
  • 配置启动菜单

TFTP服务及引导文件

  • 安装tftp-server软件包,启动tftp服务
  • 准备内核文件vmlinuz,初始化镜像initrd.img
  • 准备引导程序文件pxelinux.0(依赖于syslinux)

配置启动菜单文件

  • 创建/var/lib/tftpboot/pxelinux.cfg/default

DHCP服务的PXE设置

[root@localhost ~]#yum install dhcp -y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

 subnet 192.168.100.0 netmask 255.255.255.0 {
          range 192.168.100.0 192.168.100.50;
          option routers 192.168.100.100;
          option domain-name-servers 8.8.8.8;
          next-server 192.168.100.100;		#指定TFTP服务器地址
          filename "pxelinux.0";	       	#filename:指定要下载的引导程序文件
  }
[root@localhost ~]#systemctl start dhcpd
[root@localhost ~]#systemctl enable dhcpd

1.2.2PXE自动部署步骤

1.将PXE服务器设置双网卡

2.设置DHCP,用来自动获取IP地址,引导定位TFTP位置

  • next-server TFTP IP
  • filename “pxelinux.0”

3.设置TFTP(先安装tftp-server并设置)

  • 1.安装syslinux(包含pxelinux.0)并设置,引导程序
  • 2.压缩内核 vmlinuz (在iso镜像文件中获取)
  • 3.初始化文件 initrd.img (iso镜像文件中获取)
  • 4.默认配置文件 default (自建三个模式,默认时auto,指引FTP镜像系统文件位置)

1.3PXE自动装机实验

实验准备:1台centos7虚拟机用作PXE自动安装服务器,一台尚未安装系统的centos虚拟机用作客户机
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# vim ifcfg-ens36

在这里插入图片描述

[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# yum install dhcp
[root@localhost network-scripts]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
[root@localhost network-scripts]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost network-scripts]# vim /etc/dhcp/dhcpd.conf 

在这里插入图片描述

[root@localhost network-scripts]# yum install tftp-server -y
[root@localhost network-scripts]# yum install syslinux -y
[root@localhost network-scripts]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@localhost network-scripts]# rpm -ql tftp-server
/etc/xinetd.d/tftp           #tftp的配置文件
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot            #tftp的站点
[root@localhost network-scripts]# vim /etc/xinetd.d/tftp 

在这里插入图片描述

[root@localhost network-scripts]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost network-scripts]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
pxelinux.0
[root@localhost tftpboot]# yum install vsftpd -y

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

[root@localhost pxelinux.cfg]# iptables -F
[root@localhost pxelinux.cfg]# setenforce 0
[root@localhost pxelinux.cfg]# systemctl start dhcpd
[root@localhost pxelinux.cfg]# systemctl start tftp
[root@localhost pxelinux.cfg]# systemctl start vsftpd

在这里插入图片描述
在这里插入图片描述
到了这里其实可以很清楚的看到,这里的自动装机其实并不完善,在此界面后就需要手动选择了,大大降低了效率,所以就需要另一项技术的支持。

二、Kickstart概述

  • kickstart无人值守技术
    创建应答文件,预先定义好各种安装设置
    免去交互设置过程,从而实现全自动化安装

2.1应答文件的来源

  • 编辑CentOS 7系统中现有的应答文件
    /root/anaconda-ks.cfg
  • 使用system-config-kickstart工具创建新的应答文件
    需要安装system-config-kickstart软件包

2.2PXE与kickstart结合使用实验

在这里插入图片描述

[root@localhost ~]# yum install system-config-kickstart -y

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

[root@localhost ~]# vim anaconda-ks.cfg 

在这里插入图片描述
将这些软件包复制到ks.cfg文件中

[root@localhost ~]# vim ks.cfg 

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
打开客户机开启,整个过程全部自动安装
在这里插入图片描述
安装完毕重新启动后,可以输入账号密码进入系统了
在这里插入图片描述
在这里插入图片描述

本文地址:https://blog.csdn.net/weixin_47153988/article/details/107320477

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网