• 简单的网络引导安装CentOS7


      实验室有几台电脑,里边装有windows,因为实验需求要给其装入CentOS7。但是这几个电脑无法用U盘引导系统的安装,虽然带有光驱,但是又不想麻烦去买碟片,所以便想到用网络引导系统的安装。

    1. 软件需求

      dhcpd:   动态分配IP

      xinetd:   对服务访问进行控制,这里主要时控制tftp

      tftp:     从服务器端下载pxelinux.0、default文件

      syslinux:   用于网络引导

      httpd:     在网络上提供安装源,也就是镜像文件中的内容

    yum install dhcp xinetd syslinux tftp-server httpd

      

    2. 配置

      2.1 配置IP

        将服务器的IP配置为192.168.100.1,以便与DHCP能够正常启动,后边的TFTP,HTTP都是运行在这个IP上。

    [root@Amei tftpboot]# ip addr add 192.168.100.1/24 brd + dev p4p1
    [root@Amei tftpboot]# ip addr show dev p4p1

      

      2.2 配置DHCP

        如果要了解以下DHCP的工作原理以及简单的配置,可以参考前一篇随笔《CentOS7中DHCP配置》,这里在其基础之上增加了:

        next-server 192.168.100.1# tftp server的ip

        filename "pxelinux.0";

        dhcp的配置文件/etc/dhcp/dhcpd.conf的内容:

    #
    # DHCP Server Configuration file.
    #   see /usr/share/doc/dhcp*/dhcpd.conf.example
    #   see dhcpd.conf(5) man page
    #
    # 1. 整体的环境设定
    ddns-update-style none;
    ignore client-updates;
    default-lease-time 259200;
    max-lease-time 518400;
    option domain-name-servers 192.168.100.1;
    # 上面是 DNS 的 IP 设定,这个设定值会修改客户端的 /etc/resolv.conf
    # 2. 关于动态分配的 IP
    subnet 192.168.100.0 netmask 255.255.255.0 {
           range 192.168.100.101 192.168.100.200;
           option routers 192.168.100.1; 
           option subnet-mask 255.255.255.0;
           next-server 192.168.100.1;
           # the configuration  file for pxe boot
           filename "pxelinux.0";
    }

      启动dhcpd,查看是否有问题,如果没有成功启动需要仔细查看配置是否正确

    systemctl start dhcpd.service

      2.3 配置TFTP

        tftp是由xinetd管理的,所以在需要配置 /etc/xinetd.d/tftp文件,这个文件中只需要改一个参数即可

    service tftp
    {
        socket_type        = dgram
        protocol        = udp
        wait            = yes
        user            = root
        server            = /usr/sbin/in.tftpd
        server_args        = -s /var/lib/tftpboot
       #将此值改为no,表明开启此服务 disable
    = no per_source = 11 cps = 100 2 flags = IPv4 }

      开启xinetd和tftp服务:

      tftp的端口为69,同时xinetd接管了此端口

    [root@Amei tftpboot]# systemctl start xinetd
    [root@Amei tftpboot]# systemctl start tftp

      

      2.4 文件准备

         首先将已经下载好的CentOS的镜像文件挂载到一个目录中,然后复制可引导的、压缩的内核文件vmlinuz,以及包含一些模块和安装文件系统的initrd。因为安装过程中以http的方式提供镜像源,所以这里直接将镜像文件挂在到httpd访问目录中(/var/www/html)。

    [root@Amei ~]#mkdir  /var/www/html/centos7
    [root@Amei ~]# mount -o loop CentOS7.2.iso /var/www/html/centos7/

        复制vmlinuz,和 initrd.img 到TFTP访问目录的centos7子目录中,因为以后会引导其它的系统,所以这里通过子目录将不同的系统区分开。

    [root@Amei ~]# mkdir /var/lib/tftpboot/centos7
    [root@Amei ~]# cp /var/www/html/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/centos7/
    [root@Amei ~]# cp /var/www/html/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7/

      2.5 设置syslinux加载器

        vesamenu.c32和menu.c32是syslinux所拥有众多模块中的两个,它们的功能是制定启动器使用什么模式的背景。Vesamenu.c32图形模式,menu.c32文本模式。我选择的时menu.c32。

        同时还需要pxelinux.0文件,它对整个引导器的作用就如同内核对系统的作用一般,它可以解释default文件(配置引导菜单的文件)中的每个配置项,并根据配置项做出不同的反应。如等待的时间、启动器背景、启动菜单、内核引导等等。

        所以我们需要将这两个文件复制到tftp的访问目录中:

    cp  /usr/share/syslinux/menu.c32  /var/lib/tftpboot
    cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot

        接着就是pxelinux.cfg目录,pxelinux被执行后,它会扫描该目录下是否存在指定的配置文件,如果存在,则引用被制定的配置文件。
    default文件存放于pxelinux.cfg目录中,pxelinux程序最后扫描的配置文件名就是default。所以,我们经常把启动器配置项都写入该文件中。
        所以我们就要建立pxelinux.cfg,并在此目录下建立default文件,编辑引导菜单。

    [root@Amei ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
    [root@Amei ~]# emacs /var/lib/tftpboot/pxelinux.cfg/default

        default文件内容为:

    default menu.c32
    prompt 0
    timeout 300
    ONTIMEOUT local
     
    menu title ########## PXE Boot Menu ##########
     
    label 1
    menu label ^1) Install CentOS 7 x64 with HTTP
    kernel centos7/vmlinuz
    append initrd=centos7/initrd.img method=http://192.168.100.1/centos7 devfs=nomount

      2.5 检查文件以及服务

        此时/var/lib/tftp文件夹的结构应该是这样的:

      

      确保开启dhcpd,xinetd,tftp,http这些服务,在开启的时候没有发生错误,说明配置没问题。

    [root@Amei tftpboot]# systemctl start dhcpd.service 
    [root@Amei tftpboot]# systemctl start xinetd.service 
    [root@Amei tftpboot]# systemctl start tftp.service
    [root@Amei tftpboot]# systemctl start httpd.service

       验证httpd是否运行正常:

       

        同时为了防止意外的发生我们需要关闭防火墙和selinux。

    [root@Amei tftpboot]# systemctl stop firewalld.service 
    [root@Amei tftpboot]# setenforce 0

    3. 测试

      pxe服务器配置完成后,就可以在此子网中用网络引导安装了,此时和普通的安装系统差别不大,但是要选择从网络引导。

        

        default中定义的菜单

        

        熟悉的安装界面    

        

  • 相关阅读:
    POJ1006: 中国剩余定理的完美演绎(非原创)
    poj 1001 分析
    document.createElement()的用法
    js innertext
    转csdn-css4
    css中最基本几个选择器
    Django解决(1146, "Table 'd42.django_session' doesn't exist")方法
    django清理migration终极解决办法
    linux中的fork炸弹
    nginx转发php文件到php-fpm服务器提示502错误
  • 原文地址:https://www.cnblogs.com/linux-wangkun/p/5914103.html
Copyright © 2020-2023  润新知