• Centos7 pxe


    yum install dnsmasq
    mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
    # vim /etc/dnsmasq.conf
        interface=eth0,lo
        #bind-interfaces
        domain=centos7.lan
        # DHCP range-leases
        dhcp-range= eth0,10.10.0.20,10.10.0.30,255.255.255.0,1h
        # PXE
        dhcp-boot=pxelinux.0,pxeserver,192.168.1.20
        # Gateway
        dhcp-option=3,10.10.0.240
        # DNS
        dhcp-option=6,10.10.0.240,114.114.114.114
        server=114.114.114.114
        # Broadcast Address
        dhcp-option=28,10.0.0.255
        # NTP Server
        dhcp-option=42,0.0.0.0
         
        pxe-prompt="Press F8 for menu.",60
        pxe-service=x86PC,"Install CentOS 7 from network server 10.10.0.240", pxelinux
        enable-tftp
        tftp-root=/var/lib/tftpboot
            interface – 服务器需要监听并提供服务的网络接口。
            bind-interfaces – 取消注释来绑定到该网络接口
            domain – 替换为你的域名。
            dhcp-range – 替换为你的网络掩码定义的网段。
            dhcp-boot – 替换该IP地址为你的网络接口IP地址。
            dhcp-option=3,192.168.1.1 – 替换该IP地址为你的网段的网关。
            dhcp-option=6,92.168.1.1 – 替换该IP地址为你的DNS服务器IP——可以定义多个IP地址。h
            server=8.8.4.4 – 这里放置DNS转发服务器IP地址。
            dhcp-option=28,10.0.0.255 – 替换该IP地址为网络广播地址——可选项。
            dhcp-option=42,0.0.0.0 – 这里放置网络时钟服务器——可选项(0.0.0.0地址表示参考自身)。
            pxe-prompt – 保持默认——按F8进入菜单,60秒等待时间。
            pxe=service – 使用x86PC作为32为/64位架构,并在字符串引述中输入菜单描述提示。其它类型值可以是:PC98,IAEFI,Alpha,Arcx86,IntelLeanClient,IA32EFI,BCEFI,XscaleEFI和X86-64EFI。
            enable-tftp – 启用内建TFTP服务器。
            tftp-root – 使用/var/lib/tftpboot——所有网络启动文件所在位置。
            
    yum install syslinux
    yum install tftp-server
    cp -r /usr/share/syslinux/* /var/lib/tftpboot
    mkdir /var/lib/tftpboot/pxelinux.cfg
    touch /var/lib/tftpboot/pxelinux.cfg/default
    Vim /var/lib/tftpboot/pxelinux.cfg/default
        default menu.c32
        prompt 0
        timeout 300
        ONTIMEOUT local
        
        menu title ########## PXE Boot Menu ##########
        
        label 1
        menu label ^1)InstallCentOS7 x64 withLocalRepo
        kernel centos7/vmlinuz
        append initrd=centos7/initrd.img method=ftp://10.10.0.240/pub devfs=nomount
        
        label 2
        menu label ^2)InstallCentOS7 x64 with http://mirror.centos.org Repo
        kernel centos7/vmlinuz
        append initrd=centos7/initrd.img method=http://mirror.centos.org/centos/7/os/x86_64/ devfs=nomount ip=dhcp
        
        label 3
        menu label ^3)InstallCentOS7 x64 withLocalRepousing VNC
        kernel centos7/vmlinuz
        append initrd=centos7/initrd.img method=ftp://10.10.0.240/pub devfs=nomount inst.vnc inst.vncpassword=password
        
        label 4
        menu label ^4)Bootfromlocal drive
        
    mount  /dev/sr0 /mnt
    # ls /mnt/
    mkdir /var/lib/tftpboot/centos7
    cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7
    cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/centos7
     yum install vsftpd
    cp -r /mnt/* /var/ftp/pub/
    chmod -R 755 /var/ftp/pub
    systemctl start dnsmasq
    systemctl status dnsmasq
    systemctl start vsftpd
    systemctl status vsftpd
    systemctl enable dnsmasq
    systemctl enable vsftpd
    # netstat -tulpn
    # firewall-cmd --add-service=ftp --permanent ## Port 21
    # firewall-cmd --add-service=dns --permanent ## Port 53
    # firewall-cmd --add-service=dhcp --permanent ## Port 67
    # firewall-cmd --add-port=69/udp --permanent ## Port for TFTP
    # firewall-cmd --add-port=4011/udp --permanent ## Port for ProxyDHCP
    # firewall-cmd --reload ## Apply rules
    
    
    tailf /var/log/messages
    # umount /dev/sr0 
    # PXE安装脚本
    # 安装前配置好centos和epel yum源
    # 网卡ip和localip一致
    localip="10.10.0.240"
    eth_name='eth0'
    
    dnsmasq_install() {
      yum -y install dnsmasq
      mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
      dnsmasq_conf='interface='$eth_name'
    #bind-interfaces
    domain=centos7.lan
    # DHCP range-leases
    dhcp-range= '$eth_name',10.10.0.100,10.10.0.110,255.255.255.0,1h
    # PXE
    dhcp-boot=pxelinux.0,pxeserver,'$localip'
    # Gateway
    dhcp-option=3,'$localip'
    # DNS
    dhcp-option=6,'$localip',114.114.114.114
    server=114.114.114.114
    # Broadcast Address
    dhcp-option=28,10.10.0.255
    # NTP Server
    dhcp-option=42,0.0.0.0
    
    pxe-prompt="Press F8 for menu.",60
    pxe-service=x86PC,"Install CentOS 7 from network server '$localip'", pxelinux
    enable-tftp
    tftp-root=/var/lib/tftpboot'
      echo "$dnsmasq_conf" > /etc/dnsmasq.conf
    }
    tftp_pxe_install() {
      yum -y install syslinux
      yum -y install tftp-server
      cp -r /usr/share/syslinux/* /var/lib/tftpboot/
      if [[ ! -d /var/lib/tftpboot/pxelinux.cfg ]]
      then
        mkdir /var/lib/tftpboot/pxelinux.cfg
        touch /var/lib/tftpboot/pxelinux.cfg/default
        default_conf='default menu.c32
    prompt 0
    timeout 300
    ONTIMEOUT local
            
    menu title ########## PXE Boot Menu ##########
            
    label 1 
    menu label ^1)InstallCentOS7 x64 withLocalRepo
    kernel centos7/vmlinuz
    append initrd=centos7/initrd.img method=ftp://'$localip'/pub devfs=nomount
            
    label 2 
    menu label ^2)InstallCentOS7 x64 with http://mirror.centos.org Repo
    kernel centos7/vmlinuz
    append initrd=centos7/initrd.img method=http://mirror.centos.org/centos/7/os/x86_64/ devfs=nomount ip=dhcp 
            
    label 3 
    menu label ^3)InstallCentOS7 x64 withLocalRepousing VNC
    kernel centos7/vmlinuz
    append initrd=centos7/initrd.img method=ftp://'$localip'/pub devfs=nomount inst.vnc inst.vncpassword=password
            
    label 4 
    menu label ^4)Bootfromlocal drive'
        echo "$default_conf" > /var/lib/tftpboot/pxelinux.cfg/default
      fi
    }
    mount_cd() {
    mount|grep '^/dev/sr0'
    if [[ $? -eq 0 ]]
    then
      echo '光盘已挂载。'
    else
      mount /dev/sr0 /mnt/ &> /dev/null
      if [[ $? -ne 0 ]]
      then
        count=$(( $count + 1 ))
        if [[ $count -eq 20 ]];then
          echo '超时退出';
          exit 8;
        fi
        echo "sr0没有光盘,挂载失败,将在5秒后重试"
        sleep 5
        mount_cd
      else
        echo '光盘挂载成功。';
      fi
    fi
    }
    confing_pxeserver() {
      if [[ ! -d /var/lib/tftpboot/centos7 ]];then
        mkdir /var/lib/tftpboot/centos7
        cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7/
        cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/centos7/
      fi
      yum -y install vsftpd
      if [[ `ls -A /var/ftp/pub/` == "" ]];then
        echo 'copy光盘文件到/var/ftp/pub/ ...';
        cp -r /mnt/* /var/ftp/pub/
        chmod -R 755 /var/ftp/pub
      fi
    }
    start_service() {
    systemctl start dnsmasq
    systemctl status dnsmasq
    systemctl start vsftpd
    systemctl status vsftpd
    systemctl enable dnsmasq
    systemctl enable vsftpd
    }
    
    dnsmasq_install
    tftp_pxe_install
    mount_cd
    confing_pxeserver
    start_service
  • 相关阅读:
    详解ABBYY FineReader 12内置的自动化任务
    提高OCR质量的技巧之区域未正确检测
    详解CorelDRAW中如何合并与拆分对象
    详解CorelDRAW中关于群组的操作
    CorelDRAW中关于锁定与解锁对象的操作
    CorelDRAW中如何分布对象
    CorelDRAW中如何复制对象属性详解
    CorelDRAW中如何再制对象详解
    CorelDRAW中六种复制对象的方法详解
    CentOS执行ping命令报错 name or service not know
  • 原文地址:https://www.cnblogs.com/tianyuanchen/p/11253406.html
Copyright © 2020-2023  润新知