一、PXE的简介

PXE(preboot execute environment,预启动执行环境)是有inter公司开发的技术,工作与Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP协议下载一个启动软件包到本机内存中执行,由于这个启动预先安装在服务器中的终端操作系统。

自动化技术-PXE部署系统详情配置与说明

二、目标安装服务器能提供系统安装

dhcp server : 67/udp

tftp server : 69/udp

dhcp client: 68/udp

1.软件包安装

[[email protected] ~]# yum -y install dhcp tftp-server vsftpd xinetd syslinux

[[email protected] ~]# mkdir /var/ftp/centos7u3

[[email protected] ~]# mkdir /var/ftp/centos6u6

[[email protected] ~]# mount /dev/cdrom /var/ftp/centos7u3/

2.DHCP配置

[[email protected] ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

[[email protected] ~]# vim /etc/dhcp/dhcpd.conf

subnet 192.168.226.0 netmask 255.255.255.0 {

  range 192.168.226.150 192.168.226.250;                 #DHCP分配的地址段

  next-server 192.168.226.153;

  filename "pxelinux.0";

}

[[email protected] ~]# systemctl start dhcpd

[[email protected] ~]# systemctl enable dhcpd

测试dhcp配置自动分配IP成功

自动化技术-PXE部署系统详情配置与说明

3.tftp-server配置

提供centos7u3单个系统:

初始启动文件

[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

[[email protected] ~]# vim /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       #将此处的yes改成no

per_source  = 11

cps   = 100 2

flags   = IPv4

}

[[email protected] ~]# systemctl restart xinetd

[[email protected] ~]# systemctl enable xinetd

[[email protected] ~]# ss -utnlp | grep :69

udp    UNCONN     0      0         *:69                    *:*                   users:(("xinetd",pid=7955,fd=5))

根据引导菜单所需的文件(从centos7光盘上的isolinux目录)

[[email protected] ~]# cp -rf /var/ftp/centos7u3/isolinux/* /var/lib/tftpboot/

[[email protected] ~]# cd /var/lib/tftpboot/

[[email protected] tftpboot]# mkdir pxelinux.cfg

[[email protected] tftpboot]# cp isolinux.cfg pxelinux.cfg/default

[[email protected] tftpboot]# vim pxelinux.cfg/default

label linux

  menu label ^Install CentOS 7

  kernel vmlinuz

  append initrd=initrd.img inst.stage2=ftp://192.168.226.153/centos7u3 inst.repo=ftp://192.168.226.153/centos7u3

[[email protected]]# systemctl enable xinetd

[[email protected]]# systemctl restart xinetd

[[email protected]]# systemctl enable vsftpd

Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

[[email protected]]# systemctl restart vsftpd

启动服务器出现安装界面中安装源能够识别即为成功如果失败检查/var/lib/tftpboot/pxelinux.cfg/default 配置文件的配置信息

自动化技术-PXE部署系统详情配置与说明

如果希望提供centos7u3 centos6u8等多个系统:

1.为每个系统准备/var/lib/tftp/centosX/{vmlinuz,initrd}

2.为每个系统准备引导菜单 /var/lib/tftp/pxelinux.cfg/default

3.为每个系统准备安装树/var/ftp/centosX

Kickstart实现自动安装

部署环境:centos7u3 x86_64

项目目标:安装服务器能够提供Centos和Centos7系统的安装

一、kickstart文件简介

= =即把整个安装过程中要回答或者要做的事全部体现在应答文件中

  1. kickstart 安装选项: 包含语言、防火墙、密码、网络、分区的设置等;
  2. %Pre 部分:安装前解析的脚本,通常用来生成特殊的ks配置,比如由一段程序决定磁盘分区;
  3. %Package 部分:安装包的选择,可以是@base这样的组的形式,也可以是这样http-*包的形式;
  4. %Post 部分:安装后执行的脚本,通常用来做系统的初始化设置。比如启动的服务,相关的设定等。

二、创建ks文件,并共享

方法一:手动安装一台服务器,会自动生成ks文件,修改!

方法二:使用system-config-kickstart生成

[[email protected] ~]# yum -y install system-config-kickstart

[[email protected] ~]# system-config-kickstart           #大开kickstart图形化

自动化技术-PXE部署系统详情配置与说明

自动化技术-PXE部署系统详情配置与说明

自动化技术-PXE部署系统详情配置与说明

自动化技术-PXE部署系统详情配置与说明

自动化技术-PXE部署系统详情配置与说明

自动化技术-PXE部署系统详情配置与说明

自动化技术-PXE部署系统详情配置与说明

最后生成的kickstar模版文件执行顺序会有问题需要手动修改

[[email protected] ftp]# vim /var/ftp/centos7.cfg

install

keyboard 'us'

rootpw --iscrypted $1$GuFzhTpv$xitEUFXgs3A2hARRQotGR0

timezone Asia/Shanghai

url --url="ftp://192.168.226.157/centos7u3"

lang en_US

selinux --disabled

firewall --disabled

auth  --useshadow  --passalgo=sha512

text

skipx

network  --bootproto=dhcp --device=eth0

reboot

bootloader --append="net.ifnames=0 biosdevname=0" --location=mbr --md5pass="grub.pbkdf2.sha512.10000.F98A6EA56673779898A0F9B7EBAB11BB9D4B802E951C0A425AE32730F5772E277C6903D09CF6681678D44638432D43E140B85D1C4C22BB0D127B3FB4DC9CB924.EDA3747D05C4AB8FFA72E3B3D262606D9CA8F305A87E290E5B17BDA0BEC86EB0BBB95C2C5722834583F38D10EF9FFA640C866A6FA86A85F0C752D95C63CE5553"

zerombr

clearpart --all --initlabel

part /boot --fstype="ext4" --size=1024

part swap --fstype="swap" --size=2048

part / --fstype="xfs" --grow --size=1

%packages

@^minimal

@core

vim

%end

%post

useradd alice

echo 123 |passwd --stdin alice

%end

#md5pass生成方式

 [[email protected] ~]# grub2-mkpasswd-pbkdf2

[[email protected] ftp]# vim /var/lib/tftpboot/pxelinux.cfg/default

label linux

  menu label ^Install CentOS Linux 7

  kernel vmlinuz

  append initrd=initrd.img inst.stage2=ftp://192.168.226.157/centos7u3 inst.repo=ftp://192.168.226.157/centos7u3 inst.ks=ftp://192.168.226.157/centos7.cfg

验证通过:

自动化技术-PXE部署系统详情配置与说明

结束!

配置文件和批量安装的脚本下载链接

https://download.csdn.net/download/weixin_45423952/12623661

注意事项:有些环境运行centos7.cfg需要注释掉自动安装软件的内容

PXE自动化脚本  脚本中引用了httpd根据环境选择

 

相关文章:

  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2022-01-18
  • 2021-04-06
  • 2021-08-09
  • 2021-11-18
  • 2021-06-26
猜你喜欢
  • 2021-10-16
  • 2022-01-04
  • 2022-12-23
  • 2021-08-21
  • 2021-05-28
  • 2021-06-29
  • 2021-08-10
相关资源
相似解决方案