首页 > 其他分享 >kickstart+pxe 多系统引导服务器搭建

kickstart+pxe 多系统引导服务器搭建

时间:2022-12-24 18:25:26浏览次数:40  
标签:www kickstart ks tftpboot html var 服务器 pxe

1. 装包

注:centos8下载dhcp-server,centos7下载dhcp

yum -y install tftp-server httpd syslinux-nonlinux dhcp*

2. 配置dhcp服务

注:需要使用dhcp服务对接pxe客户机

注:{}内的缩进为两个空格

cat >/etc/dhcp/dhcpd.conf <<EOF_DHCP
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#

log-facility local7;

# A slightly different configuration for an internal subnet.
subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.10 192.168.10.20;
  option domain-name-servers ks.pxe.dhcp;
  option domain-name "pxe.dhcp";
  option routers 192.168.10.2;
  option domain-name-servers 8.8.8.8;
  option broadcast-address 192.168.10.255;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 192.168.10.7;  #tftp服务器地址
  filename "pxe/pxelinux.0";  #tftp目录下的路径
}

EOF_DHCP

3. http 配置

注:可直接挂载,也可先挂载iso,在复制其中所有文件到指定目录

注:若使用ftp,可直接使用使用匿名用户,或自定义用户后使用密码登陆也行,但ftp涉及到权限问题稍麻烦一点,一般不能直接挂载镜像共享

mkdir /var/www/html{centos7,centos8,anolis,ks}
mount CentOS_8*_x86_64.iso /var/www/html/centos8
mount Anolis_*.iso /var/www/html/anolis
mount CentOS_7*.iso /var/www/html/centos7

注:centos7的ks文件

cat > /var/www/html/ks/c7_ks.cfg <<EOF_KS
#version=RHEL
# Use graphical/text install  #图形化/字符安装界面
graphical

#要实际运行安装,必须指定 cdrom、harddrive、hmc、nfs、liveimg 或 url 之一
url --url=http://192.168.10.7/centos7

#最小化安装,及其他预装应用
%packages
@^minimal
kexec-tools
bash-completion

%end

#使用美式键盘
keyboard --xlayouts='us'
#系统默认语言设置,即环境变量$LANG,--addsupport添加对附加语言的支持
lang en_US.UTF-8 --addsupport=zh_CN

#设置主机名
network  --hostname=santiagod.ks

#enable时,系统第一次引导时启动 Initial Setup,设置语言、鼠标、键盘、root 密码、安全级别、时区以及默认网络配置。默认为disable
firstboot --disable

#使用这个选项在没有用户互动的情况下接受最终用户许可证协议(End User License Agreement,EULA)。指定这个选项可防止 Initial Setup 在完成安装并第一次重启系统后提示您接受该许可证
eula --agreed

#系统时区上海,使用UTC时间,不开启时间同步
timezone Asia/Shanghai --isUtc --nontp

# Root password: Admin123!
rootpw --iscrypted $6$uMfDCfQnqrZgk/yL$F.DkU0TF2k14QNqLUv.cc8X16ZUXGe/8Q./rspkY1tKnmOywrgcBx.eEA7u9oWT/u2T6jzNM410EL1Uy5oPk9/

#禁用selinux与firewalld
firewall --disabled
selinux  --disabled

#安装完成后,重启系统
#--eject - 在重新启动前尝试弹出可引导介质(DVD、USB 或其他介质)
reboot --eject

%include /tmp/part-include

#禁用kdump
%addon com_redhat_kdump --disable --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


#------------------------------------------------------------------------------------------------------------------------------------------------------
%pre

###设置系统盘
#找到大于10G的盘,且系统只安装在第一块逻辑盘上
disk=$(while read line;do awk 'BEGIN{} {if ($3 >= "10485760" && $2 == "0") print $4} END{}';done < /proc/partitions|grep -Ew 'sda|vda|hda')
#disk=sda或vda或hda

cat > /tmp/part-include << EOF_PART
#ignoredisk --only-use=$disk
clearpart --drives=$disk --all --initlabel

