您的位置:首页 > 运维架构 > Linux

Kickstart 全自动安装部署RHEL 7.0

2017-10-18 13:38 603 查看
一、简介1.1 什么是PXEPXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。严格来说,PXE 并不是一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。PXE 协议可以使计算机通过网络启动。此协议分为 Client端和 Server 端,而PXE Client则在网卡的 ROM 中。当计算机引导时,BIOS 把 PXE Client 调入内存中执行,然后由 PXE Client 将放置在远端的文件通过网络下载到本地运行。运行 PXE 协议需要设置 DHCP 服务器和 TFTP 服务器。DHCP 服务器会给 PXE Client(将要安装系统的主机)分配一个 IP 地址,由于是给 PXE Client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的 PXE 设置。此外,在 PXE Client 的 ROM 中,已经存在了 TFTP Client,那么它就可以通过 TFTP 协议到 TFTP Server 上下载所需的文件了。PXE的工作过程:1. PXE Client 从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP;2. DHCP 服务器返回分配给客户机的IP 以及PXE文件的放置位置(该文件一般是放在一台TFTP服务器上) ;3. PXE Client 向本网络中的TFTP服务器索取pxelinux.0 文件;4. PXE Client 取得pxelinux.0 文件后之执行该文件;5. 根据pxelinux.0 的执行结果,通过TFTP服务器加载内核和文件系统 ;6. 进入安装画面, 此时可以通过选择HTTP、FTP、NFS 方式之一进行安装;详细工作流程,请参考下面这幅图:

1.2 什么是KickstartKickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为ks.cfg的文件。如果在安装过程中(不只局限于生成Kickstart安装文件的机器)出现要填写参数的情况,安装程序首先会去查找Kickstart生成的文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便需要安装者手工干预了。所以,如果Kickstart文件涵盖了安装过程中可能出现的所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启系统,并结束安装。PXE+Kickstart 无人值守安装操作系统完整过程如下:

