欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > Linux中的无人职守安装脚本kickstart

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

2024/10/23 23:19:49 来源:https://blog.csdn.net/Dream_of_falling/article/details/140934250  浏览:    关键词: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.concp: 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.conf2 #3 # Sample configuration file for ISC dhcpd4 #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 local17 # network, the authoritative directive should be uncommented.18 #authoritative;19 20 # Use this to send dhcp log messages to a different log file (you also21 # 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-: managerThis 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 filesystemsyslinux-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-: managerThis 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 30label linuxmenu label ^Install Red Hat Enterprise Linux 7.9menu defaultkernel vmlinuz# ip地址为开了http协议的主机的ip地址。append initrd=initrd.img repo=http://172.25.254.200/rhel7 ks=http://172.25.254.200/ks.cfg  quietlabel checkmenu label Test this ^media & install Red Hat Enterprise Linux 7.9kernel vmlinuzappend initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rd.live.check quiet:wq!强制保存

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

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

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

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

在这里插入图片描述

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com