Ubuntu上配置PXE服务器

    xiaoxiao2021-12-02  19

    准备配置网卡安装DHCP TFTPPXE NFS 服务 配置DHCP配置TFTP服务配置pxe 启动文件添加启动镜像配置nfs 安装kickstart 自动安装

    转自这里

    准备

    安装好 Ubuntu 14.04 系统的机器支持DHCP的路由器一个支持pxe启动的目标机器Ubuntu机器和目标机器已经通过交换机连到同一个网络

    配置网卡

    /etc/network/interfaces

    # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.20 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8

    重启网络服务

    sudo /etc/init.d/networking restart

    这一步未必起效。ifconfig 命令可能ip没有改变, 可以从 System Settings –> Network –> 去设置静态IP 由于配置静态IP了,可能会导致无法连接外网。配置网络可以等到apt-get install的步骤之后来配置。或者Ubuntu的机器配置双网卡,一个连接外网,另一个连接交换机。

    安装DHCP, TFTP,PXE, NFS 服务

    sudo apt-get update sudo apt-get install -y isc-dhcp-Server inetutils-inetd tftpd-hpa syslinux nfs-kernel-Server sudo apt-get install -y apache2

    配置DHCP

    /etc/default/dhcp-server

    INTERFACES="eth0"

    /etc/dhcp/dhcpd.conf

    default-lease-time 600; max-lease-time 7200; subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.21 192.168.1.240; option subnet-mask 255.255.255.0; option routers 192.168.1.20; option broadcast-address 192.168.1.255; filename "pxelinux.0"; next-Server 192.168.1.20; }

    重启DHCP服务

    sudo /etc/init.d/isc-dhcp-server start

    配置TFTP服务

    /etc/inetd.conf

    tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot

    /etc/default/tftpd-hpa

    TFTP_USERNAME="tftp" TFTP_DIRECTORY="/var/lib/tftpboot" TFTP_ADDRESS="[:0.0.0.0:]:69" TFTP_OPTIONS="--secure" RUN_DAEMON="yes" OPTIONS="-l -s /var/lib/tftpboot"

    开机启动 tftp

    sudo update-inetd --enable BOOT sudo service tftpd-hpa start

    检查状态

    sudo netstat -lu | grep tftp

    配置pxe 启动文件

    sudo mkdir /var/lib/tftpboot sudo mkdir /var/lib/tftpboot/pxelinux.cfg sudo mkdir -p /var/lib/tftpboot/Ubuntu/14.04/amd64/ sudo cp /usr/lib/syslinux/vesamenu.c32 /var/lib/tftpboot/ sudo cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/

    /var/lib/tftpboot/pxelinux.cfg/default

    DEFAULT vesamenu.c32 TIMEOUT 100 PROMPT 0 MENU INCLUDE pxelinux.cfg/pxe.conf NOESCAPE 1 LABEL Try Ubuntu 14.04 Desktop MENU LABEL Try Ubuntu 14.04 Desktop kernel Ubuntu/vmlinuz append boot=casper netboot=nfs nfsroot=192.168.1.20:/var/lib/tftpboot/Ubuntu/14.04/amd64 initrd=Ubuntu/initrd.lz quiet splash ENDTEXT LABEL Install Ubuntu 14.04 Desktop MENU LABEL Install Ubuntu 14.04 Desktop kernel Ubuntu/vmlinuz append boot=casper automatic-ubiquity netboot=nfs nfsroot=192.168.1.20:/var/lib/tftpboot/Ubuntu/14.04/amd64 initrd=Ubuntu/initrd.lz quiet splash ENDTEXT

    /var/lib/tftpboot/pxelinux.cfg/pxe.conf

    MENU TITLE PXE Server NOESCAPE 1 ALLOWOPTIONS 1 PROMPT 0 MENU WIDTH 80 MENU ROWS 14 MENU TABMSGROW 24 MENU MARGIN 10 MENU COLOR border 30;44 #ffffffff #00000000 std

    添加启动镜像

    1.下载镜像

    sudo wget http://releases.ubuntu.com/14.04/ubuntu-14.04.3-desktop-amd64.iso

    2.挂载

    sudo mount -o loop /mnt/ubuntu-14.04.3-desktop-amd64.iso /media/ sudo cp -r /media/* /var/lib/tftpboot/Ubuntu/14.04/amd64/ sudo cp -r /media/.disk /var/lib/tftpboot/Ubuntu/14.04/amd64/ sudo cp /media/casper/initrd.lz /media/casper/vmlinuz /var/lib/tftpboot/Ubuntu/

    配置nfs

    /etc/exports

    /var/lib/tftpboot/Ubuntu/14.04/amd64 *(ro,async,no_root_squash,no_subtree_check)

    重启nfs服务

    sudo /etc/init.d/nfs-kernel-server start

    安装

    要在目标机器上 设置pxe启动。 现在的机器一般都支持pxe启动

    kickstart 自动安装

    /var/lib/tftpboot/pxelinux.cfg/default

    DEFAULT vesamenu.c32 TIMEOUT 100 PROMPT 0 MENU INCLUDE pxelinux.cfg/PXE.conf NOESCAPE 1 LABEL local MENU LABEL Boot from local driver MENU DEFAULT localboot 0 LABEL Try Ubuntu 14.04 Desktop MENU LABEL Try Ubuntu 14.04 Desktop kernel Ubuntu/vmlinuz append boot=casper netboot=nfs nfsroot=192.168.1.20:/var/lib/tftpboot/Ubuntu/14.04/amd64 initrd=Ubuntu/initrd.lz quiet splash ENDTEXT LABEL Install Ubuntu 14.04 Desktop MENU LABEL Install Ubuntu 14.04 Desktop kernel Ubuntu/vmlinuz append boot=casper automatic-ubiquity netboot=nfs nfsroot=192.168.1.20:/var/lib/tftpboot/Ubuntu/14.04/amd64 initrd=Ubuntu/initrd.lz quiet splash ENDTEXT LABEL Install Auto Ubuntu 14.04 Desktop MENU LABEL Auto Install Ubuntu 14.04 Desktop kernel Ubuntu/vmlinuz append boot=casper automatic-ubiquity netboot=nfs nfsroot=192.168.1.20:/var/lib/tftpboot/Ubuntu/14.04/amd64 initrd=Ubuntu/initrd.lz quiet splash ks=nfs:192.168.1.20:/var/lib/tftpboot/Ubuntu/14.04/amd64/ubuntu.ks.cfg ENDTEXT LABEL Install CentOS6.5 MENU LABEL Auto Install CentOS 6.5 kernel CentOS/6.5/vmlinuz append boot=casper automatic-ubiquity netboot=nfs nfsroot=192.168.1.20:/var/lib/tftpboot/CentOS/6.5/x86_64 initrd=CentOS/6.5/initrd.img splash ks=nfs:192.168.1.20:/var/lib/tftpboot/CentOS/6.5/auto.ks ENDTEXT LABEL Install CentOS7.2 MENU LABEL Auto Install CentOS 7.2 kernel CentOS/7.2/vmlinuz append initrd=CentOS/7.2/initrd.img method=nfs:192.168.1.20:/var/lib/tftpboot/CentOS/7.2/x86_64 devfs=nomount ks=nfs:192.168.1.20:/var/lib/tftpboot/CentOS/7.2/auto.ks ENDTEXT

    centos6 的kickstart文件

    # Kickstart file automatically generated by anaconda. #version=DEVEL install reboot nfs --server=192.168.1.20 --dir=/var/lib/tftpboot/CentOS/6.4/x86_64 lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto dhcp --noipv6 rootpw --iscrypted $6$6hnmkS6Oqv8n2bnD$pBfBL3XoZW/wXJGHdOtVlFd61xrzK7QJ0SgoC0jeCYJupp1.9o.RsGC34svfvrssiMiLnXoZP.wQ3jt2qwaFw0 firewall --service=ssh authconfig --enableshadow --passalgo=sha512 selinux --disabled timezone --utc Asia/Shanghai user --name=media --password=$6$UfwmGiXeGli2r3v0$E/3eldZ9Jkt5UrSN42wWIWBymcho5kWS..73T.B8EEB1rrU0CC56YETjt8aAd7EDIyk1nq8MHuqPBtaBUSDfL1 --iscrypted --gecos="media" xconfig --startxonboot ignoredisk --only-use=sda # Partition clearing information clearpart --all --initlabel --drives=sda part /boot --fstype ext4 --size 500 part swap --recommended part / --fstype ext4 --size 120000 --grow bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work #clearpart --all --drives=sda #part /boot --fstype=ext4 --size=500 #part pv.008002 --grow --size=1 #volgroup vg_mediapxetest --pesize=4096 pv.008002 #logvol /home --fstype=ext4 --name=lv_home --vgname=vg_mediapxetest --grow --size=100 #logvol / --fstype=ext4 --name=lv_root --vgname=vg_mediapxetest --grow --size=1024 --maxsize=51200 #logvol swap --name=lv_swap --vgname=vg_mediapxetest --grow --size=7760 --maxsize=7760 repo --name="CentOS" --baseurl=nfs:192.168.1.20:/var/lib/tftpboot/CentOS/6.4/x86_64 --cost=100 %packages @base @core @debugging @basic-desktop @desktop-debugging @desktop-platform @directory-client @fonts @general-desktop @graphical-admin-tools @input-methods @internet-applications @internet-browser @java-platform @legacy-x @network-file-system-client @office-suite @print-client @remote-desktop-clients @server-platform @server-policy @x11 mtools pax oddjob wodim sgpio genisoimage device-mapper-persistent-data abrt-gui samba-winbind certmonger pam_krb5 krb5-workstation libXmu %end

    centos7

    #version=RHEL7 # System authorization information auth --enableshadow --passalgo=sha512 # Install OS instead of upgrade install # Reboot after installation reboot # Use NFS installation media nfs --server=192.168.1.20 --dir=/var/lib/tftpboot/CentOS/7.0/x86_64 # Firewall configuration firewall --enabled --service=ssh firstboot --disable ignoredisk --only-use=sda # Keyboard layouts # old format: keyboard us # new format: keyboard --vckeymap=us --xlayouts='us' # System language lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=eth0 --noipv6 network --hostname=localhost.localdomain # Root password rootpw --iscrypted $6$6hnmkS6Oqv8n2bnD$pBfBL3XoZW/wXJGHdOtVlFd61xrzK7QJ0SgoC0jeCYJupp1.9o.RsGC34svfvrssiMiLnXoZP.wQ3jt2qwaFw0 # SELinux configuration selinux --disabled # System services services --enabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc user --name=media --password=$6$UfwmGiXeGli2r3v0$E/3eldZ9Jkt5UrSN42wWIWBymcho5kWS..73T.B8EEB1rrU0CC56YETjt8aAd7EDIyk1nq8MHuqPBtaBUSDfL1 --iscrypted --gecos="media" # X Window System configuration information xconfig --startxonboot # System bootloader configuration bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda" --boot-drive=sda # Partition clearing information clearpart --all --initlabel --drives=sda # Disk partitioning information part /boot --fstype="xfs" --ondisk=sda --size=500 part pv.49 --fstype="lvmpv" --ondisk=sda --size=228435 volgroup centos --pesize=4096 pv.49 logvol / --fstype="xfs" --grow --maxsize=51200 --size=1024 --name=root --vgname=centos logvol swap --fstype="swap" --size=7824 --name=swap --vgname=centos logvol /home --fstype="xfs" --grow --size=500 --name=home --vgname=centos %packages @^gnome-desktop-environment @base @compat-libraries @core @desktop-debugging @development @dial-up @directory-client @fonts @gnome-desktop @guest-agents @guest-desktop-agents @input-methods @internet-browser @java-platform @multimedia @network-file-system-client @print-client @security-tools @x11 chrony kexec-tools %end

    KICKSTART 语法参考 CentOS6 和 CentOS7 有点配置不同, Ubuntu 我还没有配置起来

    转载请注明原文地址: https://ju.6miu.com/read-679774.html

    最新回复(0)