一、PXE的简介
PXE(preboot execute environment,预启动执行环境)是有inter公司开发的技术,工作与Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP协议下载一个启动软件包到本机内存中执行,由于这个启动预先安装在服务器中的终端操作系统。
[[email protected] ~]# yum -y install dhcp tftp-server vsftpd xinetd syslinux
[[email protected] ~]# mkdir /var/ftp/centos7u3
[[email protected] ~]# mkdir /var/ftp/centos6u6
[[email protected] ~]# mount /dev/cdrom /var/ftp/centos7u3/
[[email protected] ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.226.0 netmask 255.255.255.0 {
range 192.168.226.150 192.168.226.250; #DHCP分配的地址段
[[email protected] ~]# systemctl start dhcpd
[[email protected] ~]# systemctl enable dhcpd
[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[[email protected] ~]# vim /etc/xinetd.d/tftp
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
server_args = -s /var/lib/tftpboot
[[email protected] ~]# systemctl restart xinetd
[[email protected] ~]# systemctl enable xinetd
[[email protected] ~]# ss -utnlp | grep :69
udp UNCONN 0 0 *:69 *:* users:(("xinetd",pid=7955,fd=5))
根据引导菜单所需的文件(从centos7光盘上的isolinux目录)
[[email protected] ~]# cp -rf /var/ftp/centos7u3/isolinux/* /var/lib/tftpboot/
[[email protected] ~]# cd /var/lib/tftpboot/
[[email protected] tftpboot]# mkdir pxelinux.cfg
[[email protected] tftpboot]# cp isolinux.cfg pxelinux.cfg/default
[[email protected] tftpboot]# vim pxelinux.cfg/default
append initrd=initrd.img inst.stage2=ftp://192.168.226.153/centos7u3 inst.repo=ftp://192.168.226.153/centos7u3
[[email protected]]# systemctl enable xinetd
[[email protected]]# systemctl restart xinetd
[[email protected]]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[[email protected]]# systemctl restart vsftpd
启动服务器出现安装界面中安装源能够识别即为成功如果失败检查/var/lib/tftpboot/pxelinux.cfg/default 配置文件的配置信息
如果希望提供centos7u3 centos6u8等多个系统:
1.为每个系统准备/var/lib/tftp/centosX/{vmlinuz,initrd}
2.为每个系统准备引导菜单 /var/lib/tftp/pxelinux.cfg/default
项目目标:安装服务器能够提供Centos和Centos7系统的安装
= =即把整个安装过程中要回答或者要做的事全部体现在应答文件中
- kickstart 安装选项: 包含语言、防火墙、密码、网络、分区的设置等;
- %Pre 部分:安装前解析的脚本,通常用来生成特殊的ks配置,比如由一段程序决定磁盘分区;
- %Package 部分:安装包的选择,可以是@base这样的组的形式,也可以是这样http-*包的形式;
- %Post 部分:安装后执行的脚本,通常用来做系统的初始化设置。比如启动的服务,相关的设定等。
方法二:使用system-config-kickstart生成
[[email protected] ~]# yum -y install system-config-kickstart
[[email protected] ~]# system-config-kickstart #大开kickstart图形化
最后生成的kickstar模版文件执行顺序会有问题需要手动修改
[[email protected] ftp]# vim /var/ftp/centos7.cfg
rootpw --iscrypted $1$GuFzhTpv$xitEUFXgs3A2hARRQotGR0
url --url="ftp://192.168.226.157/centos7u3"
auth --useshadow --passalgo=sha512
network --bootproto=dhcp --device=eth0
bootloader --append="net.ifnames=0 biosdevname=0" --location=mbr --md5pass="grub.pbkdf2.sha512.10000.F98A6EA56673779898A0F9B7EBAB11BB9D4B802E951C0A425AE32730F5772E277C6903D09CF6681678D44638432D43E140B85D1C4C22BB0D127B3FB4DC9CB924.EDA3747D05C4AB8FFA72E3B3D262606D9CA8F305A87E290E5B17BDA0BEC86EB0BBB95C2C5722834583F38D10EF9FFA640C866A6FA86A85F0C752D95C63CE5553"
part /boot --fstype="ext4" --size=1024
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
echo 123 |passwd --stdin alice
[[email protected] ~]# grub2-mkpasswd-pbkdf2
[[email protected] ftp]# vim /var/lib/tftpboot/pxelinux.cfg/default
menu label ^Install CentOS Linux 7
append initrd=initrd.img inst.stage2=ftp://192.168.226.157/centos7u3 inst.repo=ftp://192.168.226.157/centos7u3 inst.ks=ftp://192.168.226.157/centos7.cfg
配置文件和批量安装的脚本下载链接
https://download.csdn.net/download/weixin_45423952/12623661
注意事项:有些环境运行centos7.cfg需要注释掉自动安装软件的内容