◆案例◆ PXE+Kickstart-实现无人值守
◆安装PXE装机所需的软件◆
yum install -y vsftpd tftp tftp-server dhcp syslinux xinetd
a).拷贝镜像文件到FTP服务器目录
mkdir /var/ftp/pub/dvd #创建用于存放镜像的目录 chown ftp:ftp /var/ftp/pub/dvd #赋予ftp属组让其有权限 mount -t iso9660 /dev/sr0 /mnt #挂载安装光盘,后期拷贝文件用 cp -a /mnt/* /var/ftp/pub/dvd #拷贝光盘内容到dvd目录下
b).配置DHCP服务 <作用是分配IP,并指明TFTP地址>
在相应的区域中覆盖写入标★语句
vim /etc/dhcp/dhcpd.conf 1 # 2 # DHCP Server Configuration file. 3 # see /usr/share/doc/dhcp*/dhcpd.conf.example 4 # see dhcpd.conf(5) man page 5 ★ subnet 192.168.1.0 netmask 255.255.255.0 { #指明分配网段/MAC ★ range 192.168.1.100 192.168.1.200; #分配的网段(100-200) ★ next-server 192.168.1.12; #指定TFTP服务器的地址 ★ filename "pxelinux.0"; #指定PXE引导程序的文件名 ★ }
c).修改TFTP配置文件,开启TFTP服务
在相应的区域中修改以下标★语句
vim /etc/xinetd.d/tftp 1 # default: off 2 # description: The tftp server serves files using the trivial file transfer \ 3 # protocol. The tftp protocol is often used to boot diskless \ 4 # workstations, download configuration files to network-aware printers, \ 5 # and to start the installation process for some operating systems. 6 service tftp 7 { 8 socket_type = dgram 9 protocol = udp 10 wait = yes 11 user = root 12 server = /usr/sbin/in.tftpd ★ server_args = -s /tftpboot #设置默认工作目录 ★ disable = no #设置开机自启动 15 per_source = 11 16 cps = 100 2 17 flags = IPv4 18 }
d).创建相关目录并拷贝所需文件
mkdir -p /tftpboot/pxelinux.cfg cp -a /var/ftp/pub/dvd/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default cp -a /usr/share/syslinux/pxelinux.0 /tftpboot/ chmod 644 /tftpboot/pxelinux.cfg/default cp -a /var/ftp/pub/dvd/isolinux/* /tftpboot/
e).开启相关服务
systemctl restart dhcpd
systemctl restart tftp
systemctl restart vsftpd
systemctl restart xinetd
◆配置kisckstart无人值守安装脚本◆
a).安装主程序
yum install -y system-config-kickstart
b).配置安装脚本
system-config-kickstart #启动装机脚本生成工具(图形界面)
#此处应配置生成装机文件 本步骤跳过(以下是测试脚本)
vim ks.cfg #platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use network installation# url --url="ftp://192.168.1.1/pub/dvd" #此处修改为本机IP # Root password rootpw --iscrypted $1$K4WAmqxk$ccusVq9PIk6f1uMqJ48fI1 # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Installation logging level logging --level=info # System timezone timezone Asia/Shanghai # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all # Disk partitioning information part /boot --asprimary --fstype="ext4" --size=500 part swap --fstype="swap" --size=2000 part / --fstype="ext4" --grow --size=1 %packages @base %end
cp -a ks.cfg /var/ftp/pub/ #拷贝生成的脚本到指定目录下
c).打开引导文件,在相应的区域中修改以下标★语句
vim /tftpboot/pxelinux.cfg/default 61 label linux 62 menu label ^Install CentOS 7 63 menu default #添加 64 kernel vmlinuz 65 append initrd=initrd.img ks=ftp://192.168.20.10/pub/ks.cfg #指定主服务器IP地址 66 67 label check 68 menu label Test this ^media & install CentOS 7 69 # menu default #注释掉 70 kernel vmlinuz 71 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
d).另开虚拟机测试即可