PXE Centos7和Centos6

外网网卡:192.168.23.10, 内网网卡:192.168.10.2

 

 

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

 

 

  • 首先对于tftp服务的简要使用说明
1)yum安装:tftp、tftp-server
 
2)启动tftp
CentOS 6
service xinetd restart
chkconfig tftp on
CentOS 7
systemctl start tftp.socket
systemctl enable tftp.socket
 
3)服务器默认的站点目录
/var/lib/tftpboot
 
4)tftp服务端监听于udp的69端口
 
5)启动tftp服务
systemctl start tftp.socket
 
6)在/var/lib/tftpboot/里面放置一个文件/etc/inittab
cp /etc/inittab /var/lib/tftpboot
 
7)使用客户端tftp下载inittab文件
tftp 192.168.23.11
tftp> get inittab
 
8)退出tftp,查看当前目录是否有这个文件

 

 

  • 首先准备服务软件环境(DHCP服务、TFTP服务、httpd服务、syslinux包)(红帽7)
1)安装程序包,其中syslinux包提供 pxelinux.0 这个文件
yum install -y httpd dhcp tftp tftp-server syslinux
 
2)启动各服务
systemctl start dhcpd
systemctl start tftp.socket
systemctl start httpd
 
3)编辑DHCP服务配置文件/etc/dhcp/dhcpd.conf
 
# 指定DHCP区域的名称
option domain-name "uplooking.com";
 
# 指定默认网关
option routers 192.168.10.10;
 
# 指定 DNS服务器地址
option domain-name-servers 192.168.10.1;
 
# 指定DHCP服务的默认租约时长
default-lease-time 43200;
 
# 指定DHCP服务的最大租约时长
max-lease-time 84544;
 
# 指定日志文件的路径
log-facility local7;
 
# 设置DHCP服务的网络地址
subnet 192.168.10.0 netmask 255.255.255.0 {
 
# 指定连接主机的IP的范围
range 192.168.10.200 192.168.10.253;
 
# 指定主机无盘装机需要加载的文件
filename "pxelinux.0";
 
# 指定文件所在的主机IP
next-server 192.168.10.10;
 
}
 
 
4)准备yum仓库,拷贝内核文件,ramdisk文件
 
1:创建光盘挂载目录
mkdir -pv /var/www/html/centos/7/x86_64
 
2: 将centos7光盘挂载
mount -r /dev/cdrom /var/www/html/centos/7/x86_64/
 
3:创建kickstarts文件目录
mkdir /var/www/html/kickstarts
 
4:创建kickstarts文件
vi /var/www/html/kickstarts/centos7.cfg
 
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig --startxonboot
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=cn --xlayouts='cn'
# Root password
rootpw --iscrypted $1$93fLd53F$jqPGF7U7XOe3szIVqMcIl0
# System timezone
timezone Asia/Shanghai
# System language
lang en_US
# Firewall configuration
firewall --disabled
selinux --disabled
# System authorization information
auth --useshadow --passalgo=sha512
url --url="http://192.168.10.10/centos/7/x86_64/"
# Use graphical install 这里可以可以使用graphical
text
# Run the Setup Agent on first boot
firstboot --enable
 
ignoredisk --only-use=sda
# Network information
network --bootproto=dhcp --device=enp0s3
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=500
part /boot --fstype="xfs" --ondisk=sda --size=200
part / --fstype="xfs" --ondisk=sda --size=40259
 
# Reboot after installation
reboot
%packages
@base
@compat-libraries
@core
%end
5:将pxelinux.0文件拷贝到tpft的根目录下
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
 
6:拷贝引导内核所需文件,这里有专门为pxe引导的内核和ramdisk文件
cp /var/www/html/centos/7/x86_64/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
cp /usr/share/syslinux/{chain.c32,menu.c32,memdisk,mboot.c32} /var/lib/tftpboot/
 
7:创建显示菜单的默认配置文件
cd /var/lib/tftpboot/
mkdir pxelinux.cfg
vi default
 
8:default文件的内容为
default menu.c32
prompt 15
timeout 60
 
# 指定一个标题
MENU TITLE yhy PXE
 
# 指定第一个选项
LABEL linux
MENU LABEL Install CentOS 7 x86_64 manually
KERNEL vmlinuz
APPEND initrd=initrd.img inst.repo=http://192.168.10.10/centos/7/x86_64
 
# 指定第二个标题
# 这个引导选项是给定了ks文件的路径,并且给定了repodata的路径
LABEL linux auto
MENU LABEL Install CentOS 7 x86_64 automatically
KERNEL vmlinuz
APPEND initrd=initrd.img inst.repo=http://192.168.10.10/centos/7/x86_64 ks=http://192.168.10.10/kickstarts/centos7.cfg
 
 
 
 
 
 
 
 
 
 
  • 红帽6 PXE安装配置说明(为了让大家方便做实验,这里的路径没有改,直接将红帽6的光盘挂载到/var/www/html/centos/7/x86_64)
所有的安装服务都是一样的,只是拷贝的启动文件不一样,那么只需要将红帽6的光盘挂载到/var/www/html/centos/7/x86_64/目录下即可,在拷贝对应的文件
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /var/www/html/centos/7/x86_64/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
cp /var/www/html/centos/7/x86_64/isolinux/{boot.msg,vesamenu.c32,splash.png} /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/www/html/centos/7/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
  • 红帽6的/var/lib/tftpboot/pxelinux.cfg/default的内容为
default vesamenu.c32
#prompt 15
timeout 30
display boot.msg
menu background splash.jpg
menu title Welcome to yhy PXE
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
 
# 这里指定第一个选项,如果有第二个选项,还可以向后面添加
label linux
menu label ^Install CentOS 6 by YHY
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.10.10/kickstarts/centos6.cfg
  • 红帽 6中kickstart文件的内容为(为了让大家方便做实验,这里的路径没有改,直接将红帽6的光盘挂载到/var/www/html/centos/7/x86_64)
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use Network installation
url --url="http://192.168.10.10/centos/7/x86_64"
# Root password
rootpw --iscrypted $1$ZuMqItjw$Pne66twowNZBHdgzMLfoy/
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=200
part swap --fstype="swap" --size=500
part / --asprimary --fstype="ext4" --grow --size=6000
reboot
 
%packages
@base
@compat-libraries
@core
%end
posted @ 2017-09-09 20:10  ~小学生~  阅读(255)  评论(0编辑  收藏  举报