pxe自动化部署Linux系统

pxe自动化部署Linux系统

实验准备:虚拟机centos 7

需要部署:DHCP服务器,TFTP服务器,HTTP服务器

准备工作

[root@centos771 tftpboot]# yum -y install tree


# 关闭防火墙
[root@centos771 ~]# systemctl stop firewalld
[root@centos771 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2020-09-10 12:45:23 CST; 6s ago
     Docs: man:firewalld(1)
  Process: 633 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 633 (code=exited, status=0/SUCCESS)

Sep 05 21:55:02 centos771 systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 05 21:55:03 centos771 systemd[1]: Started firewalld - dynamic firewall daemon.
Sep 10 12:45:22 centos771 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Sep 10 12:45:23 centos771 systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@centos771 ~]# 


# 禁用selinux
1、临时修改
[root@centos771 ~]# setenforce 0   
[root@centos771 ~]# getenforce
Permissive


2、永久修改,需要重启
[root@centos771 ~]# vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled   #---将enforcing修改为disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

1、HTTP服务器

[root@centos771 ~]# yum -y install httpd

[root@centos771 ~]# systemctl start httpd
[root@centos771 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-09-10 12:44:52 CST; 11min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 12492 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─12492 /usr/sbin/httpd -DFOREGROUND
           ├─12502 /usr/sbin/httpd -DFOREGROUND
           ├─12503 /usr/sbin/httpd -DFOREGROUND
           ├─12504 /usr/sbin/httpd -DFOREGROUND
           ├─12505 /usr/sbin/httpd -DFOREGROUND
           └─12506 /usr/sbin/httpd -DFOREGROUND

Sep 10 12:44:40 centos771 systemd[1]: Starting The Apache HTTP Server...
Sep 10 12:44:46 centos771 httpd[12492]: AH00558: httpd: Could not reliably determine the server's fully qualified domain na...message
Sep 10 12:44:52 centos771 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos771 ~]# 

# 挂载光盘文件到HTTP的共享文件里
[root@centos771 ~]# mkdir -p /var/www/html/centos/7/
  
[root@centos771 ~]# mount /dev/sr0 /var/www/html/centos/7/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos771 ~]# ls /var/www/html/centos/7/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@centos771 ~]# 

