CentOS 7下PXE+Kickstart无人值守安装centos7

CentOS 7下PXE+Kickstart无人值守安装操作系统

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

PXE的工作过程:

  1. PXE Client 从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP;
  2. DHCP 服务器返回分配给客户机的IP 以及PXE文件的放置位置(该文件一般是放在一台TFTP服务器上) ;
  3. PXE Client 向本网络中的TFTP服务器索取pxelinux.重点内容0 文件;
  4. PXE Client 取得pxelinux.0 文件后之执行该文件;
  5. 根据pxelinux.0 的执行结果,通过TFTP服务器加载内核和文件系统 ;
  6. 进入安装画面, 此时可以通过选择HTTP、FTP、NFS 方式之一进行安装;
    这里写图片描述
    2 什么是Kickstart:
    Kickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为ks.cfg的文件。如果在安装过程中(不只局限于生成Kickstart安装文件的机器)出现要填写参数的情况,安装程序首先会去查找Kickstart生成的文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便需要安装者手工干预了。所以,如果Kickstart文件涵盖了安装过程中可能出现的所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启系统,并结束安装。

PXE+Kickstart 无人值守安装操作系统完整过程如下:
这里写图片描述
#二 系统环境
实验环境:VMware Workstation 14
系统平台:CentOS-7-x86_64最小安装
网络模式:仅主机模式

#三 准备工作:
创建光盘挂载点并挂载iOS镜像
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
#四 安装vsftp
yum --disablerepo=* --enablerepo=c7-media install vsftpd -y
将光盘上所有文件拷贝到 /var/ftp 目录下
启动FTP服务
service vsftpd start
systemctl enable vsftpd
#五 安装配置tftp-server
安装tftp-server
yum --disablerepo=* --enablerepo=c7-media install tftp-server -y
安装后配置TFTP
vim /etc/xinetd.d/tftp
具体配置如下图所示
这里写图片描述
启动tftp服务
systemctl start tftp.socket
systemctl enable tftp.socket
#六 配置支持PXE的启动程序
**# yum install syslinux -y
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

说明:syslinux是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX是一个小型的Linux操作系统,它的目的是简化首次安装Linux的时间,并建立修护或其它特殊用途的启动盘
[root@localhost yum.repos.d]# cp /media/cdrom/images/pxeboot/vmlinuz /var/lib/tftpboot
[root@localhost yum.repos.d]# cp /media/cdrom/images/pxeboot/initrd.img /var/lib/tftpboot
[root@localhost isolinux]# cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@localhost pxelinux.cfg]# vim default
编辑如下:

   default linux
   timeout 6
   
   
   label linux
     menu label ^Install CentOS 7
     kernel vmlinuz
     append initrd=initrd.img quiet ks=ftp://192.168.159.132/ks.cfg
   

#七 安装并配置DHCP
yum --disablerepo=* --enablerepo=c7-media install dhcp -y
配置如下:

   #
   # DHCP Server Configuration file.
   #   see /usr/share/doc/dhcp*/dhcpd.conf.example
   #   see dhcpd.conf(5) man page
   # dhcpd.conf
   #
   # Sample configuration file for ISC dhcpd
   #
   
   # option definitions common to all supported networks...
  
   default-lease-time 600;
   max-lease-time 7200;
  
   # Use this to enble / disable dynamic dns updates globally.
   #ddns-update-style none;
  
   # If this DHCP server is the official DHCP server for the local
   # network, the authoritative directive should be uncommented.
   #authoritative;
  
   # Use this to send dhcp log messages to a different log file (you also
   # have to hack syslog.conf to complete the redirection).
   log-facility local7;
  
   # No service will be given on this subnet, but declaring it helps the 
   # DHCP server to understand the network topology.
   # This is a very basic subnet declaration.
   
   subnet 192.168.159.0 netmask 255.255.255.0 {
     range 192.168.159.100 192.168.159.130;       #地址池
     filename "pxelinux.0";
     next-server 192.168.159.132;
     option routers 192.168.2.1;
   }                                                                

启动DHCP服务
service dhcpd restart

