当前位置: > CentOS > CentOS入门 >

Centos 7 系统下使用PXE网络的方式(pxe+dhcpd+tftp+httpd)安装操作系统

时间:2016-12-29 22:57来源:linux.it.net.cn 作者:IT
Centos 7 系统下使用PXE网络的方式(pxe+dhcpd+tftp+httpd)安装操作系统



PXE(Pre-boot Execution Environment)是由Intel设计的协议,它可以使计算机通过网络而不是从本地硬盘、光驱等设备启动。

现代的网卡,一般都内嵌支持PXE的ROM芯片。当计算机引导时,BIOS把PXE client调入内存执行,并显示出命令菜单,

经用户选择后,PXE client将放置在远端的操作系统通过网络下载到本地运行。

 

>>>>>>这里笔者将PXE网络安装Centos 7的方法记录如下,首先服务端(Centos 7)的需要准备的环境如下:

操作系统镜像:CentOS-7-x86_64-DVD-1503-01.iso    //解压到/var/www/html/cento目录

dhcpd服务的安装与配置:可参考《关于linux - Centos 7 下DHCP服务的安装与配置》

tftp服务的安装与配置:可参考《linux-Centos 7下tftp-server服务的安装与配置》

如连接失效,可到笔者博客网:http://www.cnblogs.com/5201351进行查找

===========================================================================

1、除了如上环境,我们还需要安装httpd服务,再到httpd默认的根目录下创建centos目录,并将系统镜像挂载于此

[root@5201351 ~]# yum install httpd -y
[root@5201351 ~]# mkdir /var/www/html/centos
[root@5201351 ~]# mount CentOS-7-x86_64-DVD-1503-01.iso /var/www/html/centos

2、使用yum的方式安装syslinux软件包,安装此软件包的目录主要是为了获取对PXE网络安装有用的pxelinux.0文件

     安装syslinux软件包后,我们需要将pxelinux.0文件复制到tftp默认的根目:/var/lib/tftpboot

[root@5201351 ~]# yum install syslinux  -y
[root@5201351 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/   //pxelinux.0,是一个bootloader,类似于grub,通过它来load kernel

3、接下来就是准备tftp的根目录中,主要是将系统镜像中的文件放入tftp的根目录,除了default文件,其他全部放置在tftp根目录

[root@5201351 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
#########################################################################################
[root@5201351 ~]# cd /var/www/html/centos
[root@5201351 centos]# cp isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@5201351 centos]# cp images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
[root@5201351 centos]# cp isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/

这时,我们可以看到/var/lib/tftpboot目录的结构如下:

============================================================================

4、接下来就是配置pxelinux.cfg/default文件,这里我们可以只是简单的修改append initrd项的值

label linux
  menu label ^Install CentOS 7
  menu default                                                                //设置此项后,刚这个菜单为默认的选中启动菜单
  kernel vmlinuz
  append initrd=initrd.img inst.ks=http://192.168.0.1/ks.cfg quiet            //这里注明ks.cfg文件的位置,即实现无人值守全自动安装
  #append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet  //此项为默认的值,我们将其注释

  注:如果我们只是单纯的使用pxe网络有人值守的方式安装,即只需要设置inst.stage2=http://192.168.0.1/centos即可

============================================================================

5、如果只是现实有人值守的方式安装,只需要上面的操作,服务端即已经实现了pxe网络安装的功能

     当然我们在工作中,可能更多的是需要用到pxeKickStart现实操作系统无人值守的的安装,这样我们可能

     还需要得安装system-config-kickstart软件包,安装完成后就能使用system-config-kickstart命令生成ks.cfg文件

     当然我们如果对ks.cfg文件的配置熟悉,也可以直接创建/var/www/html/ks.cfg文件,笔者这里创建的ks.cfg内容如下:

 
# platform=x86, AMD64, or Intel EM64T
# version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'# Reboot after installation
reboot
# Root password
rootpw --iscrypted $6$Pf08DlF16p7svB6o$YngeMfbPtRPpGXT.H6r6MIhKNhf3s/34mamd1jarSU2RI08hn/wFB6ayWYbrRajmW0JhqrA1VFoGgNnGj6usl1
# System timezone
timezone Asia/Shanghai --isUtc
# Use network installation
url --url="http://192.168.0.1/centos"                 #最后面不需要加 /
# System language
lang en_US.UTF-8 --addsupport=zh_CN.UTF-8
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --onboot=yes --noipv6 --hostname=5201351
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

# System bootloader configuration
# 新硬盘需要创建mbr
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel 
# Disk partitioning information
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
part pv.123 --fstype="lvmpv" --ondisk=sda --size=953336
part /boot --fstype="xfs" --ondisk=sda --size=500
volgroup centos --pesize=4096 pv.123
logvol /data  --fstype="xfs" --size=613365 --name=data --vgname=centos
logvol swap  --fstype="swap" --size=32764 --name=swap --vgname=centos
logvol /home  --fstype="xfs" --size=204800 --name=home --vgname=centos
logvol /  --fstype="xfs" --size=102400 --name=root --vgname=centos
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

%packages
@core
@chinese-support
vim
ntp
%end
#########################################################################
%post
##
%end
 

6、最后我们再使用如下命令启动各项服务即可,网络中的客户端便能从pxe网络启动进行无人值守的系统安装了。

[root@5201351 ~]# systemctl restart dhcpd.service
[root@5201351 ~]# systemctl restart xinetd.service
[root@5201351 ~]# systemctl restart tftp.socket
[root@5201351 ~]# systemctl restart tftp.service
[root@5201351 ~]# systemctl restart httpd.service

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容