参考:http://www.linuxprobe.com/chapter-19.html
Kickstart无人值守系统原理
未安装系统的客户机,通过与无人值守系统的访问(1,获取IP地址 2,获取引导文件 3,获取应答文件),实现自动安装系统的效果,特别适用于批量安装。
初始环境
无人值守系统的这台机器地址192.168.158.111
已经将光盘挂载到/media/cdrom
配置DHCP服务程序
[root@xiaopengfei17-2-21 ~]# yum -y install dhcp
[root@xiaopengfei17-2-21 ~]# vi /etc/dhcp/dhcpd.conf
[root@xiaopengfei17-2-21 ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
allow booting;
allow bootp;
ddns-update-style interim;
ignore client-updates;
subnet 192.168.158.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.158.111;
range dynamic-bootp 192.168.158.112 192.168.158.200;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.158.111;
filename "pxelinux.0";
}
[root@xiaopengfei17-2-21 ~]#
[root@xiaopengfei17-2-21 ~]# systemctl restart dhcpd
[root@xiaopengfei17-2-21 ~]# systemctl enable dhcpd
配置TFTP服务程序
[root@xiaopengfei17-2-21 ~]# yum -y install tftp-server
[root@xiaopengfei17-2-21 ~]# vi /etc/xinetd.d/tftp
[root@xiaopengfei17-2-21 ~]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#
protocol. The tftp protocol is often used to boot diskless \
#
workstations, download configuration files to network-aware printers, \
#
and to start the installation process for some operating systems.
service tftp
{
socket_type
= dgram
protocol
= udp
wait
= yes
user
= root
server
= /usr/sbin/in.tftpd
server_args
= -s /var/lib/tftpboot
disable = no #不禁用TFTP服务程序
per_source
= 11
cps
= 100 2
flags
= IPv4
}
[root@xiaopengfei17-2-21 ~]#
[root@xiaopengfei17-2-21 ~]# systemctl restart xinetd.service
[root@xiaopengfei17-2-21 ~]# systemctl enable xinetd.service
[root@xiaopengfei17-2-21 ~]# firewall-cmd --permanent --add-port=69/udp
success
[root@xiaopengfei17-2-21 ~]# firewall-cmd --reload
success
[root@xiaopengfei17-2-21 ~]#
配置SYSLinux服务程序
提供引导文件
[root@xiaopengfei17-2-21 ~]# yum -y install syslinux
[root@xiaopengfei17-2-21 ~]# cd /var/lib/tftpboot
[root@xiaopengfei17-2-21 tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
[root@xiaopengfei17-2-21 tftpboot]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} .
[root@xiaopengfei17-2-21 tftpboot]# cp /media/cdrom/isolinux/{vesamenu.c32,boot.msg} .
[root@xiaopengfei17-2-21 tftpboot]#
[root@xiaopengfei17-2-21 tftpboot]# mkdir pxelinux.cfg
[root@xiaopengfei17-2-21 tftpboot]# cp /media/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default
[root@xiaopengfei17-2-21 tftpboot]#
[root@xiaopengfei17-2-21 tftpboot]# vi pxelinux.cfg/default
[root@xiaopengfei17-2-21 tftpboot]# more pxelinux.cfg/default
default linux
timeout 600
display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Red Hat Enterprise Linux 7.0
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a
timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install Red Hat Enterprise Linux 7.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=ftp://192.168.158.111
ks=ftp://192.168.158.111/pub/ks.cfg quiet
配置VSFtpd服务程序
[root@xiaopengfei17-2-21 ~]# yum -y install vsftpd
[root@xiaopengfei17-2-21 ~]# systemctl restart vsftpd
[root@xiaopengfei17-2-21 ~]# systemctl enable vsftpd
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-
user.target.wants/vsftpd.service'
[root@xiaopengfei17-2-21 ~]#
[root@xiaopengfei17-2-21 ~]# cp -r /media/cdrom/* /var/ftp
[root@xiaopengfei17-2-21 ~]# firewall-cmd --permanent --add-service=ftp
success
[root@xiaopengfei17-2-21 ~]# firewall-cmd --reload
success
[root@xiaopengfei17-2-21 ~]#
setsebool -P ftpd_connect_all_unreserved=on #在SELinux中开启对FTP传输的允许策略
创建KickStart应答文件
[root@xiaopengfei17-2-21 ~]# cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg
[root@xiaopengfei17-2-21 ~]# chmod +r /var/ftp/pub/ks.cfg
[root@xiaopengfei17-2-21 ~]# vi /var/ftp/pub/ks.cfg
[root@xiaopengfei17-2-21 ~]# more /var/ftp/pub/ks.cfg
#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=ftp://192.168.158.111
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=eno16777736 --onboot=off --ipv6=auto
network --hostname=xiaopengfei17-2-21
# Root password
rootpw --iscrypted $6$ytRFTzr4xfBV7zr/
$ABNj4zBRQaFhpE8uyjripuVxcDmw09.Ac2HaGigZFOIZROCcKdqJu9vyHLaK5K1t9GlMwhl7RNlBA
QzwEVXO50
# System timezone
timezone Asia/Shanghai --isUtc
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel
%packages
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@multimedia
@print-client
@x11
%end
至此,Kickstart无人值守安装系统搭建完成。
未安装系统的客户机插上网线 ,开机后首先DHCP获取一个IP,接着获取引导文件 ,然后获取应答文件,最后开始自动安装。