Linux中的无人职守安装脚本kickstart

一、linux中的无人职守安装脚本kickstart

作用:自动化装系统。就是创建虚拟机,建立完成以后,不需要再进入配置root等,直接就可以自动安装,快速装机。

1.1 提前准备

  1. 准备一台红帽linux7系统

  2. linux7 下载图形化界面

    [root@localhost ~]# yum group install “Server with GUI” -y

    [root@localhost ~]# init 5

  3. linux7若是有图形化界面,但是关了

    [root@localhost ~]# init 5

  4. 在vmware在虚拟网络适配器中,把linux7的仅主机模式的dhcp功能关闭

  5. ssh连接开启图形化界面:ssh -XL root ip地址

查看linux7的按机设置
在这里插入图片描述

1.2 kickstart装机过程

安装kickstart

​ [root@localhost ~]# yum install system-config-kickstart

在图形化界面打开kickstart

​ [root@localhost ~]# system-config-kickstart

开启后相关配置如下

yum下载httpd

​ [root@localhost ~]# yum install httpd -y

​ [root@localhost ~]# systemctl enable --now httpd

​ [root@localhost ~]# ln -s /rhel7/ /var/www/html/

​ [root@localhost ~]# cd /var/www/html
​ [root@localhost html]# ls
​ rhel7

然后再配置该位置,要保证172.25.254.200/rhel7有资源,可以在浏览器里输入该网址试一下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

点击add
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

选择第三个,fill all…,如果选错,需要在/root/ks.cfg 文件中修改,修改完毕后,在/var/www/html/ks.cfg中一并修改,最后使用[root@localhost ~]# systemctl restart dhcpd重新加载http服务
在这里插入图片描述

点击add network device
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

安装之后,自动进行的任务。

file->save->
在这里插入图片描述

点击save

​ [root@localhost ~]# vim ks.cfg

# Disk partitioning information
part / --fstype="xfs" --grow --size=1
part swap --fstype="swap" --size=512
part /boot --fstype="xfs" --size=1024

%packages
@base
httpd
%end

要是找不到ks.cfg文件,寻找ks.cfg的命令

​ [root@localhost ~]# find / -name ks.cfg

编写ks.cfg后,可以检查一下语法是否有问题,用以下命令检测语法问题

​ [root@localhost ~]# ksvalidator ks.cfg

@^g(G)raphical-server-environment是图形化界面,暂时不用
在这里插入图片描述

共享出去,给别人使用

​ [root@localhost ~]# cp /root/ks.cfg /var/www/html

检查共享资源

​ 在linux7的浏览器中搜,172.25.254.200/ks.cfg

1.3 配置dhcp服务器

安装dhcp服务器为其他服务器提供分配ip的功能

​ [root@localhost ~]# yum install dhcp -y

查看主配置文件

[root@localhost ~]# rpm -qc dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#

复制

[root@localhost ~]# cp -f /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.con
	cp: overwrite ‘/etc/dhcp/dhcpd.con’? 

会报错,使用转义符/,从而正确使用cp命令

​ [root@localhost ~]# \cp -f /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

编辑配置文件

​ vim /etc/dhcp/dhcpd.conf

​ 注:原dhcp的配置文件中37行以后都不要,27,28行注释掉,第8行修改为114.114.114.114

​ 注:vim中命令行模式使用:set nu,方便查找,显示行数

​ 注:必须;号结尾

  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 "example.org";  #公司域名
    #对外分发的dns地址
  8 option domain-name-servers 114.114.114.114;
  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 #subnet 10.152.187.0 netmask 255.255.255.0 {
 28 #}
 29 
 30 # This is a very basic subnet declaration.
 31 #       网络位                子网掩码
 32 subnet 172.25.254.0 netmask 255.255.255.0 {
    #            地址池
 33   range 172.25.254.30 172.25.254.40;
    #                  网关
 34   option routers 172.25.254.2;
 35 }


启动dhcpd

[root@localhost ~]# systemctl enable --now dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.

查看dhcp的地址分配情况

