部署DHCP服务器
• Dynamic Host Configuration Protocol
– 动态主机配置协议,由 IETF(Internet 网络工程师任
务小组)组织制定,用来简化主机地址分配管理
• 主要分配以下入网参数
– IP地址/子网掩码/广播地址
– 默认网关地址、DNS服务器地址
DHCP概述及原理,默认的端口:67
• DHCP地址分配的四次会话(广播,先到先得)
– DISCOVERY --> OFFER --> REQUEST -->ACK
一个网络中,只能有一个DHCP
虚拟机A:
1.安装软件包
[root@svr7 ~]# yum -y install dhcp
2.修改配置文件
[root@svr7 ~]# vim /etc/dhcp/dhcpd.conf
DHCP Server Configuration file.
see /usr/share/doc/dhcp*/dhcpd.conf.example
see dhcpd.conf(5) man page
末行模式下 :r /usr/share/doc/dhcp*/dhcpd.conf.example
subnet 192.168.4.0 netmask 255.255.255.0 { #分配网段
range 192.168.4.100 192.168.4.200; #分配IP地址范围
option domain-name-servers 192.168.4.7; #分配DNS服务器
option routers 192.168.4.254; #分配的网关地址
default-lease-time 600; #默认的租约时间
max-lease-time 7200; #最大的租约时间
}
[root@svr7 ~]# systemctl restart dhcpd
网络装机概述
网络装机的优势
1.规模化:同时装配多台主机
2.自动化:装系统、配置各种服务
3.远程实现:不需要光盘、U盘等物理安装介质
什么是PXE网络
1.PXE,Pre-boot execution Environment
– 预启动执行环境,在操作系统之前运行
– 可用于远程安装
2.工作模式
– PXE client 集成在网卡的启动芯片中
– 当计算机引导时,从网卡芯片中把PXE client调入内存
执行,获取PXE server配置、显示菜单,根据用户选
择将远程引导程序下载到本机运行
PXE组件及过程分析
1.需要哪些服务组件?
– DHCP服务,分配IP地址、定位引导程序
– TFTP服务,提供引导程序下载
– HTTP服务(或FTP/NFS),提供yum安装源
2,客户机应具备的条件
– 网卡芯片必须支持PXE协议
– 主板支持从网卡启动
虚拟机A:
一、构建dhcp服务,指定下一个服务器地址
[root@svr7 ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.4.0 netmask 255.255.255.0 {
range 192.168.4.100 192.168.4.200;
option domain-name-servers 192.168.4.7;
option routers 192.168.4.254;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.4.7; #指定下一个服务器地址
filename "pxelinux.0"; #指定网卡引导文件名称
}
[root@svr7 ~]# systemctl restart dhcpd
pxelinux.0:网卡引导文件(网络装机说明书),二进制文件
安装一个软件即可获得,默认名称 pxelinux.0
二、 tftp服务器,提供众多的引导文件
tftp:简单的文件传输协议
tftp默认端口为:69
默认的路径:/var/lib/tftpboot
1.安装的软件包tftp-server
[root@svr7 ~]# yum -y install tftp-server
2.启动的tftp服务
[root@svr7 ~]# systemctl restart tftp
3.部署pxelinux.0文件
[root@svr7 ~]# yum provides */pxelinux.0
[root@svr7 ~]# yum -y install syslinux
[root@svr7 ~]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@svr7 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
[root@svr7 ~]# ls /var/lib/tftpboot
pxelinux.0
4.部署菜单文件
[root@svr7 ~]# poweroff
图形添加光驱设备
[student@room9pc01 ~]$ goa
[root@svr7 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@svr7 ~]# ls /mnt/
或者利用光盘镜像文件直接挂载
[root@svr7 ~]# mount /root/CentOS7-1804.iso /opt/
mount: /dev/loop0 写保护,将以只读方式挂载
[root@svr7 ~]# ls /opt/
[root@svr7 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@svr7 ~]# cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@svr7 ~]# ls /var/lib/tftpboot/pxelinux.cfg
default
5.部署 图形的模块(vesamenu.c32)与背景图片(splash.png)
[root@svr7 ~]# cp /mnt/isolinux/vesamenu.c32 /mnt/isolinux/splash.png /var/lib/tftpboot
[root@svr7 ~]# ls /var/lib/tftpboot
pxelinux.0 pxelinux.cfg splash.png vesamenu.c32
6.部署 启动内核(vmlinuz) 与 驱动程序(initrd.img)
[root@svr7 ~]# cp /mnt/isolinux/vmlinuz /mnt/isolinux/initrd.img /var/lib/tftpboot/
[root@svr7 ~]# ls /var/lib/tftpboot/
initrd.img pxelinux.cfg vesamenu.c32
pxelinux.0 splash.png vmlinuz
7.修改菜单文件
[root@svr7 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
末行模式 :set nu 开启行号
1 default vesamenu.c32 #默认加载图形模块
2 timeout 600 #读秒时间 1/10
10 menu background splash.png #背景图片
11 menu title NSD1911 PXE Server #修改标题
61 label linux
62 menu label Install CentOS 7 #菜单的显示
63 menu default #读秒结束后默认的选择
64 kernel vmlinuz #加载内核
65 append initrd=initrd.img #加载驱动程序
总结思路:
1.dhcp服务器—>IP地址 next-server filename pxelinux.0
2.tftp服务器—> pxelinux.0
3.pxelinux.0—>菜单文件
/var/lib/tftpboot/pxelinux.cfg/default
4.default—> 图形模块 内核 驱动…
初步测试:
1.必备的服务进行重起
[root@svr7 ~]# systemctl restart dhcpd
[root@svr7 ~]# systemctl restart tftp
2.新建一台虚拟机
安装方式选择:网络引导(PXE)
内存:2048M
网络的类型:private1
三、构建Web服务,提供光盘的所有内容
1.安装httpd软件
[root@svr7 ~]# yum -y install httpd
2.挂载方式
[root@svr7 ~]# mkdir /var/www/html/centos
[root@svr7 ~]# ls /var/www/html/centos
[root@svr7 ~]# mount /dev/cdrom /var/www/html/centos
mount: /dev/sr0 写保护,将以只读方式挂载
[root@svr7 ~]# ls /var/www/html/centos
3.重起httpd服务,测试访问
[root@svr7 ~]# systemctl restart httpd
[root@svr7 ~]# firefox 192.168.4.7/centos
四 生成应答文件,实现无人值守安装
1.图形的工具system-config-kickstart
[root@svr7 ~]# yum -y install system-config-kickstart
2.以英文的方式,运行图形的工具
[root@svr7 ~]# LANG=en system-config-kickstart
点击 "软件包选择(Package Selection)" 查看是否可以进行选择
需要Yum仓库的支持:指向光盘的内容仓库,标识必须为[development]
[root@svr7 ~]# vim /etc/yum.repos.d/local.repo
[development]
name=CentOS-$releasever - Base
baseurl=ftp://192.168.4.254/centos-1804
enabled=1
gpgcheck=0
[root@svr7 ~]# LANG=en system-config-kickstart
点击 "软件包选择(Package Selection)" 查看是否可以进行选择
3.查看应答文件
[root@svr7 ~]# ls /root/ks.cfg
/root/ks.cfg
[root@svr7 ~]#
4.利用Web服务,传输应答文件
[root@svr7 ~]# cp /root/ks.cfg /var/www/html/
[root@svr7 ~]# ls /var/www/html
5.修改菜单文件,指定获取应答文件的方式及名称
[root@svr7 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
.......
label linux
menu label Install CentOS 7
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.4.7/ks.cfg
总结思路:
1.dhcp服务器—>IP地址 next-server filename pxelinux.0
2.tftp服务器—> pxelinux.0
3.pxelinux.0—>菜单文件
/var/lib/tftpboot/pxelinux.cfg/default
4.default—> 图形模块 内核 驱动 ks应答文件…
5.ks应答文件—>时区 密码 软件包 …
–url=“http://192.168.4.7/centos”