pex+http+kickstart

图片 3

图片 1

 

1、说明

所谓的PXE是Preboot Execution
Environment的缩写,字面上的情趣是开机前的实行遇到。

要兑现pxe,最少需求3个劳务

图片 2

 

2、流程

图片 3

 注意:全体用的udp封装

 1卡塔尔client向pxe
server上的dhcp发送IP地址乞求音讯,dhcp检查测量试验client是或不是合法,同事将pxe情况下的boot
loader文件pxelinux.0的职位新闻发放client

 2卡塔尔国client向pxe
server上的tftp须要pxelinux.0,tftp收到新闻向client发送pxelinux.0大小消息,试探client是不是满意,当tftp收到client发回的统第一次全国代表大会小音讯后,发送pxelinux.0.

 3卡塔 尔(阿拉伯语:قطر‎client实施选用到的pxelinux.0

 4卡塔 尔(阿拉伯语:قطر‎client向TFTP乞请pxelinux.cfg文件(其实是目录,里面放了开发银行菜单,即grub的配备文件卡塔 尔(阿拉伯语:قطر‎,TFTP将配置文件发回client,进而client依据布置文件试行后续的操作

 5卡塔 尔(阿拉伯语:قطر‎client向TFTP发送linux内核诉求音讯,TFTP发送内核

 6卡塔 尔(英语:State of Qatar)client向TFTP发送根文件乞请新闻,TFTP采取到新闻随后回来linux根文件系统

 7卡塔 尔(阿拉伯语:قطر‎client加载linux内核(运营参数已经在4中的配置文件中设置好了卡塔 尔(英语:State of Qatar)。

 8卡塔尔国client通过nfs/ftp/http下载系统安装文件进行设置,固然4中的配置文件钦赐了kickstart路径,则回遵照此文件自动回复安装系统

 

多少个公文的验证

  • vmlinuz:大旨文件(kernel file);
  • initrd.img:开启进度中基本组件的参数;
  • isolinux.cfg –> demo:开机pxe选拔参谋;

3、部署

顺序

DHCP

TFTP

提供bootloader及布署文件

挂载光盘,把基本文件cp到tftp目录

配备httpd,并放置文件

安装菜单及提供系统安装文件

3.1部署DHCP

  yum -y install 
  dhcp[root@localhost ~]# cat /etc/dhcp/dhcpd.con

default-lease-time 600;
max-lease-time 7200;
subnet 192.168.216.0 netmask 255.255.255.0 {
  range dynamic-bootp 192.168.216.220 192.168.216.230;
  option domain-name-servers 192.168.216.147;
  option subnet-mask 255.255.255.0;
  option routers 192.168.216.147;
  default-lease-time 600;
  max-lease-time 7200;  
  next-server 192.168.216.147;      ###这个就是tftp地址
  filename"pxelinux.0";          ###告知从tftp根目录获取bootloader文件

}

host clientA{                        ###可以绑定某台主机的ip地址,用mac绑定
        hardware ethernet 00:0C:29:83:A2:10;      
        fixed-address 192.168.216.229;
}
ddns-update-style interim;

    运行服务

  systemctl start dhcpd

3.2部署TFTP
  从流程得知boot loader文件pxelinux.0以及内核相关的配置文件(目录pxelinux.cfg下)主要都是由TFTP来提供的

  yum install tftp-server
  yum -y install xinetd
  TFTP是由xinetd这个super daemon所管理的,因此设定好TFTP之后,要启动的是xinetd;

[root@localhost ~]# cat /etc/xinetd.d/tftp 
# default: off
# 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.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot  ###这个是tftp的根目录
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

  启动tftp

  systemctl start tftp

  查看服务ps -ef |grep xinetd

[root@localhost tftpboot]# ps -ef |grep xinetd
root      49896      1  0 Aug29 ?        00:00:00 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
root      61791  49577  0 16:15 pts/0    00:00:00 grep --color=auto xinetd

  ss -unlp

  查看一下端口是不是监听端口是69

3.3提供bootloader及配置文件

  yum -y install syslinux

   需要使用CentOS提供的syslinux包,从中copy几个文件

  cp -a /usr/share/syslinux/{menu.c32,vesamenu.c32,pxelinux.0} /var/lib/tftpboot

  

[root@localhost tftpboot]# ll 
total 47964
-rw-r--r-- 1 root root       84 Sep 21  2017 boot.msg
-rw-r--r-- 1 root root    20704 Sep 20  2017 chain.c32
-rw-r--r-- 1 root root      501 Sep 20  2017 fstab
-rw-r--r-- 1 root root 43372552 Sep 20  2017 initrd.img
-rw-r--r-- 1 root root    33628 Sep 20  2017 mboot.c32
-rw-r--r-- 1 root root    26140 Sep 20  2017 memdisk
-rw-r--r-- 1 root root    55012 Sep 20  2017 menu.c32      #图形化菜单
-rw-r--r-- 1 root root    26764 Sep 20  2017 pxelinux.0     #bootloader
drwxr-xr-x 2 root root       21 Aug 29 18:34 pxelinux.cfg    #开机菜单设定
-rw-r--r-- 1 root root      186 Sep 21  2017 splash.png
-rw-r--r-- 1 root root   152976 Sep 21  2017 vesamenu.c32    #也是图形菜单
-rwxr-xr-x 1 root root  5392080 Sep 20  2017 vmlinuz

 注意:pxelinux.cfg是个目录,能够放置私下认可的开机选项,也足以针对不相同的顾客端主机提供分裂的开机选项。能够在pxelinux.cfg目录内创设叁个名字为default的文件来提供暗中同意选项。

3.4部署http服务

yum install -y httpd

mkdir /media/cdrom

mount -r /dev/cdrom /media/cdrom

mount –bind /media/cdrom/ /var/www/html/centos7

3.4挂载光盘,把底子文件cp到tftpmulu

 cd /var/www/html/centos7

cp isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

cp images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot

cp isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/

 

3.5装置菜单及提供系统安装文件

[root@localhost pxelinux.cfg]# cat default 
default menu.c32   #这个必须有也可以使用vesamenu.c32
prompt 1
timeout 10       #超时时间

menu title ########## PXE Boot Menu ##########

label 1
menu label ^1) Install CentOS 7 x64 with Local Repo    #菜单文字
menu default                         #表示开机光标一开始停留在label上 
kernel vmlinuz                          #内核文件路径,相对路径是从/tftpboot开始的
append initrd=initrd.img inst.repo=http://192.168.216.147/centos7   #内核启动选项,其中initrd的路径,还有其他的stage2文件,
ks=http://192.168.216.147/ks.cfg              #指定kickstart路径  

 

 那样就实现了安顿,接下去开启个劳务,并开机自启

 systemctl restart dhcpd.service

systemctl restart xinetd.service

systemctl restart tftp.socket

systemctl restart tftp.service

systemctl restart httpd.service

 

systemctl enable dhcpd.service

systemctl enable xinetd.service

systemctl enable tftp.service

systemctl  enable httpd.service

 

4、kickstart达成无人值班守护批量安装(不完全都以无人卡塔 尔(阿拉伯语:قطر‎

cp -a ~/anaconda-ks.cfg /var/www/html/ks.cfg

chmod +r /var/www/html/ks.cfg  #使全局可读

cd /var/www/html/

[root@localhost html]# cat ks.cfg
#version=DEVEL
# System authorization information
auth --useshadow --enablemd5
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.216.147/centos7"
# Use graphical install
graphical
# Firewall configuration
firewall --enabled
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=link
network  --hostname=localhost.localdomain
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$uH$aaWTA7AmvIxGMidj0sp.u1
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# X Window System configuration information
xconfig  --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=300
part swap --fstype="swap" --size=3841
part / --fstype="xfs" --size=57298

%post
/usr/sbin/adduser zhangxingeng
/usr/sbin/usermod -p '$1$uH$aaWTA7AmvIxGMidj0sp.u1' zhangxingeng
/usr/bin/chfn -f "centos-7-64" zhangxingeng
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.00
echo '#!/bin/bash' > /etc/rc.d/rc.local
ln -s ../rc.local /etc/rc.d/rc5.d/S99rclocal
chmod 755 /etc/rc.d/rc.local
echo 'mkdir -p /var/log/vmware' >> /etc/rc.d/rc.local
echo 'exec 1> /var/log/vmware/rc.local.log' >> /etc/rc.d/rc.local
echo 'exec 2>&1' >> /etc/rc.d/rc.local
echo 'set -x' >> /etc/rc.d/rc.local
echo 'echo Installing Open VM Tools' >> /etc/rc.d/rc.local
echo 'set -x' >> /etc/rc.d/rc.local
echo '/bin/eject sr0 || /bin/true' >> /etc/rc.d/rc.local
echo '/bin/eject sr1 || /bin/true' >> /etc/rc.d/rc.local
echo '/bin/vmware-rpctool' 'guest.upgrader_send_cmd_line_args --default' >> /etc/rc.d/rc.local
echo '/bin/vmware-rpctool' 'upgrader.setGuestFileRoot /tmp' >> /etc/rc.d/rc.local
echo '/bin/vmware-rpctool' 'toolinstall.installerActive 1' >> /etc/rc.d/rc.local
echo '/bin/vmware-rpctool' 'toolinstall.installerActive 100' >> /etc/rc.d/rc.local
echo 'rm -f /etc/rc.d/rc.local' >> /etc/rc.d/rc.local
echo 'rm -f /etc/rc.d/rc5.d/S99rclocal' >> /etc/rc.d/rc.local
echo 'mv /etc/rc.d/rc.local.00 /etc/rc.d/rc.local' >> /etc/rc.d/rc.local
/bin/echo done
%end

%packages
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@print-client
@x11
binutils
ftp
gcc
kernel-devel
kexec-tools
make
open-vm-tools
patch
python

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end
[root@localhost html]# 

  

 

先到此地,本着学习的神态,只是为着熟知一下总体pxe流程,本文仿照效法