所谓的PXE是Preboot Execution Environment的缩写,字面上的意思是开机前的执行环境。html
要实现pxe,至少须要3个服务java
注意:所有用的udp封装python
1)client向pxe server上的dhcp发送IP地址请求消息,dhcp检测client是否合法,同事将pxe环境下的boot loader文件pxelinux.0的位置信息发给clientlinux
2)client向pxe server上的tftp请求pxelinux.0,tftp收到消息向client发送pxelinux.0大小信息,试探client是否满意,当tftp收到client发回的统一大小信息后,发送pxelinux.0.redis
3)client执行接收到的pxelinux.0centos
4)client向TFTP请求pxelinux.cfg文件(实际上是目录,里面放了启动菜单,即grub的配置文件),TFTP将配置文件发回client,继而client根据配置文件执行后续的操做bash
5)client向TFTP发送linux内核请求信息,TFTP发送内核app
6)client向TFTP发送根文件请求信息,TFTP接受到消息以后返回linux根文件系统less
7)client加载linux内核(启动参数已经在4中的配置文件中设置好了)。dom
8)client经过nfs/ftp/http下载系统安装文件进行安装,若是4中的配置文件指定了kickstart路径,则回根据此文件自动应答安装系统
几个文件的说明
顺序
DHCP
TFTP
提供bootloader及配置文件
挂载光盘,把内核文件cp到tftp目录
部署httpd,并放置文件
设置菜单及提供系统安装文件
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的文件来提供默认选项。
yum install -y httpd
mkdir /media/cdrom
mount -r /dev/cdrom /media/cdrom
mount --bind /media/cdrom/ /var/www/html/centos7
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/
[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
四、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流程,本文参考:http://www.cnblogs.com/f-ck-need-u/p/7342919.html