pex+http+kickstart
1、说明
所谓的pxe是preboot execution environment的缩写,字面上的意思是开机前的执行环境。
要实现pxe,至少需要3个服务
2、流程
注意:全部用的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)client向tftp发送根文件请求信息,tftp接受到消息之后返回linux根文件系统
7)client加载linux内核(启动参数已经在4中的配置文件中设置好了)。
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流程,本文参考:
上一篇: jQuery中is()方法用法实例教程