PXE无人值守安装

关闭vmware自带的dhcp服务

在这里插入图片描述

安装所需服务

[root@pxe ~]# yum install dhcp tftp-server vsftpd syslinux xinetd vim -y

配置服务

DHCP

[root@pxe /]# vim /etc/dhcp/dhcpd.conf 
allow booting;
allow bootp;
ddns-update-style interim;
ignore client-updates;
subnet 172.16.9.0 netmask 255.255.255.0 {
        option subnet-mask      255.255.255.0;
        option domain-name-servers      172.16.9.25;
        range dynamic-bootp 172.16.9.50 172.16.9.55;
        default-lease-time      21600;
        max-lease-time          43200;
        next-server             172.16.9.25;
        filename                "pxelinux.0";
[root@pxe /]# systemctl restart dhcpd
[root@pxe /]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.

TFTP

在这里插入图片描述

进入配置文件把yes改为no,TFTP的运行和关闭是通过xinetd网络守护进程服务来管理的,xinetd会同时监听系统的多个端口,根据用户请求的端口挑取相应的服务程序来响应用户的请求。

[root@pxe /]# 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@pxe /]# systemctl restart xinetd
[root@pxe /]# systemctl enable xinetd

让TFTP端口号通过防火墙

TFTP默认使用UDP协议,占用的端口号为69,写入防火墙永久生效。

[root@pxe /]# firewall-cmd --permanent --add-port=69/udp
success
[root@pxe /]# firewall-cmd --reload
success

配置SYSLinux服务程序

SYSLinux是一个用于提供引导记载的服务程序,安装好SYSLinux服务程序软件包后,/usr.share/syslinux/中会出现很多引导文件。
首先要把SYSLinux提供的引导文件复制到TFTP服务程序的默认目录中,也就是前面的pxelinux.0,这样客户端就可以顺利读取到引导文件,确认光盘被挂载以后把光盘自带的一些引导文件也复制到TFTP服务程序的默认目录中。

我这里光盘镜像挂载的目录是/opt/

[root@pxe /]# cd /var/lib/tftpboot/
[root@pxe tftpboot]# ll
总用量 0
[root@pxe tftpboot]# cp /usr/share/syslinux/pxe
pxechain.com  pxelinux.0    
[root@pxe tftpboot]# cp /usr/share/syslinux/pxelinux.0  .
[root@pxe tftpboot]# cp /opt/centos/images/pxeboot/
initrd.img  TRANS.TBL   vmlinuz     
[root@pxe tftpboot]# cp /opt/centos/images/pxeboot/{initrd.img,vmlinuz}   .
[root@pxe tftpboot]# cp /opt/centos/isolinux/
boot.cat      grub.conf     isolinux.bin  memtest       TRANS.TBL     vmlinuz       
boot.msg      initrd.img    isolinux.cfg  splash.png    vesamenu.c32  
[root@pxe tftpboot]# cp /opt/centos/isolinux/{vesamenu.c32,boot.msg}    .
[root@pxe tftpboot]# ll
总用量 57920
-rw-r--r--. 1 root root       84 1027 00:41 boot.msg
-rw-r--r--. 1 root root 52893200 1027 00:40 initrd.img
-rw-r--r--. 1 root root    26764 1027 00:39 pxelinux.0
-rw-r--r--. 1 root root   152976 1027 00:41 vesamenu.c32
-rwxr-xr-x. 1 root root  6224704 1027 00:40 vmlinuz

然后再TFTP的目录中新建pxelinux.cfg目录,将系统光盘中的开机选项菜单复制到该目录中,并命名为default,这个default就是开机时的选项菜单

这里是引用

[root@pxe tftpboot]# mkdir pxelinux.cfg
[root@pxe tftpboot]# cp /opt/centos/isolinux/isolinux.cfg  pxelinux.cfg/default

默认的开机菜单中有两个选项,一个是安装系统,一个是对安装介质进行检验

我们采用的是无人值守安装系统,如果这样停留的话就不是无人了,所以需要编辑一下default文件,把第一行的default参数修改为liunx,这样系统开机时就会默认执行名称为linux的选项了,对应的linux选项大概在64行

我们将默认的光盘镜像安装方式修改为ftp文件传输方式,并指定好光盘镜像获取地址以及Kickstart应答文件的获取路径

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

[root@pxe tftpboot]# cat -n pxelinux.cfg/default
     1  default linux        #  第一处修改
     2  timeout 600
     3
     4  display boot.msg
     5
     6  # Clear the screen when exiting the menu, instead of leaving the menu displayed.
     7  # For vesamenu, this means the graphical background is still displayed without
     8  # the menu itself for as long as the screen remains in graphics mode.
     9  menu clear
    10  menu background splash.png
    11  menu title CentOS 7
    12  menu vshift 8
    13  menu rows 18
    14  menu margin 8
    15  #menu hidden
    16  menu helpmsgrow 15
    17  menu tabmsgrow 13
    18
    19  # Border Area
    20  menu color border * #00000000 #00000000 none
    21
    22  # Selected item
    23  menu color sel 0 #ffffffff #00000000 none
    24
    25  # Title bar
    26  menu color title 0 #ff7ba3d0 #00000000 none
    27
    28  # Press [Tab] message
    29  menu color tabmsg 0 #ff3a6496 #00000000 none
    30
    31  # Unselected menu item
    32  menu color unsel 0 #84b8ffff #00000000 none
    33
    34  # Selected hotkey
    35  menu color hotsel 0 #84b8ffff #00000000 none
    36
    37  # Unselected hotkey
    38  menu color hotkey 0 #ffffffff #00000000 none
    39
    40  # Help text
    41  menu color help 0 #ffffffff #00000000 none
    42
    43  # A scrollbar of some type? Not sure.
    44  menu color scrollbar 0 #ffffffff #ff355594 none
    45
    46  # Timeout msg
    47  menu color timeout 0 #ffffffff #00000000 none
    48  menu color timeout_msg 0 #ffffffff #00000000 none
    49
    50  # Command prompt text
    51  menu color cmdmark 0 #84b8ffff #00000000 none
    52  menu color cmdline 0 #ffffffff #00000000 none
    53
    54  # Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
    55
    56  menu tabmsg Press Tab for full configuration options on menu items.
    57
    58  menu separator # insert an empty line
    59  menu separator # insert an empty line
    60
    61  label linux
    62    menu label ^Install CentOS 7
    63    kernel vmlinuz
    #  第二处修改
    64    append initrd=initrd.img inst.stage2=ftp://172.16.9.25 ks=ftp://172.16.9.25/pub/ks.cfg quiet  

    65
    66  label check
    67    menu label Test this ^media & install CentOS 7
    68    menu default
    69    kernel vmlinuz
    70    append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
    71
    72  menu separator # insert an empty line
    73
    74  # utilities submenu
    75  menu begin ^Troubleshooting
    76    menu title Troubleshooting
    77
    78  label vesa
    79    menu indent count 5
    80    menu label Install CentOS 7 in ^basic graphics mode
    81    text help
    82          Try this option out if you're having trouble installing
    83          CentOS 7.
    84    endtext
    85    kernel vmlinuz
    86    append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
    87
    88  label rescue
    89    menu indent count 5
    90    menu label ^Rescue a CentOS system
    91    text help
    92          If the system will not boot, this lets you access files
    93          and edit config files to try to get it booting again.
    94    endtext
    95    kernel vmlinuz
    96    append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
    97
    98  label memtest
    99    menu label Run a ^memory test
   100    text help
   101          If your system is having issues, a problem with your
   102          system's memory may be the cause. Use this utility to
   103          see if the memory is working correctly.
   104    endtext
   105    kernel memtest
   106
   107  menu separator # insert an empty line
   108
   109  label local
   110    menu label Boot from ^local drive
   111    localboot 0xffff
   112
   113  menu separator # insert an empty line
   114  menu separator # insert an empty line
   115
   116  label returntomain
   117    menu label Return to ^main menu
   118    menu exit
   119
   120  menu end

vsftpd

光盘镜像是通过FTP协议传输的,因此要用到vsftpd服务,当然也可以用httpd服务,只要能保证光盘镜像可以顺利传输给客户端主机即可,如果打算使用web网站来提供镜像,一定要修改获取网址和Kickstart应答文件获取网址

[root@pxe tftpboot]# systemctl restart vsftpd 
[root@pxe tftpboot]# systemctl enable vsftpd 
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

再确认镜像正常挂载到目录后,吧目录中所有光盘镜像文件全部复制到vsftpd默认的工作目录中

[root@pxe tftpboot]# cp -r /opt/centos/* /var/ftp/

这个不会立马结束,可以趁这段时间克隆一个窗口来写策略
在firewalld防火墙管理工具中写入使FTP 协议永久生生效的允许策略,然后再SElinux中放行FTP传输。

[root@pxe tftpboot]# firewall-cmd --permanent --add-service=ftp
success
[root@pxe tftpboot]# firewall-cmd --reload
success
[root@pxe tftpboot]# setsebool -P ftpd_connect_all_unreserved=on

创建Kickstart应答文件

Kick应答文件包括了系统安装过程需需要使用的选项和参数信息,系统可以自动调取应答文件的内容,在root管理员的家目录下有个anaconda-ks.cfg文件就是应答文件
把这个文件复制到vsftpd目录下(在开机选项菜单的配置文件中已经定义了改文件的获取路径,也就是在vsftpd服务程序的数据目录的pub子目录中)
用chmod命令设置该文件的权限,确保所有人可读,保证客户端可以顺利读取应答文件

[root@pxe ~]# cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg
[root@pxe ~]# chmod +r /var/ftp/pub/ks.cfg

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

[root@pxe ~]# cat  -n /var/ftp/pub/ks.cfg
     1  #version=DEVEL
     2  # System authorization information
     3  auth --enableshadow --passalgo=sha512
     4  # Use CDROM installation media
     5  url --url=ftp://172.16.9.25
     6  # Use graphical install
     7  graphical
     8  # Run the Setup Agent on first boot
     9  firstboot --enable
    10  ignoredisk --only-use=sda
    11  # Keyboard layouts
    12  keyboard --vckeymap=cn --xlayouts='cn'
    13  # System language
    14  lang zh_CN.UTF-8
    15
    16  # Network information
    17  network  --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
    18  network  --hostname=localhost.localdomain
    19
    20  # Root password
    21  rootpw --iscrypted $6$09vgxbtr5squ2ubP$mi8kHC3OHvuqEZJ5Aa29biah4rY/45X0W8N2zvT9VL6N7fp/hrygWrhHQIXap9X89/DomiJgEp4BE93LWlF4Q0
    22  # System services
    23  services --enabled="chronyd"
    24  # System timezone
    25  timezone Asia/Shanghai --isUtc
    26  # System bootloader configuration
    27  bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
    28  autopart --type=lvm
    29  # Partition clearing information
    30  clearpart --all --initlabel
    31
    32  %packages
    33  @^minimal
    34  @core
    35  chrony
    36  kexec-tools
    37
    38  %end
    39
    40  %addon com_redhat_kdump --enable --reserve-mb='auto'
    41
    42  %end
    43
    44  %anaconda
    45  pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    46  pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    47  pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    48  %end

PXE无人值守部署完成,部署客户端

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值