PXE+Kickstart 无人值守安装操作系统
安装前准备
#关闭防火墙、selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
#配置ip地址
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPADDR=192.168.130.135
PREFIX=24
GATEWAY=192.168.130.1
DNS=8.8.8.8
DEVICE="ens33"
ONBOOT="yes"
#重启
[root@localhost ~]# systemctl restart network
#配置yum源安装软件包
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir backup
[root@localhost yum.repos.d]# mv *.repo backup/
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo #这里用阿里云的yum源
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum install -y dhcp tftp tftp-server syslinux wget vsftpd pykickstart
配置dhcp服务
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
#确保配置文件如下
ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
allow unknown-clients;
# A slightly different configuration for an internal subnet.
subnet 192.168.130.0 netmask 255.255.255.0
{
range 192.168.130.130 192.168.130.200;
option domain-name-servers 8.8.8.8;
option domain-name "server1.example.com";
option routers 192.168.130.1;
option broadcast-address 192.168.130.255;
default-lease-time 600;
max-lease-time 7200;
# PXE SERVER IP
next-server 192.168.130.135; # DHCP server ip
filename "pxelinux.0";
}
准备TFTP服务
#打开tftp配置文件
[root@localhost ~]# vim /etc/xinetd.d/tftp
#修改内容如下
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = yes
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} /var/lib/tftpboot/
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# mkdir /var/lib/tftpboot/netboot
准备vsftpf服务
#在VMware中将cd驱动器链接
[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cp -rf /mnt/* /var/ftp/pub/
#拷贝系统启动时需要的镜像文件
[root@localhost ~]# cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/netboot
[root@localhost ~]# cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/netboot/
#创建ks.cfg文件
[root@localhost ~]# vim /vim/ftp/pub/ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use NFS installation media
url --url="ftp://10.36.178.135/pub/"
rootpw --plaintext 123456
#root的密码设为123456
# Use graphical install
graphical
firstboot disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux disabled
# Installation logging level
logging level=info
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader location=mbr
clearpart --all --initlabel
part swap --asprimary --fstype="swap" --size=1024
part /boot --fstype xfs --size=200
part pv.01 --size=1 --grow
volgroup rootvg01 pv.01
logvol / --fstype xfs --name=lv01 --vgname=rootvg01 --size=1 --grow
reboot
%packages
@core
%end
%post
%end
#检查语法是否有错误
[root@localhost ~]# ksvalidator /var/ftp/pub/ks.cfg
PXE菜单
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 30
MENU TITLE Togogo.net Linux Training
LABEL centos7_x64
MENU LABEL CentOS 7 X64 for takehaye
KERNEL /netboot/vmlinuz
APPEND initrd=/netboot/initrd.img inst.repo=ftp://10.36.178.135/pub ks=ftp://10.36.178.135/pub/ks.cfg
#重启服务
[root@localhost ~]# systemctl restart dhcpd vsftpd tftp
#最后创建虚拟机-自动安装
注意:内存必须大于2G