centos 7.6 ——部署PXE远程安装服务和kickstart无人值守部署
文章目录
-
centos 7.6 ——部署PXE远程安装服务和kickstart无人值守部署 - PXE工作原理
- 部署PXE远程安装服务
- 一、实验描述
- 二、实验步骤
- kickstart无人值守部署
- 一、实验描述
- 二、实验步骤
PXE工作原理
PXE(Pre-boot Execution Environment)是由Intel设计的协议,它可以使计算机通过网络启动。协议分为client和server两端,PXE client在网卡的ROM中,当计算机引导时,BIOS把PXE client调入内存执行,并显示出命令菜单,经用户选择后,PXE client将放置在远端的操作系统通过网络下载到本地运行。
通过什么协议下载Linux内核和根文件系统
对于第一个问题,可以通过DHCP Server解决,由DHCP server来给PXE client分配一个IP地址,DHCP Server是用来给DHCP Client动态分配IP地址的协议,不过由于这里是给PXE Client分配IP地址,所以在配置DHCP Server时,需要增加相应的PXE特有配置。
至于第二个问题,在PXE client所在的ROM中,已经存在了TFTP Client。PXE Client使用TFTP Client,通过TFTP协议到TFTP Server上下载所需的文件。
这样,PXE协议运行的条件就具备了,下面我们就来看看PXE协议的工作过程。
工作过程
在上图中,PXE client是需要安装Linux的计算机,TFTP Server和DHCP Server运行在另外一台Linux Server上。Bootstrap文件、配置文件、Linux内核以及Linux根文件系统都放置在Linux Server上TFTP服务器的根目录下。
PXE client在工作过程中,需要三个二进制文件:bootstrap、Linux 内核和Linux根文件系统。Bootstrap文件是可执行程序,它向用户提供简单的控制界面,并根据用户的选择,下载合适的Linux内核以及Linux根文件系统。
部署PXE远程安装服务
一、实验描述
二、实验步骤
设置双网卡的
ens33 nat模式
ens37 仅主机模式
cd /etc/sysconfig/network-scripts
cp ifcfg-ens33 ifcfg-ens37
vim ifcfg-ens37
1. 配置网卡信息
2. 编辑dhcp.conf配置文件信息
yum -y install dhcp
rpm -ql dhcpd
[root@localhost ftp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim dhcpd.conf
3. 安装系统内核文件
[root@localhost dhcp]# yum -y install syslinux
[root@localhost dhcp]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
yum -y install tftp-server
[root@localhost dhcp]# rpm -ql tftp-server
/etc/xinetd.d/tftp //配置文件
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot //站点
[root@localhost dhcp]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
[root@localhost dhcp]# ls /var/lib/tftpboot/
pxelinux.0
[root@localhost dhcp]# vim /etc/xinetd.d/tftp
4. 开启tftp服务
5. 安装vsftp服务
[root@localhost dhcp]# yum install vsftpd -y
[root@localhost dhcp]# cd /var/ftp
[root@localhost ftp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 4月 1 12:55 pub
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 7月 13 17:32 centos7
drwxr-xr-x. 2 root root 6 4月 1 12:55 pub
[root@localhost ftp]#
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ftp]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda3 xfs 182G 5.3G 177G 3% /
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 11M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 174M 841M 18% /boot
tmpfs tmpfs 406M 16K 406M 1% /run/user/42
tmpfs tmpfs 406M 0 406M 0% /run/user/1000
/dev/sr0 iso9660 4.3G 4.3G 0 100% /var/ftp/centos7
[root@localhost ftp]#
[root@localhost ftp]# cd centos7/
[root@localhost centos7]# ll
总用量 686
-rw-rw-r--. 1 root root 14 11月 26 2018 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 11月 26 2018 EFI
-rw-rw-r--. 1 root root 227 8月 30 2017 EULA
-rw-rw-r--. 1 root root 18009 12月 10 2015 GPL
drwxr-xr-x. 3 root root 2048 11月 26 2018 images
drwxr-xr-x. 2 root root 2048 11月 26 2018 isolinux
drwxr-xr-x. 2 root root 2048 11月 26 2018 LiveOS
drwxrwxr-x. 2 root root 663552 11月 26 2018 Packages
drwxrwxr-x. 2 root root 4096 11月 26 2018 repodata
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 11月 26 2018 TRANS.TBL
[root@localhost centos7]# cd images/
[root@localhost images]# ls
efiboot.img pxeboot TRANS.TBL
[root@localhost images]# ls -lh
总用量 8.6M
-rw-r--r--. 1 root root 8.5M 11月 26 2018 efiboot.img
drwxr-xr-x. 2 root root 2.0K 11月 26 2018 pxeboot
-r--r--r--. 1 root root 442 11月 26 2018 TRANS.TBL
[root@localhost images]# cd pxeboot/
[root@localhost pxeboot]# ll
总用量 57838
-rw-r--r--. 1 root root 52584760 11月 26 2018 initrd.img
-r--r--r--. 1 root root 441 11月 26 2018 TRANS.TBL
-rwxr-xr-x. 1 root root 6639904 11月 9 2018 vmlinuz
[root@localhost pxeboot]# cp initrd.img vmlinuz /var/lib/tftpboot/ 将初始化文件和vmlinuz压缩内核放到tftpboot目录中
[root@localhost pxeboot]#
[root@localhost pxeboot]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ll
总用量 57872
-rw-r--r--. 1 root root 52584760 7月 13 17:35 initrd.img
-rw-r--r--. 1 root root 26759 7月 13 17:27 pxelinux.0
-rwxr-xr-x. 1 root root 6639904 7月 13 17:35 vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# ll
总用量 57872
-rw-r--r--. 1 root root 52584760 7月 13 17:35 initrd.img
-rw-r--r--. 1 root root 26759 7月 13 17:27 pxelinux.0
drwxr-xr-x. 2 root root 6 7月 13 17:37 pxelinux.cfg
-rwxr-xr-x. 1 root root 6639904 7月 13 17:35 vmlinuz
[root@localhost tftpboot]# vim pxelinux.cfg/ //手配引导配置文件default
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
[root@localhost pxelinux.cfg]# systemctl stop firewalld
[root@localhost pxelinux.cfg]# setenforce 0
[root@localhost pxelinux.cfg]# systemctl start dhcpd
[root@localhost pxelinux.cfg]# systemctl start tftp
[root@localhost pxelinux.cfg]# systemctl start vsftpd
[root@localhost pxelinux.cfg]#
新建一个centos 7.6的虚拟机不添加镜像文件点击启动客户机,网络配置仅主机模式基于VMnet1网卡,启动客户机之后,系统会自动安装系统。
kickstart无人值守部署
一、实验描述
二、实验步骤
[root@localhost ~]# yum -y install system-config-kickstart
[root@localhost pxelinux.cfg]# cd /var/ftp/
[root@localhost ftp]# ll
总用量 6
drwxrwxr-x. 8 root root 2048 11月 26 2018 centos7
-rw-r--r--. 1 root root 978 7月 13 19:05 ks.cfg
drwxr-xr-x. 2 root root 6 4月 1 12:55 pub
[root@localhost ftp]# cat ks.cfg
#platform=Intel Itanium (安腾)
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$fFK.BWmk$jXoXXtkBZEx6A1iYQYiwS/
# Use network installation
url --url="ftp://192.168.100.100/centos7"
# System language
lang zh_CN
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=none
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part /home --fstype="xfs" --size=2048
part /var --fstype="xfs" --size=2048
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
[root@localhost ftp]# cd ~
[root@localhost ~]# vim anaconda-ks.cfg
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# vim ks.cfg
将在anaconda-ks.cfg 复制的内容粘贴到ks.cfg 文件末尾
[root@localhost ftp]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ll
总用量 57872
-rw-r--r--. 1 root root 52584760 7月 13 17:35 initrd.img
-rw-r--r--. 1 root root 26759 7月 13 17:27 pxelinux.0
drwxr-xr-x. 2 root root 21 7月 13 18:25 pxelinux.cfg
-rwxr-xr-x. 1 root root 6639904 7月 13 17:35 vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# vim default
[root@localhost pxelinux.cfg]# systemctl restart tftp
启动客户机,显示自动加载安装系统