#基于 UEFI 的 AMD64、Intel 64 和 64 位 ARM 需要 200 MiB EFI 系统分区。推荐的最小值是 200 MiB,默认大小为 600 MiB,最大为 600 MiB。BIOS 系统不需要 EFI 系统分区
part /boot/efi --fstype="efi" --ondisk=$disk --size=600 --fsoptions="umask=0077,shortname=winnt"
#将sda创建为ID:311的物理卷,最小10G,若磁盘大于10G,也全部做成物理卷
#--grow 自增长
part pv.311 --fstype="lvmpv" --ondisk=$disk --size=10240 --grow
#boot分区,建议大小1G
part /boot --fstype="xfs" --ondisk=$disk --size=1024
#将pv.311加入卷组,默认pe大小4M
volgroup santiagod --pesize=4096 pv.311
#逻辑卷-交换空间,视磁盘大小而定,为安装时的系统盘大小10%
logvol swap --fstype="swap" --recommended --name=swap --vgname=santiagod
#逻辑卷-根分区,虽然 5 GiB 根文件系统允许您最小安装,但建议至少分配 10 GiB,以便可以尽可能安装您想要的软件包组
logvol / --fstype="xfs" --size=10240 --grow --name=root --vgname=santiagod

EOF_PART
#-------------------------------------------------------------------------------------------------------------
%end

EOF_KS

注:centos8的ks文件

cat > /var/www/html/ks/c8_ks.cfg <<EOF_KS 
#version=RHEL
# Use graphical/text install  #图形化/字符安装界面
#text
graphical

#使用系统上的第一个光驱执行安装
#cdrom
#装机使用的yum源
#repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-cdrom/AppStream

#要实际运行安装,必须指定 cdrom、harddrive、hmc、nfs、liveimg 或 url 之一
url --url=http://192.168.10.7/centos8

#最小化安装,及其他预装应用
%packages
@^minimal-environment
kexec-tools
bash-completion

%end

#使用美式键盘
keyboard --xlayouts='us'
#系统默认语言设置,即环境变量$LANG,--addsupport添加对附加语言的支持
lang en_US.UTF-8 --addsupport=zh_CN

#设置主机名
network  --hostname=santiagod.ks
#IP设置,需指明device,否则会取消后续所有network指令
#network --bootproto=static --ip=192.168.122.10 --netmask=255.255.255.0 --gateway=192.168.122.1 --nameserver=8.8.8.8,114.114.114.114 --device=ens192


#enable时,系统第一次引导时启动 Initial Setup,设置语言、鼠标、键盘、root 密码、安全级别、时区以及默认网络配置。默认为disable
firstboot --disable

#使用这个选项在没有用户互动的情况下接受最终用户许可证协议(End User License Agreement,EULA)。指定这个选项可防止 Initial Setup 在完成安装并第一次重启系统后提示您接受该许可证
eula --agreed

#系统时区上海,使用UTC时间,不开启时间同步
timezone Asia/Shanghai --isUtc --nontp

# Root password: Admin123!
rootpw --iscrypted $6$uMfDCfQnqrZgk/yL$F.DkU0TF2k14QNqLUv.cc8X16ZUXGe/8Q./rspkY1tKnmOywrgcBx.eEA7u9oWT/u2T6jzNM410EL1Uy5oPk9/

#禁用selinux与firewalld
firewall --disabled
selinux  --disabled

#安装完成后,重启系统
#--eject - 在重新启动前尝试弹出可引导介质(DVD、USB 或其他介质)
reboot --eject

%include /tmp/part-include

#禁用kdump
%addon com_redhat_kdump --disable --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


#------------------------------------------------------------------------------------------------------------------------------------------------------
%pre

###设置系统盘
#找到大于10G的盘
disk=$(while read line;do awk 'BEGIN{} {if ($3 >= "10485760" && $2 == "0") print $4} END{}';done < /proc/partitions|grep -Ew 'sda|vda|hda')
#disk=sda,vda,hda

cat > /tmp/part-include << EOF_PART
#ignoredisk --only-use=$disk
clearpart --drives=$disk --all --initlabel

