亲妈式手把手教你如何PXE实现自动批量安装部署操作系统

PXE简介

PXE 让计算机通过网络从服务器获取启动文件来安装系统。先搭建含安装镜像等的 PXE 服务器,客户端设网络启动优先。开机后向服务器请求,下载引导文件启动安装,按预配置参数自动完成。如企业为新员工、学校实验室部署系统,能提效。但要注意网络稳定、配置准确及服务器性能规划。

1. 实验环境配置

实验环境准备:

1.红帽7主机

2.要全图形安装

3.配置网络为手动,配置网络可用

4.关闭vmware DHCP功能

注:4.关闭vmware DHCP功能如下图

2.配置仓库

root@node2 ~]# mkdir -p /rhel7
[root@node2 ~]# echo mount /dev/cdrom  /rhel7  >> /etc/rc.d/rc.local
[root@node2 ~]# chmod +x /etc/rc.d/rc.local
[root@node2 ~]# mount /dev/cdrom /rhel7
mount: /dev/sr0 is write-protected, mounting read-only
[root@node2 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               894M     0  894M   0% /dev
tmpfs                  910M     0  910M   0% /dev/shm
tmpfs                  910M   11M  900M   2% /run
tmpfs                  910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   15G  4.1G   11G  28% /
/dev/sda1             1014M  183M  832M  19% /boot
tmpfs                  182M   28K  182M   1% /run/user/1000
/dev/sr0               4.3G  4.3G     0 100% /rhel7   #rhel7已经挂载上来
tmpfs                  182M     0  182M   0% /run/user/0

[root@node2 ~]# cat  /etc/yum.repos.d/rpm.repo  
[repo]
name=repo
baseurl=file:///rhel7
gpgcheck=0

[root@node2 ~]# ln -s /rhel7/   /var/www/html/  
//ln -s /rhel7/ /var/www/html/ 这条命令的作用是创建一个从 /rhel7/ 到 /var/www/html/ 的符号链
//接(symbolic link)。
//这意味着当访问 /var/www/html/ 时,实际上会指向 /rhel7/ 的内容。

3.kickstart自动安装脚本制作

Kickstart 是一种用于自动化操作系统安装的工具。

它通过一个配置文件(即 Kickstart 脚本),让用户能够预先指定安装过程中的各种详细参数和选项。例如,用户可以在脚本中指定磁盘分区的方式、要安装的软件包、系统的语言和时区设置、网络配置信息,甚至可以设置 root 用户的密码等。在企业级环境中,如果需要大量部署相同配置的服务器或计算机,Kickstart 可以显著提高安装效率,减少人工干预和出错的可能性。比如一家公司新采购了一批服务器,使用 Kickstart 就能够快速、统一地完成操作系统的安装和基本配置。

下载kickstart

[root@node2 ~]# yum install system-config-kickstart -y

启动图形界面

[root@node2 ~]# system-config-kickstart

照着提示图修改配置文件

 

 

mkdir -p   /rhel7
echo mount /dev/cdrom  /rhel7  >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local



cat  > /etc/yum.repos.d/rhel7.repo  <<EOF
[rhel7]
name=rhel7
baseurl=file:///rhel7
gpgcheck=0
EOF

yum install gcc -y

编辑一下文件vim ks.cfg

:wq 保存退出

检查一下文件是否有语法错误

[root@node2 ~]# ksvalidator ks.cfg  #检查是否有语法错误
[root@node2 ~]# 

通过浏览器查看一下rhel7是否有文件

[root@node2 ~]# systemctl start httpd
[root@node2 ~]# systemctl stop firewalld
[root@node2 ~]# setenforce 0

出现上面即可

将ks.cfg共享出去

[root@node2 ~]# mv ks.cfg /var/www/html

查看是否共享成功

4.配置和安装dhcp服务

[root@node2 ~]# yum install dhcpd -y
[root@node2 ~]# vim /etc/dhcp/dhcpd.conf

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

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

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 172.25.250.0 netmask 255.255.255.0 {
  range 172.25.250.30 172.25.250.40;
  option routers 172.25.250.2;
  next-server 172.25.250.200;
   filename "pxelinux.0";
}

 详细配置过程如下

systemctl restart dhcpd

5.搭建PXE网络安装环境实现服务器自动部署

[root@node2 ~]# yum install syslinux.x86
[root@node2 ~]#  yum install tftp-server.x86_64 -y
[root@node2 ~]# systemctl enable --now tftp 
[root@node2 ~]# cp -p /rhel7/isolinux/* /var/lib/tftpboot/  
[root@node2 ~]# cp -p /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ 
[root@node2 ~]# cd /var/lib/tftpboot/
[root@node2 tftpboot]# mkdir pxelinux.cfg
[root@node2 tftpboot]# cp isolinux.cfg pxelinux.cfg/default
[root@node2 tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default



default vesamenu.c32
timeout 600

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 Red Hat Enterprise Linux 7.9
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 ti

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

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

label linux
  menu label ^Install Red Hat Enterprise Linux 7.9
  kernel vmlinuz
  append initrd=initrd.img repo=http://172.25.250.200/rhel7 ks=http://172.25.250.200/ks.cfg q

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.9
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install Red Hat Enterprise Linux 7.9 in ^basic graphics mode
  text help
        Try this option out if you're having trouble installing
        Red Hat Enterprise Linux 7.9.
  endtext
label rescue
  menu indent count 5
  menu label ^Rescue a Red Hat Enterprise Linux system
  text help
        If the system will not boot, this lets you access files
        and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rescue quiet

label memtest
  menu label Run a ^memory test
  text help
        If your system is having issues, a problem with your
        system's memory may be the cause. Use this utility to
        see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

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

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

label returntomain
  menu label Return to ^main menu
  menu exit

menu end

 :wq! 退出


新建虚拟机安装之后

进入电源固件

使用shift+上移动

enter

到了上图要耐心等待,起码要等待1分钟

再次打开电源固件,将启动方式更改成默认的方式:Hard Drive 即硬盘启动方式。不然会进入无限安装

最后,开启虚拟机

完结撒花

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值