系統版本:
root@zjh-server-pxe:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal
1、dhcp
安裝 isc-dhcp-server
apt-get install isc-dhcp-server
修改 /etc/default/isc-dhcp-server
INTERFACESv4="ens33"
修改 /etc/dhcp/dhcpd.conf,在最后一行添加配置如下:
subnet 192.168.57.0 netmask 255.255.255.0 { range 192.168.57.100 192.168.57.200; option subnet-mask 255.255.255.0; option routers 192.168.57.2; option domain-name-servers 192.168.57.2; option broadcast-address 192.168.57.255; filename "pxelinux.0"; next-server 192.168.57.149; }
啟動dhcp服務並設置開機啟動
systemctl start isc-dhcp-server systemctl enable isc-dhcp-server
2、tftp
安裝 tftpd-hpa
apt-get install tftp-hpa
修改 /etc/default/tftpd-hpa
TFTP_USERNAME="tftp" TFTP_DIRECTORY="/var/lib/tftpboot" TFTP_ADDRESS="0.0.0.0:69" TFTP_OPTIONS="-l -c -s"
創建 tftp目錄並設置權限
mkdir /var/lib/tftpboot/ && chmod 777 /var/lib/tftpboot/
啟動 tftp服務並設置開機啟動
systemctl start tftpd-hpa.service systemctl enable tftpd-hpa.service
3、http
安裝 apache2
apt-get install apache2
啟動 apache2服務並設置開機啟動
systemctl start apache2.service systemctl enable apache2.service
4、pxe
創建工作目錄
mkdir /var/lib/tftpboot/Centos7.2 mkdir /var/www/html/Centos7.2
由於ubuntu20.04已經沒有pxelinux.0這個啟動文件,所以我們需要到官網下載
wget http://www.archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/netboot.tar.gz /var/lib/tftpboot/
解壓
root@zjh-server-pxe:/var/lib/tftpboot# tar -zxvf netboot.tar.gz root@zjh-server-pxe:/var/lib/tftpboot# ls ldlinux.c32 netboot.tar.gz pxelinux.0 pxelinux.cfg ubuntu-installer version.info Centos7.2
掛載光盤並拷貝鏡像文件到工作目錄
root@zjh-server-pxe:~# mount /dev/sr0 /mnt/ root@zjh-server-pxe:~# cd /mnt/ root@zjh-server-pxe:/mnt# cp -r * /var/www/html/Centos7.2/
拷貝啟動內核到工作目錄
root@zjh-server-pxe:/mnt# cd /var/www/html/Centos7.2/isolinux/ root@zjh-server-pxe:/var/www/html/Centos7.2/isolinux# cp vmlinuz initrd.img /var/lib/tftpboot/Centos7.2/
修改 /var/lib/tftpboot/pxelinux.cfg/default
default Centos7.2 prompt 0 timeout 600 display boot.msg label Centos7.2 kernel Centos7.2/vmlinuz append initrd=Centos7.2/initrd.img repo=http://192.168.57.149/Centos7.2 ks=http://192.168.57.149/Centos7.2/ks.cfg
5、kickstart
這里可以通過安裝system-config-kickstart,通過圖形化界面生成ks.cfg文件;
還有一種方法就是 已經安裝完成的機器上都有/root/anaconda-ks.cfg這個文件,可以改名為ks.cfg直接使用。
root@zjh-server-pxe:/var/www/html/Centos7.2# more ks.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use network installation url --url="http://192.168.57.149/Centos7.2" # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda # Keyboard layouts keyboard --vckeymap=us --xlayouts='us','cn' # System language lang zh_CN.UTF-8 # Network information network --bootproto=dhcp --device=eno16777736 --ipv6=auto --activate network --hostname=localhost.localdomain # Root password rootpw --iscrypted $6$totlFMklPXP1obga$zC1nRV6L2YcB5ZF88Y6JjdE3OT6Vm6GBVkEmpXy22xKK9umMR5ofDJiCEoYCVuiVGDvPCGLYzX5TeXxidkhM3. # System services services --enabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc user --name=zjh --password=$6$gucjhf1N9pliUxRk$VkC.HHC6QvHjm6g6mDENczlwwwGbhpgUDnqk0pOg9KCWo.5QreEp254hXlhZeAxLmKyOOU0j9ebiG1tvE4.Qh1 --iscrypted --gecos="zjh" # System bootloader configuration bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda autopart --type=lvm # Partition clearing information clearpart --none --initlabel %packages @^infrastructure-server-environment @base @core @development @dns-server @file-server @ftp-server @ha @infiniband @java-platform @mail-server @mariadb @postgresql @remote-system-management @resilient-storage chrony kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end