DHCP+TFTP+HTTP+PXE实现无人值守快速安装操作系统
PXE(preboot execute environment,预启动执行环境)可通过CS网络模式,实现无盘操作系统安装;其工作原理如下:当计算机引导时,BIOS把 PXE Client 调入内存中执行,然后由 PXE Client 将放置在远端的文件通过网络下载到本地运行;效率是有盘情况下的3倍。下面我们通过vmware虚拟机搭建一个PXE环境环境:Server: RHEL7.4 x8...
PXE(preboot execute environment,预启动执行环境)可通过CS网络模式,实现无盘操作系统安装;其工作原理如下:当计算机引导时,BIOS把 PXE Client 调入内存中执行,然后由 PXE Client 将放置在远端的文件通过网络下载到本地运行;效率是有盘情况下的3倍。下面我们通过vmware虚拟机搭建一个PXE环境
环境:
Server: RHEL7.4 x86_64(192.168.101.130)
vmware:vmware workstation 14 pro
DHCP:range 192.168.101.140~192.168.101.150
提示:
为了vmware更好的实现DHCP动态地址获取,我们需要关闭vmware自身的DHCP服务,仅开启NAT模式;具体方法为:【编辑】--->【虚拟网络编辑器】,选中【nat模式】--->【更改配置】,去掉【使用本地DHCP服务将IP地址分配给虚拟机】前面的√即可,【应用】或者【确定】之后便可。
搭建DHCP服务
1、yum安装DHCPD
[root@localhost ~]# yum install -y dhcp
2、DHCPD配置
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
/* 因为yum安装的DHCP是不提供配置文件的,需要复制一个模板并重命名后使用
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks…
option domain-name “example.org”; /*全局变量,域名
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600; /*全局变量,默认的租约时长(1/10s)
max-lease-time 7200; /*全局变量,最大的租约时长
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
# This is a very basic subnet declaration.
subnet 192.168.101.0 netmask 255.255.255.0 {
range 192.168.101.160 192.168.101.170;
option routers 192.168.101.2;
option broadcast-address 192.168.101.255;
next-server 192.168.101.130;
filename “pxelinux.0”;
}
3、启动服务
[root@localhost ~]# systemctl start dhcpd.service /*启动DHCPD服务
[root@localhost ~]# systemctl enable dhcpd.service /*加入开机自启动
安装syslinux
1、安装
[root@localhost ~]# yum install -y syslinux
2、RHEL7环境下所需的文件如下:menu.c32、memdisk、pxelinux.0、chain.c32
[root@localhost tftpboot]# cd /usr/share/syslinux/
[root@localhost syslinux]# ls
altmbr.bin diag gptmbr_f.bin int18.com kbdmap.c32 memdump.com reboot.c32 vesainfo.c32
altmbr_c.bin disk.c32 gpxecmd.c32 isohdpfx.bin linux.c32 meminfo.c32 rosh.c32 vesamenu.c32
altmbr_f.bin dmitest.c32 gpxelinux.0 isohdpfx_c.bin ls.c32 menu.c32 sanboot.c32 vpdtest.c32
cat.c32 dosutil gpxelinuxk.0 isohdpfx_f.bin lua.c32 pcitest.c32 sdi.c32 whichsys.c32
chain.c32 elf.c32 hdt.c32 isohdppx.bin mboot.c32 pmload.c32 sysdump.c32 zzjson.c32
cmd.c32 ethersel.c32 host.c32 isohdppx_c.bin mbr.bin poweroff.com syslinux64.exe
config.c32 gfxboot.c32 ifcpu64.c32 isohdppx_f.bin mbr_c.bin pwd.c32 syslinux.com
cpuid.c32 gptmbr.bin ifcpu.c32 isolinux.bin mbr_f.bin pxechain.com syslinux.exe
cpuidtest.c32 gptmbr_c.bin ifplop.c32 isolinux-debug.bin memdisk pxelinux.0 ver.com
搭建HTTPD服务##
1、yum 安装httpd
[root@localhost ~]#yum install -y httpd
2、搭建本地镜像仓及KS目录
[root@localhost ~]#mkdir -pv /var/www/html/{ksdir,centos/7.4} /*创建镜像所需目录centos/7.4,和存放kickstart.cfg文件的ksdir目录
[root@localhost ~]#cp -r /mnt/* /var/www/html/centos/7.4/ /*将7.4镜像复制至本机
3、启动服务
[root@localhost ~]#systemctl start httpd.service
[root@localhost ~]#systemctl enable httpd.service
搭建TFTP服务
TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。是进行小文件传输的。因此它不具备通常的FTP的许多功能,它只能从文件服务器上获得或写入文件,不能列出目录,不进行认证,它传输8位数据。是进行小文件传输的。因此它不具备通常的FTP的许多功能,它只能从文件服务器上获得或写入文件,不能列出目录,不进行认证,它传输8位数据。端口号为69。
1、yum安装tftp-server
[root@localhost ~]#yum install -y tftp-server
2、修改tftp配置文件
[root@localhost ~]# vi /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 = no /*修改为NO
per_source = 11
cps = 100 2
flags = IPv4
}
3、创建pxe所需目录及文件,多系统安装时将vmlinuz等文件单独存放在各自目录下,此时在配置相对应的kernel、initrd文件指向时需要带上一级目录,tftp-server默认根目录为:/var/lib/tftpboot
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]#cp /usr/share/syslinux/{chain.c32,memdisk,menu.c32,pxelinux.0} ./
[root@localhost tftpboot]#mkdir pxelinux.cfg /*创建MENU default目录
[root@localhost tftpboot]#mkdir centos7 /*创建存放centos7的vmlinuz等文件的目录,如果存在多系统安装时,可创建各自目录存放文件
[root@localhost tftpboot]#vim pxelinux.cfg/default
default menu.c32
prompt 1
timeout 30
display boot.msg
menu background timg.jpg
menu title ############PXE boot Menu###########
label Centos7.4
menu label Kickstart RHEL7.4
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.101.130/ksdir/7.4/ks7.4.cfg inst repo=http://192.168.101.130/centos/7.4/ /*指定镜像所在路径及KS配置文件所在目录
[root@localhost centos7]#cp /mnt/images/pxeboot/* /var/lib/tftpboot/centos7/
[root@localhost centos7]#ls -al
total 108567
dr-xr-xr-x. 2 root root 2048 Jul 11 2017 .
dr-xr-xr-x. 3 root root 2048 Jul 11 2017 ..
-r--r--r--. 2 root root 49763300 Jul 11 2017 initrd.img
-r--r--r--. 1 root root 664 Jul 11 2017 TRANS.TBL
-r--r--r--. 2 root root 55528012 Jul 11 2017 upgrade.img
-r-xr-xr-x. 2 root root 5875184 Jul 7 2017 vmlinuz
4、启动服务
[root@localhost ~]#systemctl start tftp.socket
[root@localhost ~]#systemctl enable tftp.service
System-config-kickstart
kickstart工具是由Redhat开发,也是目前比较通用的自动化部署工具之一,system-config-kickstart是需要在图形化界面下工作生成ks.cfg文件;如果熟练语法的话,也可以手动书写ks.cfg。
在图形界面下,打开Terminal,执行【system-config-kickstart】即可
结尾
在虚拟机中新建虚拟机,便可测试无人值守自动化安装操作系统
更多推荐
所有评论(0)