[root@centos771 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:10:96:2e brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.71/24 brd 10.0.0.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe10:962e/64 scope link 
       valid_lft forever preferred_lft forever
[root@centos771 ~]# 

# 通过浏览器访问该IP地址文件路径
http://10.0.0.71/centos/7/

在这里插入图片描述

2、kickstart应答文件

# 使用的连接方式是通过**Xshell 7 + Xmanager**进行连接,需要下载xmanager
[root@centos771 ~]# yum -y groupinstall  "X Window System" "Fonts"

# 新开窗口-属性-隧道-选中'转发X11'-选择'Xmanager'-连接
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu Sep 10 11:53:36 2020 from 10.0.0.1
[root@centos771 ~]# 

部署应答文件,安装图形工具

[root@centos771 ~]# yum -y install system-config-kickstart
[root@centos771 ~]# export DISPLAY=10.0.0.1:0.0 # 主机IP

在这里插入图片描述

# 启动
[root@centos771 ~]# system-config-kickstart

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

应答文件放到HTTP共享文件夹里

[root@centos771 ~]# ls
anaconda-ks.cfg  ks.cfg  
[root@centos771 ~]# mkdir /var/www/html/ksdir
[root@centos771 ~]# cp ks.cfg /var/www/html/ksdir/ks7.cfg
[root@centos771 ~]# ls /var/www/html/ksdir/
ks7.cfg
[root@centos771 ~]# 

[root@centos771 ~]# vim /var/www/html/ksdir/ks7.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
#ignoredisk --only-use=sda
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# System language
lang en_US.UTF-8
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --enable
# SELinux configuration
selinux --disabled

# Do not configure the X Window System
skipx

# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
network  --hostname=centos7
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.71/centos/7"
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="xfs" --ondisk=sda --size=1024
part / --fstype="xfs" --ondisk=sda --size=10240
part /data --fstype="xfs" --ondisk=sda --size=51200


[root@centos771 ~]# 

在这里插入图片描述

3、TFTP服务器

[root@centos771 ~]# yum -y install tftp-server
[root@centos771 ~]# systemctl start tftp 
[root@centos771 ~]# systemctl status tftp 
● tftp.service - Tftp Server
   Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
   Active: active (running) since Thu 2020-09-10 12:34:10 CST; 8s ago
     Docs: man:in.tftpd
 Main PID: 12304 (in.tftpd)
   CGroup: /system.slice/tftp.service
           └─12304 /usr/sbin/in.tftpd -s /var/lib/tftpboot

Sep 10 12:34:10 centos771 systemd[1]: Started Tftp Server.
[root@centos771 ~]# 


# /var/lib/tftpboot/ # 此路径是TFTP服务器的共享文件路径
[root@centos771 ~]# cd /var/lib/tftpboot/
[root@centos771 tftpboot]# 

4、pxe引导文件

# 安装提供引导文件的软件包
[root@centos771 ~]# yum -y install syslinux

# pxelinux.0文件路径
[root@centos771 ~]# rpm -ql syslinux | grep pxelinux
/usr/share/doc/syslinux-4.05/pxelinux.txt
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/gpxelinuxk.0
/usr/share/syslinux/pxelinux.0
[root@centos771 ~]# 

# 拷贝pxe引导文件到TFTP共享文件目录下
[root@centos771 ~]# cd /var/lib/tftpboot/
[root@centos771 tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
[root@centos771 tftpboot]# ls
pxelinux.0

5、DHCP服务器

# 安装并启动服务
[root@centos771 ~]# yum -y install dhcp

# 启动服务,查看报错信息
[root@centos771 ~]# 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.
[root@centos771 ~]# 

[root@centos771 ~]# systemctl status dhcpd.service
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-09-10 11:26:56 CST; 1min 22s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
  Process: 2528 ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid (code=exited, status=1/FAILURE)
 #  /etc/dhcp/dhcpd.conf  > dhcp 配置文件
 
 Main PID: 2528 (code=exited, status=1/FAILURE)

Sep 10 11:26:56 centos771 dhcpd[2528]: All rights reserved.
Sep 10 11:26:56 centos771 dhcpd[2528]: For info, please visit https://www.isc.org/software/dhcp/
Sep 10 11:26:56 centos771 dhcpd[2528]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified ...ig file
Sep 10 11:26:56 centos771 dhcpd[2528]: Wrote 0 leases to leases file.
Sep 10 11:26:56 centos771 dhcpd[2528]: 
Sep 10 11:26:56 centos771 dhcpd[2528]: No subnet declaration for ens32 (10.0.0.71).
Sep 10 11:26:56 centos771 systemd[1]: dhcpd.service: main process exited, code=exited, status=1/FAILURE
Sep 10 11:26:56 centos771 systemd[1]: Failed to start DHCPv4 Server Daemon.
Sep 10 11:26:56 centos771 systemd[1]: Unit dhcpd.service entered failed state.
Sep 10 11:26:56 centos771 systemd[1]: dhcpd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos771 ~]# 

修改配置文件

[root@centos771 ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
	# 根据提示信息查看文件

#   see dhcpd.conf(5) man page
#

[root@centos771 ~]# cat /usr/share/doc/dhcp*/dhcpd.conf.example
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# 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.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

host passacaglia {
  hardware ethernet 0:0:c0:5d:bd:95;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
}

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

class "foo" {
  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}

shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo";
    range 10.0.29.10 10.0.29.230;
  }
}
[root@centos771 ~]# 

# 复制
[root@centos771 ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@centos771 ~]# vim /etc/dhcp/dhcpd.conf
[root@centos771 ~]# vim /etc/dhcp/dhcpd.conf

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "baidu.org";  # 设置dhcp域名
option domain-name-servers 114.114.114.114, 8.8.8.8; # 设置DNS

default-lease-time 3600;  # 设置分配的IP有效时间
max-lease-time 72000;     # 设置最大的有效时间

# 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.

