1、名词解释 一、PXE PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术, 工做于Client/Server的网络模式。严格来讲,PXE 并非一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC),即网卡中必需要有 PXE Client。现有网卡基本支持pxe技术。 二、Kickstart Kickstart是一种无人值守的安装方式。它的工做原理是在安装过程当中记录典型的须要人工干预填写的各类参数,并生成一个名为ks.cfg的文件。 2、实现原理 原理图以下:html
Pxe详细的工做流程图:node
3、系统环境 本实验目标:经过pxe、tftp、dhcp、http、kickstart实现CentOS 7 minimal无人值守安装。 实验环境:vmware workstation 14.0.0 网络模式:桥接模式 TFTP、DHCP、HTTP服务器IP地址(共用同一虚机):192.168.1.230linux
准备工做: 确保服务器selinux以及防火墙已关闭:ios
关闭防火墙命令以下:web
#systemctl stop firewall ##临时关闭防火墙,重启后防火墙恢复 #systemctl disable firewall ##关闭防火墙,永久有效。
关闭iptables:centos
#systemctl stop iptables #systemctl disable iptables
关闭selinux:浏览器
#setenforce 0 #临时关闭selinux
若是想永久关闭selinux,直接修改/etc/selinux/config,将 SELINUX=enforcing修改为SELINUX=disable。 4、部署安装 一、安装http服务器服务器
#yum install httpd -y
检查httpd是否在运行:网络
#systemctl status httpd
能够看到active(running)则表示服务正在运行。socket
经过web访问验证,在宿主机上用浏览器访问 http://192.168.1.230:8088 (默认端口为80,可是个人虚机上80端口被别的应用占用,因而修改为8088端口),以下图示,则成功:
设置http服务开机启动:
#systemctl enable httpd
二、安装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
三、安装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 (不建议设成开机启动)
四、部署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文件中安装介质地址以下: 更改前:
更改后:
五、建立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文件获取。
5、安装操做系统 开启目标计算机,而后进入bios设置成网络启动,即进入安装过程。
参考: https://www.cnblogs.com/mchina/p/centos-pxe-kickstart-auto-install-os.html