Linux ❀ PXE+Kickstart服务教研笔记

Posted 国家级干饭型选手°

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux ❀ PXE+Kickstart服务教研笔记相关的知识,希望对你有一定的参考价值。

Kickstart:是一种无人值守的安装方式,提前定义好Linux安装过程的配置文件,名为ks.cfg,这个文件预先定义了安装要求从而进行自动化安装;
PXE:预启动执行环境 是由Intel公司开发的最新技术,工作与C/S的网络模式,支持从远端下载镜像,并由此支持通过网络启动操作系统;

RHEL 8无此服务包,此实验在RHEL 7上完成!

1、安装服务


[root@localhost ~]# yum install -y dhcp xinetd tftp-server vsftpd syslinux system-config-kickstart
  • dhcp - 动态主机配置协议;
  • xinted - 可以监视一些网络请求的守护进程,其根据网络请求来调用相应的服务进程来处理连接请求;
  • tftp-server - 简单文件传输协议;
  • vsftpd - 为客户端提供系统安装时所需的文件;
  • syslinux - 产生pxelinux.0文件;
  • system-config-kickstart - 生成kickstart配置文件;

配置DHCP服务

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 
ddns-update-style none;
ignore client-updates;
filename "pxelinux.0";			/
next-server 192.168.18.131;		/
option routers 192.168.18.2;
subnet 192.168.18.0 netmask 255.255.255.0{
        range 192.168.18.20 192.168.18.30;
        default-lease-time 2000;
        max-lease-time 5000;
}
[root@localhost ~]# systemctl restart dhcpd

配置TFTP服务:

[root@localhost ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \\
#       protocol.  The tftp protocol is often used to boot diskless \\
#       workstations, download configuration files to network-aware printers, \\
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot		/指定目录,可自定义;
        disable                 = no					/开启服务开关;
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}			
[root@localhost ~]# systemctl restart tftp
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 .	
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cp /mnt/isolinux/isolinux.cfg pxelinux.cfg/default
[root@localhost tftpboot]# cp /mnt/images/pxeboot/vmlinuz .
[root@localhost tftpboot]# cp /mnt/images/pxeboot/initrd.img .
[root@localhost tftpboot]# ll
总用量 43860
-r--r--r--. 1 root root 39725808 12月 22 16:32 initrd.img
-rw-r--r--. 1 root root    26748 12月 22 16:28 pxelinux.0
drwxr-xr-x. 2 root root       20 12月 22 16:31 pxelinux.cfg
-r-xr-xr-x. 1 root root  5154912 12月 22 16:32 vmlinuz
[root@localhost tftpboot]# ll pxelinux.cfg/
总用量 4
-r--r--r--. 1 root root 3166 12月 22 16:31 default

重启FTP服务:

[root@localhost tftpboot]# systemctl restart vsftpd		

默认访问路径为:/var/ftp/

[root@localhost tftpboot]# mount /dev/sr0 /var/ftp/pub/
mount: /var/ftp/pub: WARNING: device write-protected, mounted read-only.
[root@localhost tftpboot]# ll /var/ftp/pub/
总用量 872
dr-xr-xr-x.  4 root root   2048 10月 30 2015 addons
dr-xr-xr-x.  3 root root   2048 10月 30 2015 EFI
-r--r--r--.  1 root root   8266 4月   4 2014 EULA
-r--r--r--.  1 root root  18092 3月   6 2012 GPL
dr-xr-xr-x.  3 root root   2048 10月 30 2015 images
dr-xr-xr-x.  2 root root   2048 10月 30 2015 isolinux
dr-xr-xr-x.  2 root root   2048 10月 30 2015 LiveOS
-r--r--r--.  1 root root    114 10月 30 2015 media.repo
dr-xr-xr-x.  2 root root 835584 10月 30 2015 Packages
dr-xr-xr-x. 24 root root   6144 10月 30 2015 release-notes
dr-xr-xr-x.  2 root root   4096 10月 30 2015 repodata
-r--r--r--.  1 root root   3375 10月 23 2015 RPM-GPG-KEY-redhat-beta
-r--r--r--.  1 root root   3211 10月 23 2015 RPM-GPG-KEY-redhat-release
-r--r--r--.  1 root root   1568 10月 30 2015 TRANS.TBL

查看配置文件

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

default vesamenu.c32		/
timeout 600				/等待超时时间600s

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.2	
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
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


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.2
  kernel vmlinuz
  append initrd=initrd.img ks=ftp://192.168.18.130/ks.cfg

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.2
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\\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.2 in ^basic graphics mode
  text help
        Try this option out if you're having trouble installing
        Red Hat Enterprise Linux 7.2.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\\x20Server.x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.2
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\\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.2 in ^basic graphics mode
  text help
        Try this option out if you're having trouble installing
        Red Hat Enterprise Linux 7.2.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\\x20Server.x86_64 xdriver=vesa nomodeset quiet

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.2\\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

[root@localhost tftpboot]# cp /mnt/isolinux/vesamenu.c32 .

2、图形化界面配置


[root@localhost 桌面]# system-config-kickstart

弹出kickstart的配置界面

选择【安装方法】-【安装方法-FTP】-配置FTP服务器地址与对应的文件路径;

配置分区信息,确认是否删除现存分区,设置新的分区;

设置网络配置,选择【添加网络设备】-【网络类型】,配置对应的IP地址,子网掩码,网关,DNS;

修改防火墙配置,默认防火墙禁用;

默认安装图形化界面,可以取消;

将yum源的[base]修改为[development],重新打开kickstart配置界面即可选择软件包;

[root@localhost tftpboot]# cat /etc/yum.repos.d/base.repo 
[development]
name=haha
baseurl=file:///mnt
gpgcheck=0
enable=1
[root@localhost 桌面]# system-config-kickstart

配置完成后,保存ks.cfg文件到对应的ftp路径;

文件保持路径为:/var/ftp,名称为ks.cfg;

保存完成后,查看

[root@localhost tftpboot]# ll /var/ftp
总用量 8
-rw-r--r--.  1 root root  756 12月 22 17:10 ks.cfg
dr-xr-xr-x. 10 root root 4096 10月 30 2015 pub

以上是关于Linux ❀ PXE+Kickstart服务教研笔记的主要内容,如果未能解决你的问题,请参考以下文章

linux之pxe远程安装服务的部署和kickstart无人值守安装

linux---PXE高效批量网络装机,kickstart无人值守技术

Linux PXE远程安装服务 并实现KIckstart无人值守安装

RedHat7搭建无人值守自动安装Linux操作系统(PXE+Kickstart)

linux部署pxe+kickstart批量安装linux操作系统实施方案

Centos 6.* 下搭建pxe+dhcp+nfs+kickstart