​ [root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases

1.4 新建linux7虚拟机,用来检测kickstart的使用

  1. VMware新建虚拟机

  2. 选择稍后安装操作系统

  3. 默认

  4. 改名:ceshi-k

  5. 处理器数量:1,每个处理器的内核数量:2

  6. 内存:2048

  7. 选择NAT

  8. 默认

  9. 默认

  10. 默认

  11. 最大磁盘大小 100,多个文件

  12. 默认

  13. 默认

  14. 完成

  15. 编辑虚拟机设置,CD选择linux7.9光盘,显示器取消3D图形,选择拉伸模式,选择自由拉伸

  16. 确定

  17. 开启虚拟机

    前提:需要在配置好linux7的dhcp服务,配置步骤在1.3.

在这里插入图片描述

选择第一个,install red hat enterprise linux 7.9 按tab,然后输入ks=http://172.25.254.200/ks.cfg

注意:若是当前缺失dhcp服务,没有IP地址,无法上网访问172.25.254.100/ks.cfg地址,就会启动失败

二、快速部署多台服务器

需要重看这方面视频

Pxe:比如机房中有200台主机,一台P1有系统,有DHCP。其他机从网卡启动,从P1获取到ip地址,和文件地址。其他机根据文件地址,从P1处源源不断的下载安装,直到安装完成

​ pxelinux.0文件;指引下一步读取什么文件

注:nat模式的dhcp服务要取消

注:被测试的主机不可以配置CD镜像,最好是刚创建的新的虚拟机,进去后选否。然后配置如下图14步骤所示的选择。

思路:通过网络把这些文件共享出去
在这里插入图片描述

  1. [root@localhost www]# yum search pxelinux

    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
                  : manager
    
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    
    ============================== Matched: pxelinux ===============================
    # 复制这个文件名
    syslinux.x86_64 : Simple kernel loader which boots from a FAT filesystem
    
    syslinux-extlinux.x86_64 : The EXTLINUX bootloader, for booting the local
                             : system.
    syslinux-tftpboot.noarch : SYSLINUX modules in /var/lib/tftpboot, available for
                             : network booting
    
    
  2. [root@localhost www]# yum install syslinux.x86_64

  3. 这个信息文件相当于目录,指引主机根据目录读取文件

    1. 查看命令

    在这里插入图片描述

  4. 共享pxelinux.0数据文件的网络服务

    [root@localhost www]# yum search tftp

    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
                  : manager
    
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    
    ============================== N/S matched: tftp ===============================
    syslinux-tftpboot.noarch : SYSLINUX modules in /var/lib/tftpboot, available for
                             : network booting
    tftp.x86_64 : The client for the Trivial File Transfer Protocol (TFTP)
    
    #复制这个文件名
    tftp-server.x86_64 : The server for the Trivial File Transfer Protocol (TFTP)
    
      Name and summary matches only, use "search all" for everything.
    
    

    [root@localhost www]# yum install tftp-server.x86_64 -y

  5. 查看tftp启动文件

    [root@localhost www]# rpm -ql tftp-server

    /etc/xinetd.d/tftp
    
    #这个是启动文件
    /usr/lib/systemd/system/tftp.service
    
    /usr/lib/systemd/system/tftp.socket
    /usr/sbin/in.tftpd
    /usr/share/doc/tftp-server-5.2
    /usr/share/doc/tftp-server-5.2/CHANGES
    /usr/share/doc/tftp-server-5.2/README
    /usr/share/doc/tftp-server-5.2/README.security
    /usr/share/man/man8/in.tftpd.8.gz
    /usr/share/man/man8/tftpd.8.gz
    /var/lib/tftpboot
    
    

6 启动tftp

​ [root@localhost ~]# systemctl enable --now tftp

7 查询数据目录,东西都在最后一行。

[root@localhost ~]# rpm -ql tftp-server

/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot

8 复制,共享

[root@localhost ~]# cp /rhel7/isolinux/* /var/lib/tftpboot/

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

[root@localhost ~]# cd /var/lib/tftpboot/

9 创建数据目录

[root@localhost tftpboot]# mkdir pxelinux.cfg

10 创建数据文件,完成

[root@localhost tftpboot]# cp isolinux.cfg pxelinux.cfg/default

11 配置dhcp

[root@localhost tftpboot]# vim /etc/dhcp/dhcpd.conf

subnet 172.25.254.0 netmask 255.255.255.0 {
  range 172.25.254.30 172.25.254.40;
  option routers 172.25.254.2;
  next-server 172.25.254.200;   #本地ip地址
  filename "pxelinux.0";
}

filename这一行相当于找到下面这个文件
在这里插入图片描述

12

[root@localhost tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default

timeout 30


label linux
  menu label ^Install Red Hat Enterprise Linux 7.9
  menu default
  kernel vmlinuz
  # ip地址为开了http协议的主机的ip地址。
  append initrd=initrd.img repo=http://172.25.254.200/rhel7 ks=http://172.25.254.200/ks.cfg  quiet

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.9

  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rd.live.check quiet
  
  :wq!强制保存

写之前先在浏览器查询一下网址是否能看到

13 安装测试
在这里插入图片描述

使用左右方向键,选择boot,+:shift +。-:-改变顺序,顺序如图所示
在这里插入图片描述

进入这里,选择第一项,保存退出

在这里插入图片描述

14 安装完毕后,调整为硬盘启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值