用Kickstart从FTP服务安装CentOS7

基于PXE协议

1、安装相关工具
yum install -y xinetd syslinux tftp-server vsftpd dhcp

2、配置xinetd启用tftp服务
vi /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
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

3、启动xinetd和tftp服务
systemctl --system daemon-reload
systemctl start xinetd.service
systemctl start tftp.service
systemctl enable xinetd.service
systemctl enable tftp.service

4、添加PXE加载器到tftp
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

# 可选择安装加载器菜单
menu文本风格(推荐)
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
或vesamenu简单图形风格
cp /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/

5、CentOS7镜像mount到ftp共享目录
wget http://mirrors.usc.edu/pub/linux/distributions/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso
mkdir centos7
mount -o loop CentOS-7-x86_64-Minimal-1804.iso /var/ftp/pub/centos7

6、添加Linux启动镜像到tftp
cp /var/ftp/pub/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/
cp /var/ftp/pub/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/

7、添加PXE安装引导配置
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/ftp/pub/centos7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
vi /var/lib/tftpboot/pxelinux.cfg/default

default pxe
timeout 600

menu clear

label pxe
  menu label ^Install CentOS 7 by PXE
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=ftp://192.168.10.111/ks.cfg

menu separator # insert an empty line

label local
  menu label Boot from ^local drive
  localboot 0xffff

menu end

8、配置dhcp服务
vi /etc/dhcp/dhcpd.conf

ddns-update-style interim;
ignore client-updates;
subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.150 192.168.10.200;
  option routers 192.168.1.1;
  option subnet-mask 255.255.0.0;
  option domain-name-servers 192.168.1.1;
  default-lease-time 259200;
  max-lease-time 518400;
  next-server 192.168.10.111;
  filename "pxelinux.0";
}

9、配置Kickstart
cp /root/anaconda-ks.cfg /var/ftp/ks.cfg
chmod +r /var/ftp/ks.cfg
vi /var/ftp/ks.cfg

graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8

# Network information
network  --bootproto=dhcp --ipv6=auto --activate
network  --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$.15GwS6IuwOqAc8r$4D5lT2Fus5ouvq7BGu8vdZ8pGd6oF7eWhLC7WiekOb.jg4KJR5qEoDuV3Xl.6aSVku1SENraGDLnNKuz/mEZQ/
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
#clearpart --all --initlabel --drives=sda
clearpart --none

%packages
@^minimal
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

10、启动PXE安装服务
systemctl --system daemon-reload
systemctl start vsftpd.service
systemctl start dhcpd.service
systemctl enable vsftpd.service
systemctl enable dhcpd.service

11、临时关闭防火墙和SELinux
systemctl stop firewalld
setenforce 0

12、踩到的坑

  • dhcp服务启动后导致局域网内动态分配IP的主机无法上网

dhcp服务配置的“option routers”和“domain-name-servers”改为局域网主网关IP

  • PXE-E11: ARP Timeout

检查tftp的pxelinux配置是否正确,dhcp是否启动正常

13、参考资料
https://www.cnblogs.com/linux-wangkun/p/5914103.html
https://www.linuxidc.com/Linux/2017-02/140512.htm
http://www.cnblogs.com/linux-wangkun/p/5910709.html
https://communities.vmware.com/message/2355112
http://bbs.chinaunix.net/thread-3620659-1-1.html
https://www.linuxidc.com/Linux/2017-08/146169.htm
https://www.cnblogs.com/zwei0227/p/6561897.html
https://www.linuxidc.com/Linux/2013-10/91013.htm

你可能感兴趣的:(用Kickstart从FTP服务安装CentOS7)