PXE
PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工做于Client/Server的网络模式,支持工做站经过网络从远端服务器下载映像,并由此支持经过网络启动操做系统,在启动过程当中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户端)基本软件设置,从而引导预先安装在服务器中的终端操做系统。
PXE工做原理html
环境搭建
三台虚拟机,一台预装centos系统,另外两台建立空机器就好(安装centos7的机器最好配置1.5g以上内存),selinux关闭,iptables规则清空。
软件需求
system-config-kickstart 图形化的工具,生成kickstart文件(要求图形界面centos6和7的有必定区别,最好使用两台有图形的机器去生成kickstart文件)
dhcp 搭建dhcp服务器给空白机器提供ip地址以便后续的系统部署
tftp 提供基础系统引导文件
httpd或者ftp提供软件包和kickstart文件的存储和支持网络访问
syslinux 提供pxelinux.0文件
kickstart文件生成
首先安装kickstart图形化工具linux
yum install system-config-kickstart -y #我这里已经装过了就再也不重复安装了
安装完成后在终端输入算法
system-config-kickstart
6和7这个程序的界面基本相同。
由于提供了中文,所以就不在过多截图和说明。跟着指示一步一步选择便可,所有选择完成后能够选择“文件”进行保存。centos
kickstart文件的结构分析
centos6服务器
#platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade 指明是安装系统仍是升级系统 install # Use network installation 使用网络安装系统,指明包安装路径 url --url="http://192.168.99.150/centos/6" # Root password 设定root密码 rootpw --iscrypted $1$83EH4TBr$Q.b9cbOc79IC4aXYbCO3A0 # System authorization information 密钥加密算法启用shadow文件 auth --useshadow --passalgo=sha512 # Use text mode install 使用文本模式或者图形模式安装系统 text # System keyboard 键盘设定 keyboard us # System language 语言设定 lang en_US # SELinux configuration selinux是否关闭 selinux --disabled # Do not configure the X Window System 是否安装图形界面 skipx # Installation logging level 日志级别 logging --level=info # Reboot after installation 声明安装完成后重启系统 reboot # System timezone 设置时区(能够改为亚洲上海) timezone Africa/Abidjan # System bootloader configuration 设定BootLoader bootloader --location=mbr # Clear the Master Boot Record 清除mbr记录 zerombr # Partition clearing information 清除所有分区 clearpart --all --initlabel # Disk partitioning information 分区设定 part /boot --fstype="ext4" --size=200 part / --fstype="ext4" --size=16000 part swap --fstype="swap" --grow --size=2048 %packages 安装的包设定(这里仅仅最小化安装) @core
centos7网络
#platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$/oxkHD8i$x9g6m.ghBq2L3Vz6ENY7i0 # Use network installation url --url="http://192.168.99.150/centos/7" # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Firewall configuration firewall --disabled # Reboot after installation reboot # System timezone timezone Africa/Abidjan # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="xfs" --size=200 part / --fstype="xfs" --size=16000 part swap --fstype="swap" --grow --size=2048 %packages 安装包选项最小化安装 7在选择完包以后要添加%end表示结束 @^minimal %end
1.安装dhcpapp
yum install dhcp -y
2.建立dhcp地址段配置文件,安装dhcp以后会默认生成示例文件,只要对示例文件进行简单修改便可使用。ide
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
3.修改文件,添加如下字段工具
subnet 192.168.99.0 netmask 255.255.255.0 { #设定分配的子网和掩码 range 192.168.99.160 192.168.99.200; #设定地址范围 option subnet-mask 255.255.255.0; #设定掩码 option routers 192.168.99.150; #指定网关地址 default-lease-time 86400; #设定租约期,不设定话默认是全局时间 max-lease-time 864000; #最大租约期,不设定继承全局 next-server 192.168.99.150; #指定下一个服务器地址,用来指明提供ftp或者http服务的地址 filename "pxelinux.0"; }
4.启动服务而且设定开机启动加密
chkconfig dhcpd on service dhcpd start #centos 7 使用systemctl enable dhcpd systemctl start dhcpd
地址分配记录,新配置的应该不会有记录这里是实验完成后的记录。
/var/lib/dhcpd/dhcpd.leases
1.经过yum方式安装httpd而且开机启动
yum install httpd -y chkconfig httpd on #centos7 #systemctl enable httpd
2.建立相应目录挂载光盘文件(使用两个光驱挂载以便节省磁盘空间)以及存放ks文件。要注意权限,最好在挂载完成后在宿主机网页访问一下。
mkdir -pv /var/www/html/centos/{6,7,ks} mount /dev/sr0 /var/www/html/centos/6/ mount /dev/sr1 /var/www/html/centos/7/ mv centos6.cfg centos7.cfg /var/www/html/ks/ #以前准备好的ks文件均为最小化安装
1.安装tftp服务而且配置开机启动
yum install tftp-server -y chkconfig tftp on chkconfig xinetd on (centos 6 tftp由xinetd管理) #centos7 # systemctl enable tftp
2.准备相关的启动文件及目录
mkdir /var/lib/tftpboot/pxelinux.cfg mkdir -pv /var/lib/tftpboot/centos{6,7} cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ cp /var/www/html/centos/6/isolinux/vesamenu.c32 /var/lib/tftpboot/ cp /var/www/html/centos/6/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6/ cp /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/ cp /var/www/html/centos/6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
3.修改default菜单文件
#仅仅修改label字段 label linux7 menu label Install centos^7 kernel centos7/vmlinuz #因为是多版本部署因此要指明对应的路径 append initrd=centos7/initrd.img text ks=http://192.168.99.150/centos/ks/centos7.cfg label linux6 menu label Install centos^6 kernel centos6/vmlinuz append initrd=centos6/initrd.img text ks=http://192.168.99.150/centos/ks/centos6.cfg
1.重启httpd dhcpd xinetd服务
service httpd restart service dhcpd restart service xinetd restart #centos7使用systemctl命令重启服务,centos7再也不使用xinetd管理tftp服务 #systemctl restart tftp
2.验证服务端口是否正常启动
ss -tunlp
3.配置3台主机都到vmnat2段
4.启动2台空白虚拟机分别安装centos6和centos7
5.静静等待安装完成
centos6
centos7
.
实验进行基本顺利,感受对pxe过程的中的坑有了比较详细的了解,下篇会继续pxe的进阶cobbler的配置。