PXE+KickStart 全自动化部署
PXE 简介
-
PXE (preboot execute environment ,预启动执行环境)工作于 Client/Server 的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,
-
进行 PXE 安装的必要条件是要安装的计算机中包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。PXE 协议使计算机可以通过网络启动。
-
协议分为 client 和 server 端,PXE client 在网卡的 ROM 中,当计算机引导时,BIOS 把 PXE client 调入内存执行,由 PXE client 将放置在远端的文件通过网络下载到本地运行。
-
运行 PXE 协议需要设置 DHCP 服务器和 TFTP 服务器。
DHCP 服务器用来给 PXE client(将要安装系统的主机)分配一个 IP 地址,由于是给 PXE client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的 PXE 设置。(bootp booting等选项) -
此外,在 PXE client 的 ROM 中,已经集合了 TFTP Client。PXE Client 通过 TFTP 协议就可以 到 TFTP Server 上下载网络引导 所需的文件
工作过程
1)、PXE Client 从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP;
2)、DHCP 服务器返回分配给客户机的 IP 以及PXE文件的放置位置(该文件一般是放在一台TFTP服务器上) ;
3)、PXE Client 向本网络中的TFTP服务器索取pxelinux.0 文件;
4)、PXE Client 取得pxelinux.0 文件后之执行该文件;
5)、根据pxelinux.0 的执行结果,通过TFTP服务器加载内核和文件系统 ;
6)、进入安装画面, 此时可以通过选择HTTP、FTP、NFS 方式之一进行安装;
Kickstart 的概述
-
Kickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为ks.cfg的文件。如果在安装过程中(不只局限于生成Kickstart安装文件的机器)出现要填写参数的情况,安装程序首先会去查找Kickstart生成的文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便需要安装者手工干预了。所以,如果Kickstart文件涵盖了安装过程中可能出现的所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启系统,并结束安装。
-
目的是为了 减少系统安装的过程中的人机交互,提高安装效率
实现部署的环境要求
1、客户端可以是裸机,客户端和服务器,必须处于同一 广播域
2、客户端的网卡,必须拥有 PXE ROM (preboot execution Enviroment)芯片,远程引导技术。(一般有)
3、客户端的 BIOS 开启网络启动功能,并将网络引导作为首选启动项。
使用一台服务器搭建,实现全自动化部署
dhcp + tftp + syslinux + NFS + kickstart
一、配置 dhcp 服务器
[root@rehl-14 ~]# yum install -y dhcp #安装dhcp服务
[root@rehl-14 ~]# vim /etc/dhcpd/dhcpd.conf #修改dhcp配置
ddns-update-style interim;
ignore client-updates;
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.2;
option subnet-mask 255.255.255.0;
option domain-name "gz.com";
option domain-name-servers 202.96.128.166;
range dynamic-bootp 192.168.10.20 192.168.10.30;
default-lease-time 21600;
max-lease-time 43200;
allow bootp;
allow booting;
next-server 192.168.10.14;
filename "pxelinux.0"; ##不要写路径,只需要写文件名称即可
}
[root@rehl-14 ~]# service dhcpd start #启动服务
二、安装 tftp服务
[root@rehl-14 ~]# yum install -y tftp tftp-server #安装tftp服务
[root@rehl-14 ~]# systemctl start tftp #启动tftp服务
三、安装 syslinux 提供引导文件 pxelinux.0 和菜单
1、提供的 pxelinux.0 复制到 tftp 工作目录 /var/lib/tftpboot/ 下
[root@rehl-14 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
2、拷贝各个版本启动所需的文件内核以及镜像文件
[root@rehl-14 ~]# cp /iso/isolinux/vmlinuz /var/lib/tftpboot/rhel7-vmlinuz
[root@rehl-14 ~]# cp /iso/isolinux/initrd.img /var/lib/tftpboot/rhel7-initrd.img
3、创建 pxelinux 的配置文件, 已经启动欢迎信息文件
**注意:**rhel7-vmlinuz 内核的命名 和 rhel7-initrd.img 引导启动程序命名必须要和引导配置文件的命名一样;否则会找不到内核和启动程序导致引导失败无法安装 …
[root@rehl-14 tftpboot]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@rehl-14 tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
default 1
timeout 600
display boot.msg
prompt 1
label 1
kernel rhel7-vmlinuz
append initrd=rhel7-initrd.img method=nfs://192.168.10.14/iso
label 2
kernel centos7-vmlinuz
append initrd=centos7-initrd.img method=nfs://192.168.10.73/iso
4、创建并编辑 boot.msg 欢迎界面(自定义编辑)
[root@rehl-14 ~]# vim /var/lib/tftpboot/boot.msg
#############################################################
# WELCOME #
# please select the system you want to install #
# #
# ----1-To Install RHEL7.4 Press Enter ------- #
# #
# ----2-To Install CentOS7.4 Type 2 And Press Enter ------ #
# #
# ----3-To Install CentOS6 Type 3 And Press Enter ------ #
# #
#############################################################
5、检查, /var/lib/tftpboot 目录
检查是否存在如下文件
[root@rehl-14 tftpboot]# ls
boot.msg pxelinux.0 pxelinux.cfg rhel7-initrd.img rhel7-vmlinuz
四、配置好NFS 服务器
[root@rehl-14 ~]# yum install -y nfs-utils rpcbind
[root@rehl-14 ~]# vim /etc/exports
/iso 192.168.10.0/255.255.255.0(ro)
[root@rehl-14 ~]# exportfs -rv #直接生效
五、安装 kickstart (确保有图形安装界面)
[root@rehl-14 ~]# yum install -y system-config-kickstart
[root@rehl-14 ~]# system-config-kickstart #启动Kickstart
对配置程序进行修改
保存生成对应的脚本配置文件(可自定义命名后,但缀必须是 .cfg)
如果没有图形化界面,那就引用图形化界面操作生成的脚本配置文件。配置模板 ks.cfg
[root@rehl-14 ~]# vim /root/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$R3/f9TQa$Zm8fEGCP55jeEPXBsk7bg. ##密码123123
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Use NFS installation media
nfs --server=192.168.10.12 --dir=iso
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --asprimary --fstype="ext4" --size=10240
part /data --fstype="ext4" --grow --size=1
%packages
@base
@core
wget
tree
psmisc
vsftpd
%end
修改配置文件 /var/lib/tftboot/pxelinux.cfg/defautl
[root@rehl-14 ~]# vim /var/lib/tftboot/pxelinux.cfg/defautl
......
abel 1
kernel vmlinuz7-4
append initrd=initrd7-4.img method=nfs://192.168.10.14/iso ks=http://192.168.10.14/ks.cfg
......
六、启动测试机进行自动化部署安装
在 VMware 上添加新的虚拟机进行安装测试
选择 1,回车确认,接下来就是等待他自个完成就行
安装完成后会来到这个界面,那表示已经安装成功了