PXE自动化安装CentOS 8

安装前准备:关闭防火墙和SELINUX,DHCP服务器静态IP。
切勿用桥接模式 最好是NET模式而且把自动分配DHCP对勾取消。

PXE自动化安装CentOS 8_第1张图片
查看防火墙和seelinux是否关闭

[root@centos8 ~]#firewall-cmd --state
not running
[root@centos8 ~]#getenforce 
Disabled

安装对应的软件包

PXE自动化安装CentOS 8_第2张图片
安装syslinux的时候centos8和centos7存在一点不同在后面的后缀-nonlinuxPXE自动化安装CentOS 8_第3张图片
启动相应的三个服务 但是由于dhcp的文件配置还没有配置,所以这里起不来。
在这里插入图片描述

[root@centos8 ~]#ss -ntulp
查看对应端口号

![在这里插入图片描述](https://img-blog.csdnimg.cn/20191114145943475.png

开启HTTP服务

把光盘仓库挂载到web上面 同时做好的应答文件和初始化脚本也可以一起挂载上去

[root@centos8 ~]#cd /var/www/html/

[root@centos8 html]#mkdir centos/{6,7,8}/isos/x86_64/ -pv
mkdir: created directory 'centos'
mkdir: created directory 'centos/6'
mkdir: created directory 'centos/6/isos'
mkdir: created directory 'centos/6/isos/x86_64/'
mkdir: created directory 'centos/7'
mkdir: created directory 'centos/7/isos'
mkdir: created directory 'centos/7/isos/x86_64/'
mkdir: created directory 'centos/8'
mkdir: created directory 'centos/8/isos'
mkdir: created directory 'centos/8/isos/x86_64/'

[root@centos8 html]#tree
.
└── centos
    ├── 6
    │   └── isos
    │       └── x86_64
    ├── 7
    │   └── isos
    │       └── x86_64
    └── 8
        └── isos
            └── x86_64

10 directories, 0 files
[root@centos8 html]#mount /dev/sr0 centos/8/isos/x86_64/
mount: /var/www/html/centos/8/isos/x86_64: WARNING: device write-protected, mounted read-only.
[root@centos8 html]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          910228       0    910228   0% /dev
tmpfs             924716       0    924716   0% /dev/shm
tmpfs             924716   17508    907208   2% /run
tmpfs             924716       0    924716   0% /sys/fs/cgroup
/dev/nvme0n1p2 104806400 4768644 100037756   5% /
/dev/nvme0n1p3  52403200  398588  52004612   1% /data
/dev/nvme0n1p1    999320  131252    799256  15% /boot
tmpfs             184940       4    184936   1% /run/user/0
/dev/sr0         6967726 6967726         0 100% /var/www/html/centos/8/isos/x86_64
[root@centos8 html]#ls
centos
[root@centos8 html]#mkdir ksdir
[root@centos8 html]#cd ksdir/

把ks8.cfg应答文件拷贝到这个目录下面

[root@centos8 ksdir]#ls
ks8.cfg
[root@centos8 ksdir]#vim ks8.cfg 

# Use graphical install
#repo --name="Appstream"  --baseurl=http://192.168.39.8/centos/8/isos/x86_64/AppStream
url --url=http://192.168.32.8/centos/8/isos/x86_64/
#repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
# Use CDROM installation media
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network  --hostname=centos8.kaivi
# Root password
rootpw --iscrypted $6$OOwmaN2kXda4dp0t$oMs3ggugp0xuMknu6TqFyoZNPfka4LDIPftfqn1rrfkNmiQEJtUGPmvU2CbPjo0cvovkt4vBLIQPdb7Uz7vNe1
# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --password=$6$oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang"
# Disk partitioning information
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024

%packages
@^minimal-environment
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

%post
curl http://192.168.32.8/reset |bash
yum install vim -y
"ks8.cfg" 60L, 1805C                                     

把脚本也放在共享服务器上面,这里注意应答文件ks8.cfg中安装后脚本的路径要保持一致

[root@centos8 ~]#cd /var/www/html/
[root@centos8 html]#ls
centos  ksdir 
[root@centos8 html]#cp /data/init.sh ./reset
cp: overwrite './reset'? y
[root@centos8 html]#ls
centos  ksdir  reset

PXE自动化安装CentOS 8_第4张图片
PXE自动化安装CentOS 8_第5张图片
PXE自动化安装CentOS 8_第6张图片
可以正常访问,http服务正常

配置tftp服务

[root@centos8 ksdir]#cd /var/lib/tftpboot/
[root@centos8 tftpboot]#rpm -ql syslinux-nonlinux 
查找对应的安装包文件。这里我们需要/usr/share/syslinux/menu.c32和/usr/share/syslinux/pxelinux.0
拷贝到 /var/lib/tftpboot/内
[root@centos8 tftpboot]#cp /usr/share/syslinux/menu.c32 .
[root@centos8 tftpboot]#cp /usr/share/syslinux/pxelinux.0 .
[root@centos8 tftpboot]#ls
menu.c32  pxelinux.0

还需要对应的内核启动文件,这些文件在光盘里面有,可以直接拷贝过来

[root@centos8 tftpboot]#ls /var/www/html/centos/8/isos/x86_64/isolinux/
boot.cat  grub.conf   isolinux.bin  ldlinux.c32   libutil.c32  splash.png  vesamenu.c32
boot.msg  initrd.img  isolinux.cfg  libcom32.c32  memtest      TRANS.TBL   vmlinuz

[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/vmlinuz .
[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/initrd.img .
[root@centos8 tftpboot]#ls
initrd.img  menu.c32  pxelinux.0  vmlinuz

创建一个新的文件夹 pxelinux.cfg,里面用于放置菜单配置文件

[root@centos8 tftpboot]#mkdir pxelinux.cfg
[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/isolinux.cfg pxelinux.
pxelinux.0    pxelinux.cfg/ 
[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/isolinux.cfg pxelinux.
pxelinux.0    pxelinux.cfg/ 
[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/isolinux.cfg pxelinux.cfg/default
拷贝过来改名为default

[root@centos8 tftpboot]#vim /var/lib/tftpboot/pxelinux.cfg/default 
default menu.c32
timeout 600

menu title CentOS Linux 8

label linux
  menu label ^Auto Install CentOS Linux 8.0 mini
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.32.8/ksdir/ks8.cfg

label manual
  menu label ^Manual Install CentOS Linux 8.0
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://192.168.32.8/centos/8/isos/x86_64/

menu separator # insert an empty line


label local
   menu default
  menu label Boot from ^local drive
  localboot 0xffff

[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/ldlinux.c32 .
[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/libutil.c32 .
[root@centos8 tftpboot]#cp /var/www/html/centos/8/isos/x86_64/isolinux/libcom32.c32 .
centos 7上面以上三个可以不要  但是centos8上面对于上面三个文件有一定的依赖性,所以也要一起拷贝过来
[root@centos8 tftpboot]#tree
.
├── initrd.img
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│   └── default
└── vmlinuz

1 directory, 8 files

到这里tftp服务就配置好了

配置DHCP服务

[root@centos8 tftpboot]#systemctl start dhcpd
Job for dhcpd.service failed because the control process exited with error code.
See "systemctl status dhcpd.service" and "journalctl -xe" for details.
报错是因为没有配置/etc/dhcp/dhcpd.conf 这个文件暂时为空。需要复制参考文件
[root@centos8 tftpboot]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: overwrite '/etc/dhcp/dhcpd.conf'? y

[root@centos8 tftpboot]#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 180.76.76.76, 114.114.114.114;

default-lease-time 84600;
max-lease-time 100000;

# 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.32.0 netmask 255.255.255.0 {
  range 192.168.32.100 192.168.32.200;
  option routers 192.168.32.2;
  next-server 192.168.32.8;
  filename "pxelinux.0";
}
~          

重启服务即可

[root@centos8 ~]#systemctl restart dhcpd
[root@centos8 ~]#systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-11-14 14:12:29 CST; 5s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 10692 (dhcpd)
   Status: "Dispatching packets..."
    Tasks: 1 (limit: 11377)
   Memory: 5.1M
   CGroup: /system.slice/dhcpd.service
           └─10692 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

Nov 14 14:12:29 centos8 dhcpd[10692]: ** Ignoring requests on virbr0.  If this is not what
Nov 14 14:12:29 centos8 dhcpd[10692]: you want, please write a subnet declaration
Nov 14 14:12:29 centos8 dhcpd[10692]: in your dhcpd.conf file for the network segment
Nov 14 14:12:29 centos8 dhcpd[10692]: to which interface virbr0 is attached. **
Nov 14 14:12:29 centos8 dhcpd[10692]: 
Nov 14 14:12:29 centos8 dhcpd[10692]: Listening on LPF/eth0/00:0c:29:fe:da:42/192.168.32.0/24
Nov 14 14:12:29 centos8 dhcpd[10692]: Sending on   LPF/eth0/00:0c:29:fe:da:42/192.168.32.0/24
Nov 14 14:12:29 centos8 dhcpd[10692]: Sending on   Socket/fallback/fallback-net
Nov 14 14:12:29 centos8 dhcpd[10692]: Server starting service.
Nov 14 14:12:29 centos8 systemd[1]: Started DHCPv4 Server Daemon.
[root@centos8 ~]#

PEX自动化安装就配置好了

安装新系统

现在去安装一个新的centos8的系统
PXE自动化安装CentOS 8_第7张图片
选择菜单

PXE自动化安装CentOS 8_第8张图片

PXE自动化安装CentOS 8_第9张图片
安装成功
PXE自动化安装CentOS 8_第10张图片
脚本运行成功

扩展同时配置加载安装centos6 和 centos 7

需要安装什么系统,对应的光盘同样需要挂载上去
PXE自动化安装CentOS 8_第11张图片PXE自动化安装CentOS 8_第12张图片
查看web服务器上是否挂载
PXE自动化安装CentOS 8_第13张图片PXE自动化安装CentOS 8_第14张图片

现在配置应答文件,这里用之前已经做好的应答文件

[root@centos8 html]#cd /var/www/html/
[root@centos8 html]#ls
centos  ksdir  reset
[root@centos8 html]#cd ksdir/
[root@centos8 ksdir]#ls
ks8.cfg
[root@centos8 ksdir]#rz -E
rz waiting to receive.
[root@centos8 ksdir]#ls
ks6.cfg  ks7.cfg  ks8.cfg

修改对应的应答文件 特别是注意路径

[root@centos8 ksdir]#vim ks7.cfg 
[root@centos8 ksdir]#vim ks6.cfg 
[root@centos8 ksdir]#ll
-rw-r--r-- 1 root root 1235 Nov 14 16:13 ks6.cfg
-rw-r--r-- 1 root root 1435 Nov 14 16:09 ks7.cfg
-rw-r--r-- 1 root root 1805 Nov 14 14:35 ks8.cfg

PXE自动化安装CentOS 8_第15张图片
在网页需要分别能打开对应的应答文件,不然就是权限问题 需要设置一下权限

设置tftp配置文件

[root@centos8 tftpboot]#ls
initrd.img  ldlinux.c32  libcom32.c32  libutil.c32  menu.c32  pxelinux.0  pxelinux.cfg  vmlinuz

创建分别放置不同操作系统的目录6 7 8.用来放置不同的内核文件

[root@centos8 tftpboot]#mkdir {6,7,8}
[root@centos8 tftpboot]#mv vmlinuz initrd.img 8/

[root@centos8 tftpboot]#cp /var/www/html/centos/7/isos/x86_64/isolinux/vmlinuz ./7/
[root@centos8 tftpboot]#cp /var/www/html/centos/7/isos/x86_64/isolinux/initrd.img ./7/


[root@centos8 tftpboot]#cp /var/www/html/centos/6/isos/x86_64/isolinux/vmlinuz ./6/
[root@centos8 tftpboot]#cp /var/www/html/centos/6/isos/x86_64/isolinux/initrd.img ./6/
[root@centos8 tftpboot]#tree
.
├── 6
│   ├── initrd.img
│   └── vmlinuz
├── 7
│   ├── initrd.img
│   └── vmlinuz
├── 8
│   ├── initrd.img
│   └── vmlinuz
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

4 directories, 12 files

修改菜单项 注意路径 是相对路径

[root@centos8 tftpboot]#vim pxelinux.cfg/default 

default menu.c32
timeout 600

menu title CentOS Linux

label linux8
  menu label Auto Install CentOS Linux ^8.0 mini
  kernel 8/vmlinuz
  append initrd=8/initrd.img ks=http://192.168.32.8/ksdir/ks8.cfg

label linux7
  menu label Auto Install CentOS Linux ^7.0 mini
  kernel 7/vmlinuz
  append initrd=7/initrd.img ks=http://192.168.32.8/ksdir/ks7.cfg

label linux6
  menu label Auto Install CentOS Linux ^6.0 mini
  kernel 6/vmlinuz
  append initrd=6/initrd.img ks=http://192.168.32.8/ksdir/ks6.cfg


label manual
  menu label Manual Install CentOS Linux 8.0
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://192.168.32.8/centos/8/isos/x86_64/

menu separator # insert an empty line


label local
   menu default
  menu label Boot from ^local drive
  localboot 0xffff

参考文献如下

PXE自动化安装CentOS 8_第16张图片PXE自动化安装CentOS 8_第17张图片
PXE自动化安装CentOS 8_第18张图片PXE自动化安装CentOS 8_第19张图片PXE自动化安装CentOS 8_第20张图片PXE自动化安装CentOS 8_第21张图片

你可能感兴趣的:(linux,centos8,PXE自动化安装,PEX,linux,PEX)