From 93fde519f6a8bd9ef6c27c08b29295835f416363 Mon Sep 17 00:00:00 2001 From: xiaoshun Date: Mon, 26 Aug 2024 11:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PXE+Kickstart无人值守安装操作系统(1).md | 230 ++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 PXE+Kickstart无人值守安装操作系统(1).md diff --git a/PXE+Kickstart无人值守安装操作系统(1).md b/PXE+Kickstart无人值守安装操作系统(1).md new file mode 100644 index 0000000..f21d9a3 --- /dev/null +++ b/PXE+Kickstart无人值守安装操作系统(1).md @@ -0,0 +1,230 @@ +# PXE+Kickstart无人值守安装操作系统 +[TOC] + +### 什么是PXE? + +PXE(Preboot Execution Environment,预启动执行环境)是一种允许计算机在启动过程中通过网络接口卡(NIC)从服务器加载操作系统或其他软件的协议 + +PXE,全名Pre-boot Execution Environment,预启动执行环境; +通过网络接口启动计算机,不依赖本地存储设备(如硬盘)或本地已安装的操作系统; +由Intel和Systemsoft公司于1999年9月20日公布的技术; +Client/Server的工作模式; +PXE客户端会调用网际协议(IP)、用户数据报协议(UDP)、动态主机设定协议(DHCP)、小型文件传输协议(TFTP)等网络协议; +PXE客户端(client)这个术语是指机器在PXE启动过程中的角色。一个PXE客户端可以是一台服务器、笔记本电脑或者其他装有PXE启动代码的机器(我们电脑的网卡) + + + +pxe+kickstart 全自动安装操作系统,(不包括win) +pxe是网卡上的芯片 +kickstart软件 pylickstart 用来配置操作系统安装过程的配置文件ks.cfg + +initrd初始化磁盘影像文件 + +![](https://img.beyourself.org.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDYvMjIvNWQwZDE0YzY3NTFiMDY1ODMxLnBuZw) + +图中的vmlinux应该为vmliuz + + + + ### PXE工作原理示意图说明 + +``` +1. Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client。 + +2. Client向PXE Server上的TFTP发送获取pxelinux.0请求消息,TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0。 + +3. Client执行接收到的pxelinux.0文件。 + +4. Client向TFTP发送针对本机的配置信息(记录在TFTP的pxelinux.cfg目录下),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。 + +5. Client向TFTP发送Linux内核请求信息,TFTP接收到消息之后将内核文件发 送给Client。 + +6. Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件 系统。 + +7. Client启动Linux内核(启动参数已经在4中的配置文件中设置好了)。 + +8. Client通过NFS下载镜像文件,读取autoyast自动化安装脚本。 至此,Client正式进入自动化安装模式开始安装系统直到完成 +``` +### 一、环境 +|名称| 值 | +|--|--| +| 软件 | vmware | +|系统|centos7.5| +|网络|桥接| +|ip地址|10.20.157.100| + + +### 二、安装前准备 +```shell +# 关闭防火墙、selinux +[root@localhost ~]# systemctl stop firewalld +[root@localhost ~]# systemctl disable firewalld +[root@localhost ~]# setenforce 0 +[root@localhost ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config + +# 配置ip地址 +[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 +TYPE="Ethernet" +PROXY_METHOD="none" +BROWSER_ONLY="no" +BOOTPROTO="static" +DEFROUTE="yes" +IPADDR=10.20.157.100 +PREFIX=24 +GATEWAY=10.20.157.1 +DNS1=114.114.114.114 +DNS2=8.8.8.8 +DEVICE="ens33" +ONBOOT="yes" + +[root@localhost ~]# systemctl restart network + +# 配置yum源并安装软件包 +[root@localhost ~]# rm -rf /etc/yum.repos.d/* +[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo +[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo +[root@localhost ~]# yum clean all +[root@localhost ~]# yum makecache fast +[root@localhost ~]# yum install -y dhcp tftp tftp-server syslinux wget vsftpd pykickstart +``` + + +### 三、dhcp服务器配置 +```shell +[root@localhost ~]# vim /etc/dhcp/dhcpd.conf +#确保配置文件内容如下 +ddns-update-style interim; +ignore client-updates; +authoritative; +allow booting; +allow bootp; +allow unknown-clients; + +# A slightly different configuration for an internal subnet. + subnet 10.20.157.0 netmask 255.255.255.0 +{ + range 10.20.157.110 10.20.157.200; + option domain-name-servers 10.20.157.1; + option domain-name "server1.example.com"; + option routers 10.20.157.1; + option broadcast-address 10.20.157.255; + default-lease-time 600; + max-lease-time 7200; + + # PXE SERVER IP + next-server 10.20.157.100; # DHCP server ip + filename "pxelinux.0"; + } +``` + +### 四、TFTP服务准备 + +```shell +[root@localhost ~]# vim /etc/xinetd.d/tftp +#修改内容如下 +service tftp +{ + socket_type = dgram + protocol = udp + wait = yes + user = root + server = /usr/sbin/in.tftpd + server_args = -s /tftpboot + disable = no + per_source = 11 + cps = 100 2 + flags = IPv4 + } + +[root@localhost ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} /var/lib/tftpboot/ +[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg +[root@localhost ~]# mkdir /var/lib/tftpboot/netboot + + +``` + +### 五、VSftpd服务准备 +在VMware中将cd驱动器链接 +![在这里插入图片描述](https://img.beyourself.org.cn/19e6fdfcee284b6e87730b787069634f.png) + +``` +[root@localhost ~]# mount /dev/cdrom /mnt +[root@localhost ~]# cp -rf /mnt/* /var/ftp/pub/ + +# 拷贝系统启动时需要的镜像文件 +[root@localhost ~]# cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/netboot/ +[root@localhost ~]# cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/netboot/ + +# 创建ks.cfg 文件 +[root@localhost ~]# vim /var/ftp/pub/ks.cfg +#platform=x86, AMD64, or Intel EM64T + #version=DEVEL + # Firewall configuration + firewall --disabled + # Install OS instead of upgrade + install + # Use NFS installation media + url --url="ftp://10.20.157.100/pub/" + rootpw --plaintext 123456 +#root的密码设为123456 + # Use graphical install + graphical + firstboot disable + # System keyboard + keyboard us + # System language + lang en_US + # SELinux configuration + selinux disabled + # Installation logging level + logging level=info +# System timezone + timezone Asia/Shanghai + # System bootloader configuration + bootloader location=mbr + clearpart --all --initlabel + part swap --asprimary --fstype="swap" --size=1024 + part /boot --fstype xfs --size=200 + part pv.01 --size=1 --grow + volgroup rootvg01 pv.01 + logvol / --fstype xfs --name=lv01 --vgname=rootvg01 --size=1 --grow + reboot + +%packages + @core + wget + %end + +%post + %end + +# 检查语法是否有错误 +[root@localhost ~]# ksvalidator /var/ftp/pub/ks.cfg +``` + +### 六、PXE菜单 +``` +[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default + default menu.c32 + prompt 0 + timeout 30 + MENU TITLE Togogo.net Linux Training + + LABEL centos7_x64 + MENU LABEL CentOS 7 X64 for newrain + KERNEL /netboot/vmlinuz + APPEND initrd=/netboot/initrd.img inst.repo=ftp://10.20.157.100/pub ks=ftp://10.20.157.100/pub/ks.cfg + +``` + +### 七、重启服务 +``` +[root@localhost ~]# systemctl enable dhcpd vsftpd tftp +[root@localhost ~]# systemctl restart dhcpd vsftpd tftp + +``` + +### 八、创建虚拟机-自动安装系统 +> 注意:内存必须大于2G +![在这里插入图片描述](https://img.beyourself.org.cn/d57f89576d27434a8df44c87af9b5b0d.png) +