理论+实验·PXE高效批量网络装机

理论+实验·PXE高效批量网络装机

PXE概述

PXE批量部署的优点

规模化:同时装配多台服务器

自动化:安装系统、配置各种服务

远程实现:不需要光盘、U盘等安装介质

网络带宽是瓶颈 建议千兆口的带宽

指定数量的一批裸金属

PXE(Preboot eXcution Environment)

预启动执行环境,在操作之前运行

服务端

运行DHCP服务,用来分配地址、定位引导程序

运行TFTP服务,提供引导程序下载

客户端

网卡支持PXE协议

主板支持网络引导

配置PXE装机服务器

基本部署过程

1:准备CentOS 7 安装源(YUM仓库)

2:安装并启用TFTP服务

3:提供Linux内核、PXE引导程序等

4:安装并启用DHCP服务

5:配置启动菜单

准备CentOS 7 安装源

​ CentOS 7 安装源支持HTTP、FTP、NFS等协议发布

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

[root@localhost ~]# mkdir /var/ftp/centos7/

[root@localhost ~]# cp -rf /dev/cdrom/* /var/ftp/centos7/

[root@localhost ~]# systemctl start vsftpd

安装并启用TFTP服务

​ 安装tftp-server软件包,启用tftp服务

​ 配置文件位于/etc/xinetd.d/tftp

[root@localhost ~]# yum -y install tftp-server ===>安装tftp-server

[root@localhost ~]# vi /etc/xinetd.d/tftp  

disable	= no ===>修改配置值

[root@localhost ~]# systemctl start tftp

[root@localhost ~]# systemctl enable tftp

准备Linux内核、PXE引导程序

​ Linux内核、初始化镜像文件分别为vmlinuz和initrd.img

​ 引导程序为pxelinux.0,由软件包syslinux提供

[root@localhost ~]# cd /dev/cdrom/images/pxeboot

[root@localhost pxeboot]# cp vmliunz initrd.img /var/lib/tftpboot

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

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot ===>将内核拷贝到/vavr/lib/tftpboot目录下

DHCP服务的PXE设置

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

[root@localhost ~]# vi /etc/dhcp/dhcpd.conf

subnet 192.168.100.0 netmask 255.255.255.0{

​    ......

​    range 192.168.100.20 192.168.100.30;

​    option routers 192.168.100.100;

​    option domain-name-servers 8.8.8.8;

​    next-server 192.168.100.100; ===>指定TFTP服务器地址

​    filename "pxelinux.0"; ===>指定要下载的引导程序文件

}

[root@localhost ~]# systemctl start dhcpd

[root@localhost ~]# systemctl enable dhcpd

配置启动菜单文件

[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default ===>确保pxelinux.cfg目录已存在

default suto

prompt 1 ===>1s提示

label auto 

​	kernel	vmlinuz

​	append	initrd=initrd.img	method=ftp://192.168.100.100/centos7



label linux text ===>文本模式安装

​	kernel	vmlinuz

​	append	text	initrd=initrd.img	method=ftp://192.168.100.100/centos7



label linux rescue ===>进入急救模式

​	kernel	vmlinuz

​	append	rescue	initrd=initrd.img	method=ftp://192.168.100.100/centos7

TFTP四大文件:

1:default文件 需要先创建pxelinux.cfg目录 引导配置文件默认被加载

2:vmlinuz 压缩内核 在default中被定义最先被加载

3:initrd.img 初始化镜像文件 在default中被定义第二个被加载

4:PXElinux.0 引导程序 需要安装syslinux包才会有,在DHCP配置文件中被定义

三大服务:

1:DHCP 让客户端获取IP地址,能主动联网PXE服务器 配置中指向TFTP

2:TFTP: 简单文件系统 UDP 69 端口快速加载引导程序,引导程序的容量较小

小容量的文件 默认配置文件指向FTP镜像位置

3:FTP:文件系统 TCP 21 连接服务 20 传输数据 系统镜像存放

大容量的文件

验证PXE网络安装

为客户机安装系统

​ 调整BIOS设置,以便从网络引导

​ 自动获取IP地址,并指定CentOS 7 安装源

​ 其余过程与本地安装相同

PXE高效批量网络装机实验

1:安装DHCP服务

安装DHCP
[root@localhost ~]# yum -y install dhcp* ===>安装dhcp

[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes        ===>将模板文档直接拷贝到dhcp配置文件里面

[root@localhost ~]# vi /etc/dhcp/dhcpd.conf ===>修改配置文件
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.20 192.168.100.30;
  option routers 192.168.100.100;
  option domain-name-servers 8.8.8.8;
  next-server 192.168.100.100;
  filename "pxelinux.0";
}


2:安装tftp服务

安装tftp服务
[root@localhost ~]# yum -y install tftp-server ===>安装tftp-server

[root@localhost ~]# vi /etc/xinetd.d/tftp ===>修改配置文件
disable                 = no ===>这一行改成no

[root@localhost ~]# yum -y install syslinux ===>安装syslinux

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ ===>将pxelinux.0拷贝到tftp的站点目录下

[root@localhost tftpboot]# mount /dev/cdrom /mnt ===>挂载光盘
mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost images]# cd /mnt/images/pxeboot/ ===>进入该目录

