<XII>无人值守安装脚本

**


一、kickstart 自动安装脚本

共享资源的意义:在安装操作系统时,每个被安装的操作系统都要有安装资源,如果使用镜像安装,每个安装的系统都需要加载一个镜像,这样会浪费存储,通过网络来共享镜像中的资源,让安装系统的主机能通过网络访问被共享的资源这样就可以解决多台主机需要多个镜像安装的问题。

需要真机和两个快照node1,node2
在真机里:
[root@localhost yum.repos.d]# mount /isos/rhel-8.2-x86_64-dvd.iso /var/www/html/westos/  #挂载共享镜像
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/westos.repo   #软件仓库指向文件
%操作node2中作
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/westos.repo   #使用真机的共享镜像,软件仓库指向文件
[root@localhost yum.repos.d]# dnf search kickstart
[root@localhost yum.repos.d]# dnf install python3-kickstart.noarch -y
[root@localhost yum.repos.d]# systemctl restart httpd
[root@localhost yum.repos.d]# cd /var/www/html
[root@localhost html]# ls
[root@localhost html]# cp /root/anaconda-ks.cfg westos.cfg
[root@localhost html]# ls
westos.cfg
[root@localhost html]# vim westos.cfg
编辑内容
#version=RHEL8
#ignoredisk --only-use=vda
# Partition clearing information
clearpart --all --initlabel
# Use graphical install
#graphical
text    #无图形
# Use CDROM installation media
#cdrom
url --url=http://172.25.254.250/rhel8.2  #真机内共享的镜像源位置。自己电脑:http://10.4.17.141/westos/
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8 --addsupport=zh_CN.UTF-8

# Network information
network  --bootproto=dhcp --device=enp1s0 --onboot=on
#network  --hostname=localhost.localdomain
repo --name="AppStream" --baseurl=http://172.25.254.250/rhel8.2/AppStream  #真机内共享的镜像源位置。自己电脑:http://10.4.17.141/westos/AppStream

# Root password   #用 openssl passwd -6 查找加密密码
rootpw --iscrypted $6$j/wAunuZd0masdzO$OhrnyMr8Va4URBOS7Sxpj5N4SowqNxoXJjpIICuoJ8zx6TLmVEqe6yXnbpw6V0ne6D0zmdM7KHzCuZ4FDOUMl1
# X Window System configuration information   
#xconfig  --startxonboot
# Run the Setup Agent on first boot
firstboot --disable
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Makassar --isUtc --nontp
user --name=westos --
# Disk partitioning information
part swap --fstype="swap"  --size=500
part /boot --fstype="xfs"  --size=500
part / --fstype="xfs" --grow --size=1  #剩下的填满

reboot
%packages
#@^graphical-server-environment
@base  #核心组件
lftp
%end
#%post
#touch /mnt/westosfile{1..3}
#%end
编辑晚餐

[root@localhost html]# vim westos.cfg
[root@localhost html]# ksvalidator westos.cfg  #检测语法错误
[root@localhost html]# systemctl restart httpd 
[root@localhost html]# systemctl enable --now httpd 
[root@localhost html]# systemctl disable --now firewalld
[root@localhost html]# ll
[root@localhost html]# chmod 644 westos.cfg 

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

%测试创建有两种
1,网络安装virt-manager 小太阳创建新的
选Networt Install(HTTP,HTTPS,or FIP)
http://172.25.254.250/rhel8.2/ #安装源:真机内共享的镜像源位置。自己电脑:http://10.4.17.141/westos/
ks=http://172.25.254.103 #设置好自动安装脚本westos.cfg的虚拟机node2的ip
之后设置,2048,1,10G,test
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

2,光盘安装 node2关掉运行
新建光驱,设置使用光驱运行,选第一个,tab建,编写ks=http://172.25.254.103/westos.cfg
在系统安装基面选择
Install Red Hat Enterprise Linux 8.0.0
ks=http://172.25.254.20/westos.cfg
在这里插入图片描述

3,注意问题:
%zerombr自己双系统笔记本打开
%[root@localhost ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
然后[root@localhost ~]# reboot
%westos.cfg编写正确;httpd服务start、enable;火墙关
%自己电脑可以用http://172.25.254.27/westos/ #真机所挂载的镜像
%用网页看http://172.25.254.103/westos.cfg#含有westos.cfg的虚拟机ip,是否能打开
在这里插入图片描述
在这里插入图片描述

二、怎样配置pxelinux文件

安装
dnf seacher tftp
dnf install tftp
rpm -ql tftp-server #看安装包的文件目录
查找文件再那个安装包里,dnf whatprovides */pxelinux.0 #pxelinux.0文件的作用是读取default,default的左右是
去光盘镜像里找,
设置文件
去设置dhcp的

PXE网络安装Linux操作系统原理与详细过程
1,真机里挂镜像,拷贝所需文件
[root@westos_student3 ~]# mount /isos/rhel-8.2-x86_64-dvd.iso /westos/
mount: /westos: WARNING: device write-protected, mounted read-only.
[root@westos_student3 ~]# cd /westos
[root@westos_student3 westos]# ls
[root@westos_student3 westos]# scp isolinux/* [email protected]://var/lib/tftpboot

[root@westos_student3 ~]# cd /usr/share/syslinux
[root@westos_student3 syslinux]# ls
[root@westos_student3 syslinux]# scp pxelinux.0 [email protected]://var/lib/tftpboot

2,虚拟机node2操作
[root@localhost ~]# dnf search tftp
[root@localhost ~]# dnf install tftp-server.x86_64 httpd -y
[root@localhost ~]# systemctl enable --now tftp httpd

3,虚拟机node2操作dhcp
[root@localhost ~]# mkdir pxelinux.cfg
[root@localhost ~]# cd pxelinux.cfg/
[root@localhost ~]# ls
[root@localhost ~]# cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/default

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
编辑内容
1 # dhcpd.conf
  2 #
  3 # Sample configuration file for ISC dhcpd
  4 #
  5 
  6 # option definitions common to all supported networks...
  7 option domain-name "westos.org";    #--1
  8 option domain-name-servers 114.114.114.114;     #---2
  9 
 10 default-lease-time 600;
 11 max-lease-time 7200;
 12 
 13 # Use this to enble / disable dynamic dns updates globally.
 14 #ddns-update-style none;
 15 
 16 # If this DHCP server is the official DHCP server for the local
 17 # network, the authoritative directive should be uncommented.
 18 #authoritative;
 19 
 20 # Use this to send dhcp log messages to a different log file (you also
 21 # have to hack syslog.conf to complete the redirection).
 22 log-facility local7;
23 
 24 # No service will be given on this subnet, but declaring it helps the 
 25 # DHCP server to understand the network topology.
 26 
 27 
 28 # This is a very basic subnet declaration.
 29 
 30 subnet 172.25.254.0 netmask 255.255.254.0 {      #--3
 31   range 172.25.254.70 172.25.254.90;
 32   option routers 172.25.254.103;
 33   filename "pxelinux.0";
 34   next-server 172.25.254.103;
      }
编辑晚餐
注: vim /var/lib/tftpboot/default  #加了ks就会新建(重庄系统(node1))
%测试是在另外的node1里面,小灯泡,使用光盘启动。正常启动为完成。

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

猜你喜欢

转载自blog.csdn.net/qiao_qing/article/details/109608034