-----------------------------------分割线--------------------------------------------------系统环境实验环境:VMware Workstation 11系统平台:RHEL7网络模式:LAN区段DHCP / TFTP IP:192.168.153.130HTTP / FTP / NFS IP:192.168.153.130防火墙已关闭/iptables: Firewall is not running.SELINUX=disabled-----------------------------------分割线--------------------------------------------------前期准备所需要用到的服务:DHCP、TFTP、VSFTP配置yum仓库,挂载光盘镜像#vim /etc/yum.repos.d/rhel7.repo[rhel7]name=rhel7basurel=file:///mntenabled=1gpgcheck=0将光盘挂载到/mnt中#mount /dev/cdrom /mnt-----------------------------------分割线--------------------------------------------------配置DHCP安装DHCP服务# yum -y install dhcp修改/etc/dhcp/dhcpd.conf 配置文件,内容如下:subnet 192.168.153.0 netmask 255.255.255.0 { #所属网段及掩码; range 192.168.153.100 192.168.153.120; #IP地址池范围; option domain-name "linuxidc.seagate.com";option routers 192.168.153.130; #路由器IP,可以写网关IP; option broadcast-address 192.168.153.255;next-server 192.168.153.130; #TFTP Server 的IP地址;filename "pxelinux.0"; #pxelinux 启动文件位置;default-lease-time 600;max-lease-time 7200;}启动DHCP服务#systemctl enable dhcpd.service#systemctl start dhcpd.service-----------------------------------分割线--------------------------------------------------配置TFTP安装TFTP# yum install tftp-server –y //此步骤会安装两个包,一个是tftp-server另一个是xinetd。修改/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 #把这行改成no即可; per_source = 11 cps = 100 2 flags = IPv4}启动xinetd服务#systemctl enable xinetd.service#systemctl start xinetd.service-----------------------------------分割线--------------------------------------------------配置vsftp安装vsftp#yum -y install vsftpd启动vsftpd服务#systemctl start vsftpd.service#systemctl enable vsftpd.service创建iso文件夹目录,用来存放光盘软件包#mkdir /var/ftp/iso拷贝光盘中所有文件到iso文件夹中#cp -rf /mnt/* /var/ftp/iso/-----------------------------------分割线--------------------------------------------------配置PXE启动所需要的文件#yum -y install syslinux说明:syslinux是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX是一个小型的Linux操作系统,它的目的是简化首次安装Linux的时间,并建立修护或其它特殊用途的启动盘。拷贝启动文件到/var/lib/tftpboot里#cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/#mkdir /var/lib/tftpboot/pxelinux.cfg#cd /mnt/isolinux/#cp -rf initrd.img vmlinuz vesamenu.c32 boot.msg /var/lib/tftpboot/#cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default检查[root@localhost tftpboot]# pwd
/var/lib/tftpboot
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 pxelinux.cfg vesamenu.c32 vmlinuz boot.msg[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# ls
default-----------------------------------分割线--------------------------------------------------生成ks.cfg 文件ks.cfg是kickstart安装配置文件,系统就是按照ks.cfg来安装的。我们将在后面配置他安装Kickstart#yum -y install system-config-kickstart在桌面环境下配置Kickstart启动X Windows 环境#startx配置Kickstart#system-config-kickstart















后面几项不用管,直接保存

保存在/root/下,后缀不要动

root目录下有个anaconda-ks.cfg文件,我们进去把安装软件脚本拷贝到咱们刚才创建的那个ks.cfg中#vim /root/anaconda-ks.cfg........%packages@base@core@desktop-debugging@dial-up@fonts@gnome-desktop@guest-agents@guest-desktop-agents@input-methods@internet-browser@kde-desktop@multimedia@print-client@x11%end把anaconda-ks.cfg文件最下方的脚本粘贴到咱们的ks.cfg中#vim /root/ks.cfg把上面一串@的所有内容都粘贴进去,包括两个%哪行。把ks文件拷贝到/var/ftp/里面#cp /root/ks.cfg /var/ftp/编辑/var/lib/tftpboot/pxelinux.cfg/default文件添加一个引导选项,最后一行指向ftp应答文件的网络路径#vim /var/lib/tftpboot/pxelinux.cfg/defaultspacer.gifwKiom1XlULnRuv0WAACt6ljDh2I570.jpgcp /var/www/html/cdrom/isolinux/*.msg /var/lib/tftpboot/-----------------------------------分割线--------------------------------------------------检查检查SELinux是否关闭#setenforce 0 //关闭SELinux检查防火墙,开放dhcp,ftp,tftp服务,或者关闭防火墙#firewall-cmd --permanent --add-service=dhcp#firewall-cmd --permanent --add-service=ftp#firewall-cmd --permanent --add-port=69/udp#firewall-cmd --reload返回结果都是“success”注:这里也可以通过systemctl stop firewall来关闭防火墙检查所有服务是否正常启动#systemctl is-active dhcpd#systemctl is-active vsftpd返回结果都是“active”#netstat -tulnp | grep :69udp 0 0 0.0.0.0:69 0.0.0.0:* 3912/xinetdspacer.gif-----------------------------------分割线--------------------------------------------------default文件[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 600display 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 linelabel rhel //标红的部分是咱们添加的部分
menu label ^Install RHEL7.0
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=ftp://192.168.153.130/iso inst.ks=ftp://192.168.153.130/ks.cfg quietlabel linux
menu label ^Install Red Hat Enterprise Linux 7.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 quietlabel check
menu label Test this ^media & install Red Hat Enterprise Linux 7.0
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check quietmenu separator # insert an empty line# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshootinglabel vesa
menu indent count 5
menu label Install Red Hat Enterprise Linux 7.0 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
Red Hat Enterprise Linux 7.0.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 xdriver=vesa nomodeset quietlabel rescue
menu indent count 5
menu label ^Rescue a Red Hat Enterprise Linux system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rescue quietlabel memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system's memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtestmenu separator # insert an empty linelabel local
menu label Boot from ^local drive
localboot 0xffffmenu separator # insert an empty line
menu separator # insert an empty linelabel returntomain
menu label Return to ^main menu
menu exitmenu end-----------------------------------分割线--------------------------------------------------ks.cfg文件[root@localhost ~]# cat /var/ftp/ks.cfg#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$J36yI8p5$UCVRjlL947gD1e5zZR9uR/
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url="ftp://192.168.153.130/iso"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --asprimary --fstype="ext4" --size=10240%packages //这里及以后的内容是从/root/anaconda-ks.cfg复制过来的
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@kde-desktop
@multimedia
@print-client
@x11%end-----------------------------------分割线--------------------------------------------------安装测试最后测试结果在附件中,压缩包中是测试视频,大小为1M多。还有两个文件,分别是default文件和ks文件,大家可以自行下载并实验。最后实验测试效果视频 与 default和ks文件下载百度云网盘下载http://pan.baidu.com/s/1sjzJF5b------------------------------------------分割线------------------------------------------免费下载地址在 http://linux.linuxidc.com/用户名与密码都是www.linuxidc.com具体下载目录在 /2015年资料/9月/20日/Kickstart 全自动安装部署RHEL 7.0/下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm------------------------------------------分割线------------------------------------------Linux 基础教程:Linux Kickstart 自动安装 http://www.linuxidc.com/Linux/2015-05/117877.htm使用PXE+DHCP+Apache+Kickstart无人值守安装CentOS5.8 x86_64 http://www.linuxidc.com/Linux/2012-12/76913p4.htmLinux PXE无人值守安装出现 PXE-E32:TFTP OPen timeout的解决办法 http://www.linuxidc.com/Linux/2014-03/98986.htm使用PXE结合kickstart 自动安装Linux系统 http://www.linuxidc.com/Linux/2014-03/98014.htmRHCE认证之无人值守安装Linux系统(FTP+TFTP+DHCP+Kickstart+PXE) http://www.linuxidc.com/Linux/2013-10/91013.htmPXE网络装机(有人值守与无人值守安装) http://www.linuxidc.com/Linux/2013-07/87456.htm更多RedHat相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10本文永久更新链接地址http://www.linuxidc.com/Linux/2015-09/123312.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  安装 linux