#基于 UEFI 的 AMD64、Intel 64 和 64 位 ARM 需要 200 MiB EFI 系统分区。推荐的最小值是 200 MiB,默认大小为 600 MiB,最大为 600 MiB。BIOS 系统不需要 EFI 系统分区
part /boot/efi --fstype="efi" --ondisk=$disk --size=600 --fsoptions="umask=0077,shortname=winnt"
#将sda创建为ID:311的物理卷,最小10G,若磁盘大于10G,也全部做成物理卷
#--grow 自增长
part pv.311 --fstype="lvmpv" --ondisk=$disk --size=10240 --grow
#boot分区,建议大小1G
part /boot --fstype="xfs" --ondisk=$disk --size=1024
#将pv.311加入卷组,默认pe大小4M
volgroup santiagod --pesize=4096 pv.311
#逻辑卷-交换空间,视磁盘大小而定,为安装时的系统盘大小10%
logvol swap --fstype="swap" --recommended --name=swap --vgname=santiagod
#逻辑卷-根分区,虽然 5 GiB 根文件系统允许您最小安装,但建议至少分配 10 GiB,以便可以尽可能安装您想要的软件包组
logvol / --fstype="xfs" --size=10240 --grow --name=root --vgname=santiagod

EOF_PART
#-------------------------------------------------------------------------------------------------------------

%end
EOF_KS

注:anolis的ks文件

cat > /var/www/html/ks/anolis_ks.cfg <<EOF_KS 
#version=RHEL
# Use graphical/text install  #图形化/字符安装界面
#text
graphical

#使用系统上的第一个光驱执行安装
#cdrom
#装机使用的yum源
#repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-cdrom/AppStream

#要实际运行安装,必须指定 cdrom、harddrive、hmc、nfs、liveimg 或 url 之一
url --url=http://192.168.10.7/anolis

#最小化安装,及其他预装应用
%packages
@^minimal-environment
kexec-tools
bash-completion

%end

#使用美式键盘
keyboard --xlayouts='us'
#系统默认语言设置,即环境变量$LANG,--addsupport添加对附加语言的支持
lang en_US.UTF-8 --addsupport=zh_CN

#设置主机名
network  --hostname=santiagod.ks
#IP设置,需指明device,否则会取消后续所有network指令
#network --bootproto=static --ip=192.168.122.10 --netmask=255.255.255.0 --gateway=192.168.122.1 --nameserver=8.8.8.8,114.114.114.114 --device=ens192


#enable时,系统第一次引导时启动 Initial Setup,设置语言、鼠标、键盘、root 密码、安全级别、时区以及默认网络配置。默认为disable
firstboot --disable

#使用这个选项在没有用户互动的情况下接受最终用户许可证协议(End User License Agreement,EULA)。指定这个选项可防止 Initial Setup 在完成安装并第一次重启系统后提示您接受该许可证
eula --agreed

#系统时区上海,使用UTC时间,不开启时间同步
timezone Asia/Shanghai --isUtc --nontp

# Root password: Admin123!
rootpw --iscrypted $6$uMfDCfQnqrZgk/yL$F.DkU0TF2k14QNqLUv.cc8X16ZUXGe/8Q./rspkY1tKnmOywrgcBx.eEA7u9oWT/u2T6jzNM410EL1Uy5oPk9/

#禁用selinux与firewalld
firewall --disabled
selinux  --disabled

#安装完成后,重启系统
#--eject - 在重新启动前尝试弹出可引导介质(DVD、USB 或其他介质)
reboot --eject

%include /tmp/part-include

#禁用kdump
%addon com_redhat_kdump --disable --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


#------------------------------------------------------------------------------------------------------------------------------------------------------
%pre

###设置系统盘
#找到大于10G的盘
disk=$(while read line;do awk 'BEGIN{} {if ($3 >= "10485760" && $2 == "0") print $4} END{}';done < /proc/partitions|grep -Ew 'sda|vda|hda')
#disk=sda,vda,hda

cat > /tmp/part-include << EOF_PART
#ignoredisk --only-use=$disk
clearpart --drives=$disk --all --initlabel