#八 编写bash文件将获得的动态IP地址等动态信息设为静态
代码如下:

  #!/bin/bash
  # get ip address,subnet mask,default gateway
  address=`ifconfig |grep inet|head -n 1 |awk '{print $2}'`
  mask=`ifconfig |grep -i netmask |head -n 1|awk '{print $4}'`
  gateway=`route -n|grep -i ug |awk '{print $2}'`
  lastnum=${address##*.}
  #modify hostname
  echo "node$lastnum.a.com" >/etc/hostname
  #modify network parms
  echo -e "DEVICE=ens33\nONBOOT=yes\nBOOTPROTO=static\nIPADDR=$address\nNETMASK=$mask\nGATEWAY=$gateway" >/etc/sysco    nfig/network-scripts/ifcfg-ens33

#九 制作kickstart文件:
安装system-config-kickstart
yum --disablerepo=* --enablerepo=c7-media install system-config-kickstart -y
添加变量
export DISPLAY=192.168.159.1:0.0
执行
system-config-kickstart

设置语言,键盘,时区,Root密码,安装完毕后重启等

这里写图片描述
设置安装方式,这篇文章介绍的是FTP方式的安装,故选择FTP
这里写图片描述
安装MBR,保持默认
这里写图片描述

设置分区
这里写图片描述
配置网络
这里写图片描述
认证配置 SELinux 和防火墙配置 图形环境配置保持默认

但是软件包选择会出现问题如下图所示
这里写图片描述
解决办法如下
将/etc/yum.repos.d目录下除CentOS-Media.repo文件的所有文件移动到当前目录下的一个新文件夹里并编辑CentOS-Media.repo 如图所示
这里写图片描述

然后就可以根据自己的需要选择相应的工具包了

将(八)编写的bash文件中出第一行的所有代码复制到安装后脚本如下图
这里写图片描述

最后将文件保存在根目录下

这里写图片描述

我们可以打开根下的ks.cfg 文件进行查看并做修改

  #platform=x86, AMD64, or Intel EM64T   #version=DEVEL
  # Install OS instead of upgrade
  install
  # Keyboard layouts   keyboard 'us'
  # Root password
  rootpw --iscrypted $1$eqKpjocv$EPrznR9cZ4ByaRVw/qnzR1
  # Use network installation
  url --url="ftp://192.168.159.132/"  #这个选项告诉安装程序:到服务器根目录下寻找安装介质
  # System language
  lang en_US
  # Firewall configuration
  firewall --disabled
  # System authorization information
  auth  --useshadow  --passalgo=sha512
  # Use text mode install
  text
  # SELinux configuration
  selinux --enforcing
  # Do not configure the X Window System
  skipx
  
  # Network information
  network  --bootproto=dhcp --device=ens33
  # Halt after installation
  poweroff
  # System timezone
  timezone Asia/Shanghai
  # System bootloader configuration
  bootloader --append="quiet" --location=mbr
  # Clear the Master Boot Record
  zerombr
  # Partition clearing information
  clearpart --all --initlabel
  # Disk partitioning information
  part /boot --fstype="xfs" --size=512
  part / --fstype="xfs" --size=15000
  part swap --fstype="swap" --size=512
  
  %post --interpreter=/bin/bash
  # get ip address,subnet mask,default gateway
  address=`ifconfig |grep inet|head -n 1 |awk '{print $2}'`
  mask=`ifconfig |grep -i netmask |head -n 1|awk '{print $4}'`
  gateway=`route -n|grep -i ug |awk '{print $2}'`
  lastnum=${address##*.}
  #modify hostname
  echo "node$lastnum.a.com" >/etc/hostname
  #modify network parms
  echo -e "DEVICE=ens33\nONBOOT=yes\nBOOTPROTO=static\nIPADDR=$address\nNETMASK=$mask\n" >/etc/sysconfig/network-scr    ipts/ifcfg-ens33
  route -n|grep -i ug && echo "GATEWAY=$gateway" >>/etc/sysconfig/network-scripts/ifcfg-ens33
  %end
  
  %packages
  @development
  @system-admin-tools
  
  %end

然后将根下的ks.cfg拷贝到/var/ftp
#十 测试安装
新建一台虚拟机然后启动就开始自己安装了
登录系统查看,磁盘分区和我们在ks.cfg 文件中设定的一样
这里写图片描述

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝色的夏天qy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值