pxe预启动执行环境

一、简述

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

1、安装

[root@server ~]# yum install httpd dhcp tftp-server syslinux -y
Loaded plugins: langpacks
rhel_dvd                                                 | 4.1 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
---> Package syslinux.x86_64 0:4.05-8.el7 will be installed
---> Package tftp-server.x86_64 0:5.2-11.el7 will be installed
--> Processing Dependency: xinetd for package: tftp-server-5.2-11.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package xinetd.x86_64 2:2.3.15-12.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch          Version                 Repository       Size
================================================================================
Installing:
 dhcp               x86_64        12:4.2.5-27.el7         rhel_dvd        506 k
 httpd              x86_64        2.4.6-17.el7            rhel_dvd        1.2 M
 syslinux           x86_64        4.05-8.el7              rhel_dvd        1.0 M
 tftp-server        x86_64        5.2-11.el7              rhel_dvd         44 k
Installing for dependencies:
 apr                x86_64        1.4.8-3.el7             rhel_dvd        103 k
 apr-util           x86_64        1.5.2-6.el7             rhel_dvd         92 k
 httpd-tools        x86_64        2.4.6-17.el7            rhel_dvd         77 k
 mailcap            noarch        2.1.41-2.el7            rhel_dvd         31 k
 xinetd             x86_64        2:2.3.15-12.el7         rhel_dvd        128 k

Transaction Summary
================================================================================
Install  4 Packages (+5 Dependent packages)

Total download size: 3.1 M
Installed size: 8.3 M
Downloading packages:
(1/9): apr-1.4.8-3.el7.x86_64.rpm                          | 103 kB   00:00     
(2/9): apr-util-1.5.2-6.el7.x86_64.rpm                     |  92 kB   00:00     
(3/9): dhcp-4.2.5-27.el7.x86_64.rpm                        | 506 kB   00:00     
(4/9): httpd-2.4.6-17.el7.x86_64.rpm                       | 1.2 MB   00:00     
(5/9): httpd-tools-2.4.6-17.el7.x86_64.rpm                 |  77 kB   00:00     
(6/9): mailcap-2.1.41-2.el7.noarch.rpm                     |  31 kB   00:00     
(7/9): syslinux-4.05-8.el7.x86_64.rpm                      | 1.0 MB   00:00     
(8/9): tftp-server-5.2-11.el7.x86_64.rpm                   |  44 kB   00:00     
(9/9): xinetd-2.3.15-12.el7.x86_64.rpm                     | 128 kB   00:00     
--------------------------------------------------------------------------------
Total                                               12 MB/s | 3.1 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                                       1/9 
  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/9 
  Installing : httpd-tools-2.4.6-17.el7.x86_64                              3/9 
  Installing : mailcap-2.1.41-2.el7.noarch                                  4/9 
  Installing : 2:xinetd-2.3.15-12.el7.x86_64                                5/9 
  Installing : tftp-server-5.2-11.el7.x86_64                                6/9 
  Installing : httpd-2.4.6-17.el7.x86_64                                    7/9 
  Installing : 12:dhcp-4.2.5-27.el7.x86_64                                  8/9 
  Installing : syslinux-4.05-8.el7.x86_64                                   9/9 
  Verifying  : 2:xinetd-2.3.15-12.el7.x86_64                                1/9 
  Verifying  : httpd-2.4.6-17.el7.x86_64                                    2/9 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                  3/9 
  Verifying  : apr-1.4.8-3.el7.x86_64                                       4/9 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  5/9 
  Verifying  : httpd-tools-2.4.6-17.el7.x86_64                              6/9 
  Verifying  : syslinux-4.05-8.el7.x86_64                                   7/9 
  Verifying  : 12:dhcp-4.2.5-27.el7.x86_64                                  8/9 
  Verifying  : tftp-server-5.2-11.el7.x86_64                                9/9 

Installed:
  dhcp.x86_64 12:4.2.5-27.el7           httpd.x86_64 0:2.4.6-17.el7             
  syslinux.x86_64 0:4.05-8.el7          tftp-server.x86_64 0:5.2-11.el7         

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                 apr-util.x86_64 0:1.5.2-6.el7       
  httpd-tools.x86_64 0:2.4.6-17.el7        mailcap.noarch 0:2.1.41-2.el7       
  xinetd.x86_64 2:2.3.15-12.el7           

Complete!
httpd        ##共享安装资源
dhcp        ##分配ip以及让客户主机获取pxelinux.0文件,当系统还没有安装时,没有ip地址,只能通过服务端的dhcp服务被动获取信息,服务端dhcp服务器向外界发送的不只动态ip,还有pex相关信息
tftp-server    ##提供tftp协议,令客户主机可以读取到预安装环境

syslinux    ##提供pxelinux.0文件(预安装环境头文件,用来指定读取后续文件的程序



服务准备

 1.httpd打开

[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld.service 
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[root@server ~]# systemctl start httpd
[root@server ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

2.启用tftp服务

[root@server ~]# vim /etc/xinetd.d/tftp
[root@server ~]# systemctl restart xinetd
[root@server ~]# 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
    disable            = on
    per_source        = 11
    cps            = 100 2
    flags            = IPv4
}

3、启动dhcp服务

[root@server ~]# vim /etc/dhcp/dhcpd.conf 
[root@server ~]# systemctl start dhcpd
[root@server ~]# systemctl enable dhcpd
ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'
[root@server ~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
option domain-name "example.com";
option domain-name-servers 114.114.114.114; 
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 172.25.254.0 netmask 255.255.255.0 {    
  range 172.25.254.2 172.25.254.5;    
  option routers 172.25.254.66;    
  filename "pxelinux.0";        
  next-server 172.25.254.66;      

设定共享文件

制作安装源
mkdir  /var/www/html/rhel7.0
mkdir  /iso
mv /root/rhel-server-7.0-x86_64-dvd.iso  /iso/
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0/
vim /etc/rc.d/rc.local
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0/

chmod +x /etc/rc.d/rc.local

制作预安装环境
cp /var/www/html/rhel7.0/isolinux/*  /var/lib/tftpboot/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
systemctl restart xinetd

设定自动化部署
yum install system-conifig-kickstart
system-config-kickstart        ---->/var/www/html/rhel7.0.cfg

vim /var/lib/tftpboot/pxelinux.cfg/default

label autoinstall    ##选项标签
  menu label ^Autoinstall RHEL7.0    ##标题
  kernel vmlinuz            ##启动的内核文件

  append initrd=initrd.img repo=http://172.25.254.100/rhel7.0 ks=http://172.25.254.100/rhel7.0.cfg

[root@foundation41 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 
[root@foundation41 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default 
default vesamenu.c32
timeout 200

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title PXE LINUX !!!!!!!!!!!!!
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label ^PXE INSTALL REDHAT 7.0
  kernel vmlinuz
  append initrd=initrd.img repo=http://172.25.254.41/rhel7.0 ks=http://172.25.254.41/rhel7.0.cfg

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.0
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install Red Hat Enterprise Linux 7.0 in ^basic graphics mode
  text help
	Try this option out if you're having trouble installing
	Red Hat Enterprise Linux 7.0.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a Red Hat Enterprise Linux system
  text help
	If the system will not boot, this lets you access files
	and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rescue quiet

label memtest
  menu label Run a ^memory test
  text help
	If your system is having issues, a problem with your
	system's memory may be the cause. Use this utility to
	see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

label local
  menu label Boot from ^local drive
  localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
  menu label Return to ^main menu
  menu exit

menu end



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值