#基于 UEFI 的 AMD64、Intel 64 和 64 位 ARM 需要 200 MiB EFI 系统分区。推荐的最小值是 200 MiB,默认大小为 600 MiB,最大为 600 MiB。BIOS 系统不需要 EFI 系统分区
part /boot/efi --fstype="efi" --ondisk=$disk --size=600 --fsoptions="umask=0077,shortname=winnt"
#将sda创建为ID:311的物理卷,最小10G,若磁盘大于10G,也全部做成物理卷
#--grow 自增长
part pv.311 --fstype="lvmpv" --ondisk=$disk --size=10240 --grow
#boot分区,建议大小1G
part /boot --fstype="xfs" --ondisk=$disk --size=1024
#将pv.311加入卷组,默认pe大小4M
volgroup santiagod --pesize=4096 pv.311
#逻辑卷-交换空间,视磁盘大小而定,为安装时的系统盘大小10%
logvol swap --fstype="swap" --recommended --name=swap --vgname=santiagod
#逻辑卷-根分区,虽然 5 GiB 根文件系统允许您最小安装,但建议至少分配 10 GiB,以便可以尽可能安装您想要的软件包组
logvol / --fstype="xfs" --size=10240 --grow --name=root --vgname=santiagod

EOF_PART
#-------------------------------------------------------------------------------------------------------------

%end



%post
#!/bin/bash

###内核调优
#kernel.sem 表示设置的信号量
#fs.aio-max-nr 表示系统范围异步 I/O 请求的最大并发数 
#fs.file-max 表示一个进程可以打开的文件句柄的最大数量
#net.ipv4.ip_local_port_range 表示专用服务器模式下与用户进程通信时分配给用户的端口区间
#kernel.pid_max 表示进程ID数量上限
#验证:sysctl 模块名,如【sysctl kernel.sem】
cat > /etc/sysctl.d/Santiagod-98-sysctl.conf <<-\EOF_SYSCTL
kernel.sem = 4010 641600 4010 1024 
fs.aio-max-nr = 1048576
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65501
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 1048576
net.core.wmem_max = 1048576
vm.swappiness = 0
vm.dirty_background_bytes=102400000
vm.dirty_bytes=409600000
vm.min_free_kbytes=512000
kernel.pid_max = 4194303
EOF_SYSCTL

#限制用户的最大线程数[nproc]和最大打开文件数[nofile],*代表所有用户,131072代表最大可接受的数
#有soft,hard和-,soft指的是当前系统生效的设置值,软限制也可以理解为警告值。hard表名系统中所能设定的最大值。
#soft的限制不能比hard限制高,用-表名同时设置了soft和hard的值。
#验证:ulimit -a
cat > /etc/security/limits.d/Santiagod-20-nofile.conf <<-\EOF_LIMITS
*       soft    nproc   131072
*       hard    nproc   131072
*       soft    nofile  131072
*       hard    nofile  131072
EOF_LIMITS
#----------------------------------------------------------------------------------------------------------
%end
EOF_KS

 

 

4. 配置tftp+pxe服务

mkdir -p /var/lib/tftpboot/pxe/pxelinux.cfg
cp /var/ftp/CentOS8/isolinux/splash.png /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/pxe 
cp /var/lib/tftpboot/pxelinux.0 /var/lib/tftpboot/pxe

cp /var/www/html/centos8/isolinux/ /var/lib/tftpboot/pxe/centos8
cp /var/www/html/centos7/isolinux/ /var/lib/tftpboot/pxe/centos7
cp /var/www/html/anolis/isolinux/ /var/lib/tftpboot/pxe/anolis

 

cat >/var/lib/tftpboot/pxe/pxelinux.cfg/default <<EOF_DEFAULT

default vesamenu.c32
timeout 60

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS Linux
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label Install anolis linux 8
  menu label ^Install anolis Linux 8
  kernel anolis/vmlinuz
  append initrd=anolis/initrd.img  inst.ks=http://192.168.10.7/ks/anolis_ks.cfg inst.stage2=http://192.168.10.7/anolis quit