# ---- 设置dhcp的ip,子网掩码
subnet 10.0.0.0 netmask 255.255.255.0 {
        range 10.0.0.50 10.0.0.100;  # 分配的IP范围
        option broadcast-address 10.0.0.2;  # 网关
        next-server 10.0.0.71;  # 指定TFTP的IP
        filename "pxelinux.0";  # 指定pxelinux引导文件路径
}
..........
:.,$s/^\([^#]\)/#\1/  # 注释掉不需要的代码

重启并监控日志

[root@centos771 ~]# systemctl restart dhcpd
[root@centos771 ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-09-10 11:51:52 CST; 10s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 2558 (dhcpd)
   Status: "Dispatching packets..."
   CGroup: /system.slice/dhcpd.service
           └─2558 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

Sep 10 11:51:52 centos771 dhcpd[2558]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified ...ig file
Sep 10 11:51:52 centos771 dhcpd[2558]: Internet Systems Consortium DHCP Server 4.2.5
Sep 10 11:51:52 centos771 dhcpd[2558]: Copyright 2004-2013 Internet Systems Consortium.
Sep 10 11:51:52 centos771 dhcpd[2558]: All rights reserved.
Sep 10 11:51:52 centos771 dhcpd[2558]: For info, please visit https://www.isc.org/software/dhcp/
Sep 10 11:51:52 centos771 dhcpd[2558]: Wrote 0 leases to leases file.
Sep 10 11:51:52 centos771 dhcpd[2558]: Listening on LPF/ens32/00:0c:29:10:96:2e/10.0.0.0/24
Sep 10 11:51:52 centos771 dhcpd[2558]: Sending on   LPF/ens32/00:0c:29:10:96:2e/10.0.0.0/24
Sep 10 11:51:52 centos771 systemd[1]: Started DHCPv4 Server Daemon.
Sep 10 11:51:52 centos771 dhcpd[2558]: Sending on   Socket/fallback/fallback-net
Hint: Some lines were ellipsized, use -l to show in full.

# 监控日志
[root@centos771 ~]# tail -f /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.2.5

server-duid "\000\001\000\001&\354_N\000\014)\020\226.";

6、TFTP服务器部署相关文件

# 部署开机菜单页面
[root@centos771 ~]# cd /var/lib/tftpboot/
[root@centos771 tftpboot]# mkdir pxelinux.cfg
[root@centos771 tftpboot]# ls
pxelinux.0  pxelinux.cfg
[root@centos771 tftpboot]# 

[root@centos771 tftpboot]# ls /var/www/html/centos/7/isolinux/
boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz
boot.msg  initrd.img  isolinux.cfg  splash.png  vesamenu.c32
# 拷贝菜单文件并重命名
[root@centos771 tftpboot]# cp /var/www/html/centos/7/isolinux/isolinux.cfg pxelinux.cfg/default

# 部署背景图片
[root@centos771 tftpboot]# cp /var/www/html/centos/7/isolinux/splash.png .

# 拷贝内核文件
[root@centos771 tftpboot]# cp /var/www/html/centos/7/isolinux/vmlinuz .

# 拷贝驱动文件
[root@centos771 tftpboot]# cp /var/www/html/centos/7/isolinux/initrd.img .

# 拷贝图形模块
[root@centos771 tftpboot]# cp /var/www/html/centos/7/isolinux/vesamenu.c32 .


[root@centos771 tftpboot]# ll 
total 60548
-rw-r--r--. 1 root root 55073584 Sep 10 14:22 initrd.img
-rw-r--r--. 1 root root    26759 Sep 10 12:38 pxelinux.0
drwxr-xr-x. 2 root root       21 Sep 10 14:16 pxelinux.cfg
-rw-r--r--. 1 root root      186 Sep 10 14:20 splash.png
-rw-r--r--. 1 root root   153104 Sep 10 14:22 vesamenu.c32
-rwxr-xr-x. 1 root root  6734016 Sep 10 14:21 vmlinuz
[root@centos771 tftpboot]# tree
.
├── initrd.img    # 驱动文件
├── pxelinux.0    # pxe引导文件
├── pxelinux.cfg  
│   └── default	  # 菜单文件
├── splash.png    # 菜单背景图片
├── vesamenu.c32  # 菜单图形模块
└── vmlinuz       # 内核文件

1 directory, 6 files
[root@centos771 tftpboot]# 

# 修改菜单文件
[root@centos771 tftpboot]# vim pxelinux.cfg/default 
default vesamenu.c32
timeout 600

menu background splash.png
menu title CentOS 7

label auto linux
  menu label ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img ks=http://10.0.0.71/ksdir/ks7.cfg

label manual
  menu label Test this ^media & install CentOS 7
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://10.0.0.71/centos/7/

# 救援模式
label rescue
  menu label ^Rescue a CentOS Linux system
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://10.0.0.71/centos/8/ rescue

# 默认启动已安装好的系统
label local
  menu default      #默认启动硬盘,防止系统被重装
  menu label Boot from ^local drive
  localboot 0xffff


重启服务器

[root@centos771 tftpboot]# systemctl restart httpd
[root@centos771 tftpboot]# systemctl restart dhcpd
[root@centos771 tftpboot]# systemctl restart tftp

测试

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

注意:报错信息

报错1:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NX9sWA7M-1600001897539)(C:\Users\superman\AppData\Roaming\Typora\typora-user-images\image-20200910171509536.png)]

Warning: deu/root does not exist
Generating "run/initramfs/rdsosreport .txt"
Entering emergency mode. Exit the shell to cotinue.
Tupe "journa lctl" to uieu sustem logs .
You might uant to saue "rruninitranfs/rdsosreport.txt" to a USB stick or /boot
after mounting them and attach it to a bug report.

解决方法:编辑虚拟机----内存---- > 2G

说明:centos7和8需要虚拟内存最少2G

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HYiA7z22-1600001897540)(C:\Users\superman\AppData\Roaming\Typora\typora-user-images\image-20200910170150420.png)]

