1:什么是kickstart
Kickstart 其实是Linux系统自动部署的一个脚本,用来定制你的系统的。Kickstart的行为是由一个配置文件来控制的,它一般叫做ks.cfg。这个文件的格式直观易懂。如果您偏爱可视化,那么Red Hat Enterprise Linux带有一个方便的GUI工具,叫做redhat-config-kickstart或者system-config-kickstart,它能让您通过点击的方式配置ks.cfg。然而在实际的工作或者学习环境里,我们一般把linux系统的自动部署,统称为kickstart。其实真正的要完成自动部署,不光光是一个Kickstart的事情,它需要结合若干的工具或者服务一起来完成,下面我们介绍有哪些方法,或者方式来实现
2:实现linux的方法
一般在linux系统下做系统自动部署的方式,无外乎这几种:
- TFTP+NFS+DHCP+Kickstart
- TFTP+HTTP+DHCP+Kickstart
- TFTP+FTP+DHCP+Kickstart
3:实现的原理
大致的原理是这样的,客户机通过网卡启动,广播找到dhcp服务器,在dhcp服务的配置里面一般都指定了tftp的IP,然后客户端通过tftp的配置文件,会下载2个内核文件,用来做系统前期安装的引导(也就是我们平时安装系统时,看到那些……),配置文件还有另外一个重要的任务,就是通过指定ks.cfg(kickstart文件)文件,让客户端读到ks.cfg文件,剩下的就是ks.cfg的事情,在这个配置文件里有你定制的系统的信息,当然还有指向安装源,以及通过何种方式挂载安装源。
4.测试环境
测试环境:
系统:centos+DHCP+VSFTP+TFTP
服务器IP:192.168.1.1
DHCP地址段:192.168.1.10 – 192.168.1.100
Client:一台普通的PC(需要能从网卡,支持PXE启动)
4.1 安装配置dhcp
4.1.1 安装dhcp
#yum -y install dhcp
4.1.2 配置dhcp
# vi /etc/dhcp/dhcpd.conf
default-lease-time 21600;
max-lease-time 43200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
filename "/pxelinux.0"; \#tftp 目录
Next-server 192.168.1.1; \#tftp服务器ip
}
4.2 ftp 安装
# yum -y install vsftp
4.2.1 vstfp配置
vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES \#运行匿名用户访问
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES \#允许匿名用户上传
anon_mkdir_write_enable=YES \#允许匿名用户写
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
4.3 安装配置tftp
4.3.1 安装tftp
# yum -y install tftp\*
4.3.2 配置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 /tftpboot \#tftp目录路径
disable = no \# yes 改为no
per_source = 11
cps = 100 2
flags = IPv4
}
4.4 复制系统安装所需要的文件
4.4.1复制安装程序所必须的initrd.img 和 vmlinuz
# mount /dev/cdrom /mnt/
# cp /mnt/isolinux/initrd.img /tftpboot/
# cp /mnt/isolinux/vmlinuz /tftpboot/
4.4.2 复制pxelinux.0和default
配置PXE的引导文件,pxe需要2个文件,一个是pxelinux.0,另外一个是default
pxelinux.0 需要先安装包
#yum -y install syslinux
# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
复制defaul
# mkdir -p /tftpboot/pxelinux.cfg/
# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/
# cd /tftpboot/pxelinux.cfg/
# mv isolinux.cfg default
查看文件
#cd /tftpboot
#ls
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
# ls /tftpboot/pxelinux.cfg/
default
4.5 配置defaul
#vi /tftpboot/pxelinux.cfg/default
default 1 \#默认启动lable
prompt 1
timeout 60 \#超时时间
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.3!
menu color border 0 \#ffffffff \#00000000
menu color sel 7 \#ffffffff \#ff000000
menu color title 0 \#ffffffff \#00000000
menu color tabmsg 0 \#ffffffff \#00000000
menu color unsel 0 \#ffffffff \#00000000
menu color hotsel 0 \#ff000000 \#ffffffff
menu color hotkey 7 \#ffffffff \#ff000000
menu color scrollbar 0 \#ffffffff \#00000000
label 1
kernel /vmlinuz
append initrd=initrd.img ramdisk_size=9216 ks=ftp://192.168.1.1/pub/RHEL6/ks.cfg
ks路径一定要写绝对路径
4.6 拷贝iso 文件
# mount /dev/cdrom /mnt/
# mkdir -p /var/ftp/pub/RHEL6/
# cp -rf /mnt/\* /var/ftp/pub/RHEL6/
4.7 配置ks.cfg
复制ks.cfg,从root下复制
# cp /root/anaconda-ks.cfg /var/ftp/pub/RHEL6/
# mv anaconda-ks.cfg ks.cfg
配置ks.cfg
# vi ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --enabled --ssh
# Install OS instead of upgrade
install
# Use NFS installation media
#nfs --server=192.168.100.101 --dir=/media/cdrom
url --url=ftp://192.168.1.1/pub/RHEL6/
# Root password
rootpw --iscrypted
\$6\$MzZ3BXZsXNr0f8/x\$eCsipyVr5SmqiqGVcGVv2N5kaQ7ff7zO5qTotejBRjjNM8QkQI.Emor8jY8RAv/ULvD/FoMU/AM2V21y../7f.
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# 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
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --size=2048
part / --fstype=ext4 --grow --size=200
%packages
@base
@core
@development
@server-policy
sgpio
%end
5. 启动服务
5.1 启动dhcp
# /etc/init.d/dhcpd start
5.2 启动tftp
# /etc/init.d/xinetd start
5.3 启动vsftp
# /etc/init.d/vsftpd start
6.注意事项
6.1 Server 端必须关闭防火墙,关闭selinux
# /etc/init.d/iptables stop
# setsebool -P
setsebool: SELinux is disabled.
7. 错误
7.1 PXE:not found file
检查tftp路径
7.2. unable to download the kickstart
检查ks文件路径及配置
关闭防火墙,selinux