部署准备
服务器
操作系统:rhel7.7
软件准备: rhel-server-7.5-x86_64-dvd.iso、rhel-server-7.7-x86_64-dvd.iso
客户机
硬件配置:至少2G以上内存
基础环境准备
关闭selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
关闭防火墙
yum remove -y firewalld
配置网络
nmcli con add type ethernet ifname eno1 con-name eno1 ipv4.method manual ipv4.addr 192.168.100.0/24
安装yum软件环境
准备镜像源
已将rhel-server-7.5-x86_64-dvd.iso和rhel-server-7.7-x86_64-dvd.iso传入服务器
mkdir -p /mnt/rhel77
mkdir -p /mnt/rhel75
mount -t loop rhel-server-7.7-x86_64-dvd.iso /mnt/rhel77
mount -t loop rhel-server-7.5-x86_64-dvd.iso /mnt/rhel75
配置yum源
cat << EOF > /etc/yum.repos.d/rhel77.repo
redhat-Base.repo
[base]
name=Redhat-$releasever
failovermethod=priority
baseurl=file:///mnt/rhel77/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
安装httpd服务
yum clean all
yum repolist
yum install -y wget httpd rsync createrepo
http源配置
mkdir -p /var/www/html/yum/rhel77
mkdir -p /var/www/html/yum/rhel75
rsync -aS /mnt/rhel77/ /var/www/html/yum/rhel77/
rsync -aS /mnt/rhel75/ /var/www/html/yum/rhel75/
createrepo -g /var/www/html/yum/rhel77/6d132b085489dcfe4a0ee2b4c38d9578c38ab83cebe4df87e3a409b48e8fee57-comps-Server.x86_64.xml /var/www/html/yum/rhel77/
createrepo -g /var/www/html/yum/rhel75/2a2dc8f8a66f9c4d8b7a8ac2ec308594b97c344ec0810266cdf0795d9f77e965-comps-Server.x86_64.xml /var/www/html/yum/rhel75/
配置repo文件
mkdir -p /var/www/html/repo
cat << EOF > /var/www/html/repo/rhel77.repo
redhat-Base.repo
[base]
name=Redhat-$releasever
failovermethod=priority
baseurl=http://192.168.100.1/yum/rhel77/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
cat << EOF > /var/www/html/repo/rhel75.repo
redhat-Base.repo
[base]
name=Redhat-$releasever
failovermethod=priority
baseurl=http://192.168.100.1/yum/rhel75/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
cp -pf /var/www/html/repo/rhel77.repo /etc/yum.repos.d/rhel77.repo
yum clean all
yum repolist
安装PXE网络环境
安装软件包
yum install -y tftp-server dhcp xinetd
配置xinetd
修改/etc/xinet.d/tftp,将 disabled 参数从 yes 改为 no
配置dhcp
修改/etc/dhcp/dhcpd.conf
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
subnet 192.168.100.0 netmask 255.255.255.0 {
option routers 192.168.100.1;
range 192.168.100.2 192.168.100.250;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.100.1;
if option architecture-type = 00:07 {
filename "uefi/shim.efi";
} else {
filename "pxelinux/pxelinux.0";
}
}
}
配置tftp
为使用BIOS的系统配置
提取配置文件
mkdir -p /root/kickstart/
cp -pr /var/www/html/yum/rhel77/Packages/syslinux-4.05-15.el7.x86_64.rpm /root/kickstart/
cd /root/kickstart/
rpm2cpio syslinux-4.05-15.el7.x86_64.rpm | cpio -dimv
mkdir /var/lib/tftpboot/pxelinux
cp /root/kickstart/usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux/
cp /root/kickstart/usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/pxelinux/
mkdir -p /var/lib/tftpboot/pxelinux/pxelinux.cfg
提取内核文件
mkdir -p /var/lib/tftpboot/images/
mkdir -p /var/lib/tftpboot/images/rhel77
mkdir -p /var/lib/tftpboot/images/rhel75
cp /var/www/html/yum/rhel77/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/images/rhel77/
cp /var/www/html/yum/rhel75/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/images/rhel75/
配置文件:/var/lib/tftpboot/pxelinux/pxelinux.cfg/default
default vesamenu.c32
prompt 1
timeout 600
label rhel77
menu label ^Install system
menu default
kernel images/rhel77/vmlinuz
append initrd=images/rhel77/initrd.img ip=dhcp inst.repo=http://192.168.100.1/yum/rhel77/ inst.ks=http://192.168.100.1/ksstart/ks77.cfg
label rhel75
menu label ^Install system
menu default
kernel images/rhel75/vmlinuz
append initrd=images/rhel75/initrd.img ip=dhcp inst.repo=http://192.168.100.1/yum/rhel75/ inst.ks=http://192.168.100.1/ksstart/ks75.cfg
为使用UEFT的系统配置
提取配置文件
cp -pr /var/www/html/yum/rhel77/Packages/shim-x64-15-2.el7.x86_64.rpm /root/kickstart/
cp -pr /var/www/html/yum/rhel77/Packages/grub2-efi-x64-2.02-0.80.el7.x86_64.rpm /root/kickstart/
cd /root/kickstart/
rpm2cpio shim-x64-15-2.el7.x86_64.rpm | cpio -dimv
rpm2cpio grub2-efi-x64-2.02-0.80.el7.x86_64.rpm | cpio -dimv
mkdir /var/lib/tftpboot/uefi
cp /root/kickstart/boot/efi/EFI/redhat/shim.efi /var/lib/tftpboot/uefi/
cp /root/kickstart/boot/efi/EFI/redhat/grubx64.efi /var/lib/tftpboot/uefi/
提取内核文件
mkdir -p /var/lib/tftpboot/images/
mkdir -p /var/lib/tftpboot/images/rhel77
mkdir -p /var/lib/tftpboot/images/rhel75
cp /var/www/html/yum/rhel77/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/images/rhel77/
cp /var/www/html/yum/rhel75/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/images/rhel75/
配置文件 /var/lib/tftpboot/uefi/grub.cfg
set timeout=60
menuentry 'RHEL 7.7' {
linuxefi images/rhel77/vmlinuz ip=dhcp inst.repo=http://192.168.100.1/yum/rhel77/ inst.ks=http://192.168.100.1/ksstart/ks77efi.cfg
initrdefi images/rhel77/initrd.img
}
menuentry 'RHEL 7.5' {
linuxefi images/rhel75/vmlinuz ip=dhcp inst.repo=http://192.168.100.1/yum/rhel75/ inst.ks=http://192.168.100.1/ksstart/ks75efi.cfg
initrdefi images/rhel75/initrd.img
}
kickstart配置
创建配置文件
mkdir -p /var/www/html/ksstart/
配置文件示例:ks77efi.cfg
System authorization information
auth --enableshadow --passalgo=sha512
Use Http install repo
url --url=http://192.168.100.1/yum/rhel77/
Use text install
text
Run the Setup Agent on first boot
firstboot --disable
firewall --disabled
selinux --disabled
格式化安装磁盘,这里的sda需要替换成对应的设备名
ignoredisk --only-use=sda
安装后操作
reboot
Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
System language
lang en_US.UTF-8
Network information,网卡设备名换成现有设备名
network --bootproto=dhcp --device=ens33 --onboot=on --activate
Root password
rootpw --plaintext 12345678
System services
services --disabled="chronyd"
System timezone
timezone Asia/Shanghai
System bootloader configuration 这里的sda需要替换成对应的设备名
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
clearpart --none --initlabel 这里的sda需要替换成对应的设备名
clearpart --none --initlabel --drives=sda
Disk partitioning information
分区操作,请自行根据硬件配置和需求修改
/boot/efi 分区只有只用uefi引导启动需要,使用bios启动请忽略
part /boot/efi --fstype="efi" --size=200 --ondisk=sda --fsoptions="defaults,uid=0,gid=0,umask=0077,shortname=winnt"
part /boot --fstype="xfs" --size=1024 --ondisk=sda
part pv.01 --ondisk=sda --grow --asprimary
volgroup rhel pv.01
logvol swap --fstype="swap" --name="swap" --vgname="rhel" --size=32768
logvol / --fstype="xfs" --name="root" --vgname="rhel" --size=409600
logvol /home --fstype="xfs" --name="home" --vgname="rhel" --size=204800
logvol /var/log --fstype="xfs" --name="var_log" --vgname="rhel" --size=204800
logvol /var/lib/docker --fstype="xfs" --name="var_lib_docker" --vgname="rhel" --size=204800
预执行操作,使用uefi引导gpt盘必须要先设定盘未gpt
%pre
parted -s /dev/sda mklabel gpt
%end
安装软件
%packages
@^minimal
@core
kexec-tools
wget
net-tools
%end
后执行操作
%post
cd /etc/yum.repos.d/
rm -rf /etc/yum.repos.d/*
wget http://192.168.100.1/repo/rhel75.repo
%end
服务启动
systemctl start xinetd
systemctl start httpd
systemctl start dhcpd
systemctl start tftp
客户端引导安装
按照默认方式启动服务器,选择启动项,按PXE启动服务器,选择相应的安装软件 rhel75或者rhel75 即可自行安装操作系统