在启动界面按esc进入,选择网络安装

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CGYkajU4-1600001897541)(C:\Users\superman\AppData\Roaming\Typora\typora-user-images\image-20200910170305873.png)]

7、部署三个操作系统

步骤:

1、centos7安装HTTP服务器,添加6,7,8的镜像文件并挂载到HTTP共享文件下面

# 插入centos6,7,8光盘
[root@centos7 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan ;echo "- - -" > /sys/class/scsi_host/host1/scan;echo "- - -" > /sys/class/scsi_host/host2/scan    #读取插入的光盘
[root@centos7 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0    2G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0   50G  0 part /data
sr0     11:0    1  3.7G  0 rom  
sr1     11:1    1    7G  0 rom  
sr2     11:2    1  4.4G  0 rom  

[root@centos7 ~]# yum -y install httpd;systemctl enable --now httpd   #安装httpd服务,并开启

[root@centos771 ~]# ls /var/www/html/centos/
6  7  8
[root@centos771 ~]# ls /var/www/html/centos/6
CentOS_BuildTag  GPL       Packages                  RPM-GPG-KEY-CentOS-6           RPM-GPG-KEY-CentOS-Testing-6
EFI              images    RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Debug-6     TRANS.TBL
EULA             isolinux  repodata                  RPM-GPG-KEY-CentOS-Security-6
[root@centos771 ~]# ls /var/www/html/centos/7
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@centos771 ~]# ls /var/www/html/centos/8
AppStream  BaseOS  EFI  images  isolinux  media.repo  TRANS.TBL
[root@centos771 ~]# 

2、分别将各个已安装好的虚拟机root目录下的.cfg文件上传到centos7共享文件下
[root@centos771 tftpboot]# tree /var/www/html/ksdir/
/var/www/html/ksdir/
├── ks6.cfg
├── ks7.cfg
└── ks8.cfg

[root@centos771 ~]# cat /var/www/html/ksdir/ks6.cfg 
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
lang en_US.UTF-8
url --url=http://10.0.0.71/centos/6/
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$cbCNviUY4I7g6x0Q$QOKb7MkJFg8X/U6DcfrR4ESroVOdn6jg7eVzAjTRUrQ.yU4BRc65/4n8kt8qgbqT/wqrUdF1GW8uH48U/y06y/
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --none
zerombr
clearpart --all --initlabel
part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=50000
part /data --fstype=ext4 --size=30000
part swap --size=2048
#part /boot --fstype=ext4 --size=1000
#part / --fstype=ext4 --size=10000
#part /data --fstype=ext4 --size=10000

#part swap --size=2000


#repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100

%packages
@base
@core
@fonts
@server-policy
@workstation-policy
@x11
%end

%post
useradd wang
echo magedu | passwd --stdin wang &> /dev/null
%end


# ks7.cfg
[root@centos771 ~]# cat /var/www/html/ksdir/ks7.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
#ignoredisk --only-use=sda
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# System language
lang en_US.UTF-8
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --enable
# SELinux configuration
selinux --disabled

# Do not configure the X Window System
skipx

# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
network  --hostname=centos7
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.71/centos/7"
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="xfs" --ondisk=sda --size=1024
part / --fstype="xfs" --ondisk=sda --size=10240
part /data --fstype="xfs" --ondisk=sda --size=51200

# ks8.cfg
[root@centos771 ~]# cat /var/www/html/ksdir/ks8.cfg 
#version=RHEL8
ignoredisk --only-use=sda
text
reboot
zerombr

# Partition clearing information
clearpart --all --initlabel
# Use graphical install
#graphical
#repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
# Use CDROM installation media
#cdrom
url --url=http://10.0.0.71/centos/8/BaseOS/
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
network  --hostname=centos82
# Root password
rootpw --iscrypted $6$LZaB7kO7I1RVA56J$6njSqc3wvnnggpCfwI.ddXXeCuNkcO6At1ZYq6VX4cmLA5RAS2ntakjbwR87Aejao.e7NPw0oocfXqLrw6D1a1
# 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=centos80 --password=$6$h8UwxiZ9B2DrU40P$2FJZEGwh2lJOaDV6LzGI7e69FIPEwoB.qQDAiDEzkh4kF.1CUKgG5ySaTnukdV8uGlVbQMOGrjR9yyRgL//nO1 --iscrypted --gecos="centos80"
# 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
useradd mage
echo magedu | passwd --stdin mage &> /dev/null
%end




3、安装DHCP服务器,并修改配置文件

[root@centos771 ~]# cat /etc/dhcp/dhcpd.conf 
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "baidu.org";
option domain-name-servers 114.114.114.114, 8.8.8.8;

default-lease-time 3600;
max-lease-time 72000;

# 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.

subnet 10.0.0.0 netmask 255.255.255.0 {
	range 10.0.0.50 10.0.0.100;
	option broadcast-address 10.0.0.2;
	next-server 10.0.0.71;
	filename "pxelinux.0";	
}



4、安装pxelinux
yum -y install syslinux
# pxelinux.0文件路径
[root@centos771 ~]# rpm -ql syslinux | grep pxelinux
/usr/share/doc/syslinux-4.05/pxelinux.txt
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/gpxelinuxk.0
/usr/share/syslinux/pxelinux.0   <----




5、安装TFTP服务器
创建相关目录及拷贝相关文件
[root@centos771 ~]# cd /var/lib/tftpboot/
[root@centos771 tftpboot]# tree
.
├── centos6
│   ├── initrd.img
│   └── vmlinuz
├── centos7
│   ├── initrd.img
│   └── vmlinuz
├── centos8
│   ├── initrd.img	# 驱动文件
│   └── vmlinuz     # 内核文件
├── ldlinux.c32	   --
├── libcom32.c32     | # 此三个文件是CentOS8安装所必须文件
├── libutil.c32    --
├── pxelinux.0      # pxe引导文件
├── pxelinux.cfg
│   └── default     # 菜单设置文件
├── splash.png      # 背景图片
├── splash.png.1
└── vesamenu.c32    # 图形模块

4 directories, 11 files
-----------------------------------------------------------
#以下三个文件是CentOS8安装所必须文件,CentOS6,7则不需要
[root@centos8 ~]#cp /var/www/html/centos/8/os/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/
-----------------------------------------------------------

[root@centos771 tftpboot]# cat pxelinux.cfg/default 
default vesamenu.c32
timeout 600

menu background splash.png
menu title CentOS 

label auto linux
  menu label ^Install CentOS 6
  kernel centos6/vmlinuz
  append initrd=centos6/initrd.img ks=http://10.0.0.71/ksdir/ks6.cfg 

label auto linux
  menu label ^Install CentOS 7
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img ks=http://10.0.0.71/ksdir/ks7.cfg

label auto linux
  menu label ^Install CentOS 8
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img ks=http://10.0.0.71/ksdir/ks8.cfg

# 救援模式光盘启动
label rescue
  menu label ^Rescue a CentOS Linux system
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img inst.repo=http://10.0.0.8/centos/8/ rescue quiet
			# yum源仓库路径

# 超时默认启动已安装好的系统
label local
  menu default
  menu label Boot from ^local drive
  localboot 0xffff

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XS4iIa42-1600001897542)(C:\Users\superman\AppData\Roaming\Typora\typora-user-images\image-20200910170353214.png)]

猜你喜欢

转载自blog.csdn.net/weixin_43976886/article/details/108568086