pxe+nfs+tftp+dhcp网络安装centos7

测试环境准备

测试网络是家庭局域网,服务端为vmware虚拟化出的Centos7.5主机(服务端直接指定固定ip192.168.0.154),同时需要禁用局域网路由器上的dhcp服务,因为dhcp服务需要去配置tftp server,这点在路由器上不好实现,故需要自己搭建一个dhcp服务,局域网网段为192.168.0.0/24,网关192.168.0.1,同时虚拟机的网络均为桥接模式
服务端需要安装的服务有nfs tftp rpcbind dhcpd

服务端配置安装

安装dhcp
yum -y install dhcp
cat /etc/dhcp/dhcpd.conf

subnet 192.168.0.0 netmask 255.255.255.0 {
                range 192.168.0.100 192.168.0.200;
                next-server 192.168.0.154;               
                option routers 192.168.0.1;
                option domain-name-servers 202.103.24.68;
                filename "/pxelinux.0";
            }

简单解释一下上面的配置文件参数
next-server 指tftp server地址
option routers 路由
option domain-name-servers 网关
filename 引导程序文件和加载内核文件的引导程序文件

安装tftp
yum install -y tftp-server tftp
cat /etc/xinetd.d/tftp

...
disable   =  no
...

安装syslinux
yum install -y syslinux

安装nfs
yunm -y install nfs-utils rpcbind

安装xinetd
yyum -y install xinetd

相关配置文件处理
cd /usr/share/syslinux
cp pxelinux.0 /var/lib/tftpboot/

因为要从原生的iso镜像里获取系统文件,所以最好先将其挂载
lsblk
mount /dev/sr0 /mnt
cd /mnt/isolinux
cp vmlinuz initrd.img boot.msg vesamenu.c32 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

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

default vesamenu.c32
timeout 600

display boot.msg
prompt 1
# 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 CentOS 7
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 ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=nfs:192.168.0.154:/mnt quiet


menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install CentOS 7 in ^basic graphics mode
  text help
        Try this option out if you're having trouble installing
        CentOS 7.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a CentOS 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=CentOS\x207\x20x86_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

上面这段配置文件是在原有默认配置文件上修改后得到的,修改了两处

  • 添加了nfs启动系统的配置
  • 删除了系统媒介检查的步骤,否则可能会报错

cat /etc/exports

/mnt *(ro)

系统服务配置

systemctl restart dhcpd   
systemctl restart tftp   
systemctl restart nfs   
systemctl restart xinetd   
systemctl restart rpcbind   
systemctl stop firewalld   
systemctl disable firewalld   
systemctl enable dhcpd   
systemctl enable tftp   
systemctl enable nfs   
systemctl enable xinetd   
systemctl enable rpcbind   
sed -i 's/enforcing/disabled/g /etc/sysconfig/selinux'   
reboot

查看服务nfs dhcp xinetd tftp rpcbind的运行情况看是否正常运行

系统安装

新建一个虚拟机,开机会开始自动查找镜像
11hhj
后面正常安装即可

说明

其实还可以将nfs换成ftp或者http也行,同时还可以实现无人值守安装,本文只实现了通过nfs来无介质网络安装