label Install linux 8
  menu label ^Install centos Linux 8
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img  inst.ks=http://192.168.10.7/ks/c8_ks.cfg inst.stage2=http://192.168.10.7/centos8 quit

label Install linux 7
  menu label Install CentOS Linux 7
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img  inst.ks=http://192.168.10.7/ks/c7_ks.cfg quit

EOF_DEFAULT

5. 启服务

systemctl restart dhcpd tftp httpd 

 

常见问题:

注1:centos7可以不注明inst.stage2;但是从centos8开始,就必须注明inst.stage2,否则报错:failed to start switch root;哪怕侥幸这一步跳过了,后面也会报错curl失败,或者装系统时找不到yum源或安装包等。

注2:使用虚拟机测试时,需要保证测试网络没问题,且能够镜像pxe网络引导,最好是一块虚拟的vd;引导最小化centos7需要至少2G内存,而centos8需要调整到4G以上内存才能保证成功引导。

注3:连接tftp时,卡在boot界面提示vesamenu.c32文件有问题,从tftpboot目录直接提取本地vesamenu.c32文件替代从原iso中导出的文件。

注4:使用ftp测试时遇到登陆问题:ftp手动改配置后,登陆使用如下格式:ftp://ftpuser:[email protected]/

标签:www,kickstart,ks,tftpboot,html,var,服务器,pxe
From: https://www.cnblogs.com/santia-god/p/17003150.html

相关文章

  • Docker+Jenkins+Gitee+Node+Vue构建dist包并通过publish over ssh传输到服务器替换重
    场景docker-compose入门以及部署SpringBoot+Vue+Redis+Mysql(前后端分离项目)以若依前后端分离版为例:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/12837......
  • pxe+kickstart多系统引导
    1.装包yum-yinstalldhcp*tftp-servervsftpdsyslinux-nonlinux2.配置dhcpcat>/etc/dhcp/dhcpd.conf<<EOF_DHCP#DHCPServerConfigurationfile.#see......
  • Linux搭建minecraft paper服务器
    前置:我的世界java版需要提前搞好java环境,但是一般机器里边要么没有装java,要么装了个java8,在运行时会因为缺乏java环境报错,为了验证你的服务器是否有java环境,输入java-ver......
  • 使用 Spring 创建基于 SOAP 的 Web 服务服务器的过程
    本指南将引导您完成使用Spring创建基于SOAP的Web服务服务器的过程。您将构建什么您将构建一个服务器,该服务器使用基于WSDL的SOAPWeb服务公开来自不同欧洲国家的......
  • 利用集群技术实现Web服务器的负载均衡(转载)
    利用集群技术实现Web服务器的负载均衡集群和负载均衡的概念集群(Cluster)所谓集群是指一组独立的计算机系统构成的一个松耦合的多处理器系统,它们之间通过网络实现进程间......
  • 第二章 部署DNS服务器
    简介在Internet中使用IP地址来确定计算机的地址,这种以数字表示的IP地址不容易记忆.为了便于对网络地址的管理和分配,人们采用了域名系统,引入了域名的概念。通过为每台主机建......
  • Day11_03_Redis教程之Redis服务器客户端安装配置及配置文件详解
    Redis服务器客户端安装配置及配置文件详解一.Redis的安装在ubuntu18.04下,可以直接通过命令安装.1.更新系统环境$sudoapt-getupdate#更新软件列表$sudoapt-getupgra......
  • 高性能web服务器nginx和反向代理
    高性能web服务器——nginx一、 简介1. nginx是什么?l 是一个使用c语言开发的高性能的http服务器和反向代理服务器以及电子邮件(IMAP/POP3)代理服务器。l 是俄罗斯的程序设......
  • PHP添加$_SERVER服务器环境变量
    PHP添加$_SERVER服务器环境变量通过nginx的fastcgi_param来设置通过php主配置文件php-fpm.conf来设置通过Apache设置环境变量NGINX设置通过nginx的fastcgi_para......
  • Linux服务器安装python3.7环境
    安装python3.7依赖yum-yinstallzlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-develgdbm-develdb4-devellibpcap-develxz-......