一、名词解释 1、PXE PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术, 工作于Client/Server的网络模式。严格来说,PXE 并不是一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。现有网卡基本支持pxe技术。 2、Kickstart Kickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为ks.cfg的文件。 二、实现原理 原理图如下:
Pxe详细的工作流程图:
三、系统环境 本实验目标:通过pxe、tftp、dhcp、http、kickstart实现CentOS 7 minimal无人值守安装。 实验环境:vmware workstation 14.0.0 网络模式:桥接模式 TFTP、DHCP、HTTP服务器IP地址(共用同一虚机):192.168.1.230
准备工作: 确保服务器selinux以及防火墙已关闭:
关闭防火墙命令如下:
#systemctl stop firewall ##临时关闭防火墙,重启后防火墙恢复
#systemctl disable firewall ##关闭防火墙,永久有效。
关闭iptables:
#systemctl stop iptables
#systemctl disable iptables
关闭selinux:
#setenforce 0 #临时关闭selinux
如果想永久关闭selinux,直接修改/etc/selinux/config,将 SELINUX=enforcing修改成SELINUX=disable。 四、部署安装 1、安装http服务器
#yum install httpd -y
检查httpd是否在运行:
#systemctl status httpd
可以看到active(running)则表示服务正在运行。
通过web访问验证,在宿主机上用浏览器访问 http://192.168.1.230:8088 (默认端口为80,但是我的虚机上80端口被别的应用占用,于是修改成8088端口),如下图示,则成功:
设置http服务开机启动:
#systemctl enable httpd
2、安装tftp服务
#yum install tftp-server –y
默认tftp的根目录是/var/lib/tftpboot/,我这里使用的是/tftpboot 目录,需要修改/etc/xinetd.d/tftp 文件。修改后文件内容如下:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -u nobody -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
创建tftp主目录:
#mkdir /tftpboot
启动tftp:
#systemctl start xinetd
设置tftp开机启动:
#systemctl enable xinetd
3、安装dhcp服务
#yum install dhcp –y
修改/etc/dhcp/dhcpd.conf配置文件,修改后内容如下:
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.1.0 netmask 255.255.255.0{
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
option netbios-node-type 2;
range dynamic-bootp 192.168.1.5 192.168.1.50; 设置ip地址池。
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.1.230; #指定tftp服务器地址
filename "pxelinux.0"; #指定pxe文件
}
启动dhcp服务:
#systemctl start dhcpd
设置dhcp开机启动:
#systemctl enable dhcpd (不建议设成开机启动)
4、部署pxelinux 安装syslinux:
#yum install –y syslinux
拷贝相关文件至tftp根目录:
#cp -a /usr/share/syslinux/{menu.c32,vesamenu.c32,pxelinux.0} /tftpboot/
创建配置文件目录:
mkdir /tftpboot/pxelinux.cfg
挂载CentOS7 iso文件至/mnt目录:
#mount /dev/cdrom /mnt
将/mnt目录下的所有文件拷贝至/var/www/html目录:
#cp –rf /mnt/* /var/www/html/
复制/var/www/html/isolinux/*.msg文件至tftp根目录:
#cp /var/www/html/isolinux/*.msg /tftp/
复制/var/www/html/isolinux/vmlinuz 至/tftpboot/目录:
#cp /var/www/html/isolinux/vmlinuz /tftpboot/
复制/var/www/html/isolinux/initrd.img 至 /tftpboot/目录:
#cp /var/www/html/isolinux/initrd.img /tftpboot/
复制/var/www/html/cdrom/isolinux/isolinux.cfg 拷贝至/tftpboot/pxelinux.cfg目录,并更名为default:
#cp /var/www/html/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
此时/tftpboot目录内容如下:(splash.png可有可无,该文件在isolinux目录下)
更改/tftpboot/pxelinux.cfg/default文件,更改timeout 600为 timeout 10,此修改主要是让安装时更快进入安装程序。 更改default文件中安装介质地址如下: 更改前:
更改后:
5、创建kickstart安装响应文件 创建kickstart安装响应文件有两种方式: 1) 通过system-config-kickstart图形化工具配置生产; 2) 通过vi工具,根据kickstart模板手工编写配置文件。 推荐使用system-config-kickstart工具生产ks配置文件。 如果通过 system-config-kickstart 工具来配置ks.cfg文件,则需要安装桌面环境,安装桌面环境命令如下:
#yum –y groupinstall ‘X Window System’
#yum –y groupinstall ‘GNOME Desktop’
安装 system-config-kickstart:
#yum –y install system-config-kickstart
运行system-config-kickstart,配置界面如下:
配置完成后,将ks.cfg 文件拷贝至/var/www/html目录下:
#cp ./ks.cfg /var/www/html/
以下是CentOS7 minimal安装的ks.cfg的内容
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$joth9Kyj$VmO624PljjP6g4nGlkLiX/
# Use network installation
url --url="http://192.168.1.230:8088/"
# System language
lang en_US
# 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
# Network information
network --bootproto=dhcp --device=eth0
# 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
# Disk partitioning information
part swap --fstype="swap" --size=512
part / --asprimary --fstype="xfs" --grow --size=1
%packages
@core
kexec-tools
%end
其中:
%packages
@core
kexec-tools
%end
可以从/root/anaconda-ks.cfg文件获取。
五、安装操作系统 开启目标计算机,然后进入bios设置成网络启动,即进入安装过程。
参考: https://www.cnblogs.com/mchina/p/centos-pxe-kickstart-auto-install-os.html