首页 > 其他 > 详细

pxe+kickstart进行多版本系统安装

时间:2018-05-27 00:55:32      阅读:347      评论:0      收藏:0      [点我收藏+]
背景

PXE
  PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户端)基本软件设置,从而引导预先安装在服务器中的终端操作系统。
  
PXE工作原理
技术分享图片

实验流程

前提

环境搭建
  三台虚拟机,一台预装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图形化工具

        yum install system-config-kickstart -y
        #我这里已经装过了就不再重复安装了

技术分享图片
  安装完成后在终端输入

    system-config-kickstart

技术分享图片
  6和7这个程序的界面基本相同。
  因为提供了中文,因此就不在过多截图和说明。跟着指示一步一步选择即可,全部选择完成后可以选择“文件”进行保存。

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

服务搭建

DHCP构建

  1.安装dhcp

    yum install dhcp -y 

技术分享图片
  2.创建dhcp地址段配置文件,安装dhcp之后会默认生成示例文件,只要对示例文件进行简单修改即可使用。

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

技术分享图片

配置httpd服务提供包的安装和kickstart文件

  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文件均为最小化安装

技术分享图片

配置tftp服务并且准备启动文件

  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的配置。

pxe+kickstart进行多版本系统安装

原文:http://blog.51cto.com/11010461/2120693

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!