[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/ ===>将内核跟初始化镜像文件拷贝到tftp站点目录下

3:安装FTP服务

安装ftp服务 
[root@localhost tftpboot]# yum -y install vsftpd ===>安装vsftpd

[root@localhost tftpboot]# mkdir /var/ftp/centos7 ===>创建一个目录存放光盘的镜像

[root@localhost tftpboot]# mount /dev/cdrom /mnt ===>挂载光盘

[root@localhost tftpboot]# cp -rf /mnt/* /var/ftp/centos7/ ===>将光盘里里面的镜像文件拷贝到centos7目录下

[root@localhost tftpboot]# setenforce 0 ===>关闭核心防护

[root@localhost tftpboot]# systemctl stop firewalld ===>关闭防火墙


关于kickstart

kickstart无人值守技术

​ 创建应答文件,预先定义好各种安装设置 ===>ks.cfg

​ 免去交互设置过程,从而实现全自动话安装

准备应答文件

应答文件的来源

​ 编辑CentOS 7 系统中现有的应答文件

​ /root/anaconda-ks.cfg ===>当前系统内都会有这个文件

​ 使用system-config-kickstart工具创建新的应答文件

​ 需要安装system-config-kickstart软件包

PXE+kickstart自动安装

PXE于kickstart结合使用

[root@localhost ~]# vi /var/lib/pxelinux.cfg/default

default auto
prompt 1

label auto
        kernel  vmlinuz
        append  initrd=initrd.img       method=ftp://192.168.100.100/centos7    ks=ftp://192.168.100.100/ks.cfg

label linux text
        kernel  vmlinuz
        append  text    initrd=initrd.img       method=ftp://192.168.100.100/centos7

label linux rescue
        kernel  vmlinuz
        append  rescue  initrd=initrd.img       method=ftp://192.168.100.100/centos7

验证自动安装

​ 将客户机以PXE方式引导

​ 系统会自动完成安装,并配置好软件仓库

​ 整个安装过程无需手动干预

kickstart无人值守安装实验

1:安装system-config-kickstart

[root@localhost ~]# yum -y install system-config-kickstart ===>安装system-config-kickstart

2:配置kickstart

打开kickstart软件

image-20200713185948063

1)基本配置

image-20200713190201451

2)安装方法

image-20200713190318262

3)引导装载程序选项

image-20200713190415309

4)分区信息

image-20200713190531454

5)网络配置

image-20200713190609066

6)防火墙配置

image-20200713190645450

7)安装后脚本

image-20200713190726761

8)保存到/var/ftp/目录下

3:修改配置文件

[root@localhost ~]# cd /root

[root@localhost ~]# ls
anaconda-ks.cfg       公共  视频  文档  音乐
initial-setup-ks.cfg  模板  图片  下载  桌面

[root@localhost ~]# vi anaconda-ks.cfg ===>复制配置文件里面的下面这些内容
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools
%end

[root@localhost ~]# cd /var/ftp/ ===>进入该目录

[root@localhost ftp]# ls ===>查看
centos7  ks.cfg  pub

[root@localhost ftp]# vi ks.cfg ===>修改配置文件(把之前复制的全部粘贴到该文件最后)

[root@localhost ftp]# cd /var/lib/tftpboot/ ===>进入该目录

[root@localhost tftpboot]# ll ===>查看
总用量 57872
-rw-r--r--. 1 root root 52584760 7月  13 17:29 initrd.img
-rw-r--r--. 1 root root    26759 7月  13 17:25 pxelinux.0
drwxr-xr-x. 2 root root       21 7月  13 18:56 pxelinux.cfg
-rwxr-xr-x. 1 root root  6639904 7月  13 17:29 vmlinuz

[root@localhost tftpboot]# cd pxelinux.cfg/ ===>进入该目录

[root@localhost pxelinux.cfg]# ls ===>查看
default

[root@localhost pxelinux.cfg]# vi default ===>修改配置文件
default auto
prompt 1

label auto
  kernel  vmlinuz
  append initrd=initrd.img  method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg

label linux text
        kernel  vmlinuz
        append  text    initrd=initrd.img       method=ftp://192.168.100.100/centos7

label linux rescue
        kernel  vmlinuz
        append  rescue  initrd=initrd.img       method=ftp://192.168.100.100/centos7

猜你喜欢

转载自blog.csdn.net/weixin_47153668/article/details/107329914
今日推荐