您的位置:首页 > 理论基础 > 计算机网络

pxe+kickstart实现无人值守网络安装rhel5.4

2014-01-24 12:49 1141 查看
前言:系统的装我们有很多种方式,光盘、硬盘、ftp、http等,而对于拥有多台主机的实验环境而言,单一的通过光盘等来手动显然已经无法满足需求,现在我们就来了解一下通过pxe/kickstart 实现通过网络的无人值守的安装。
1. 什么是PXE
严格来说,PXE 并不是一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。PXE (Pre-boot Execution Environment)协议可以使计算机通过网络启动。此协议分为 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 上下载所需的文件了。2. 什么是KickstartKickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为 ks.cfg的文件。如果在安装过程中(不只局限于生成Kickstart安装文件的机器)出现要填写参数的情况,安装程序首先会去查找 Kickstart生成的文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便需要安装者手工干预了。所以,如果Kickstart文件涵盖了安装过程中可能出现的所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启系统,并结束安装。

实现安装示意图:



1、完整的yum源
#挂载光盘
[root@localhost ~]# mount /dev/cdrom /media/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
#配置yum源
[root@localhost ~]# vim /etc/yum.repos.d/cdrom.repo
[rhel-server]
name=rhel-server
baseurl=file:///media/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release

[rhel-cluster]
name=rhel-cluster
baseurl=file:///media/cdrom/Cluster
enabled=1
gpgcheck=1
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release

[rhel-clusterstorage]
name=rhel-clusterstorage
baseurl=file:///media/cdrom/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release

[rhel-VT]
name=rhel-vt
baseurl=file:///media/cdrom/VT
enabled=1
gpgcheck=1
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release
2、dhcp服务
#安装dhcp
[root@localhost ~]# yum install dhcp -y

#拷贝配置文件并编辑配置
[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
[root@localhost ~]# vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.2.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.2.1;
option subnet-mask 255.255.255.0;

option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.2.1;
next-server 192.168.2.1;filename "pxelinux.0";

option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.2.2 192.168.2.128;
default-lease-time 21600;
max-lease-time 43200;

}
[root@localhost ~]# service dhcpd start && chkconfig dhcpd on
3、tftp服务
#安装
[root@localhost ~]# yum install tftp-server -y
#修改服务脚本
[root@localhost ~]# vim /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 /tftpboot
disable = no //开启tftp
per_source = 11
cps = 100 2
flags = IPv4
}
#启动服务
[root@localhost ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@localhost ~]# netstat -tulpn |grep 69
udp 0 0 0.0.0.0:69 0.0.0.0:* 13792/xinetd
#tftpboot目录的配置修改
[root@localhost ~]# cd /tftpboot
[root@localhost tftpboot]# cp /usr/lib/syslinux/pxelinux.0 ./
[root@localhost tftpboot]# cp /media/cdrom/images/pxeboot/vmlinuz ./
[root@localhost tftpboot]# cp /media/cdrom/images/pxeboot/initrd.img ./
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cp /media/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default
[root@localhost tftpboot]# vim pxelinux.cfg/default
default linux
prompt 1
timeout 10 //等待时长为10秒display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append ks=ftp://192.168.2.1/pub/ks.cfg ksdevice=eth0 initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -
~
"pxelinux.cfg/default" 24L, 411C written

4、ftp服务器
[root@localhost ~]# yum install vsftpd -y
#将光盘的文件及目录均拷贝到ftp的目录下[root@localhost ~]# cp -a /media/cdrom/* /var/ftp/pub/#开启服务并设为开启自动启动
[root@localhost ~]# service vsftpd start && chkconfig vsftpd on
5、kickstart产生ks.cfg文件
#安装system-config-kickstart
[root@localhost ~]# yum install system-config-kickstart -y
注意若系统没有安装图形,要先安装桌面
[root@localhost ~]# yum groupinstall "GNOME Desktop Environment" " X Window System" -y
[root@localhost ~]# system-config-kickstart




































保存为ks.cfg


注意:key --skip如果是红帽系统,此选项可以跳过输入序列号过程;如果是CentOS 系列,则可以不保留此项内容;reboot 此选项必须存在,也必须文中设定位置,不然kickstart显示一条消息,并等待用户按任意键后才重新引导;clearpart --all --initlabel此条命令必须添加,不然系统会让用户手动选择是否清除所有数据,这就需要人为干预了,从而导致自动化过程失败;因为sendmail及cups开机时很费时,故将其关闭,也可根据需要定义。
#将修改过的文件保存到ftp的根目录下 很重要
[root@localhost ~]#cp /root/ks.cfg /var/ftp/pub/
6、创建新虚拟机测试


安装完成


本文出自 “刘园的博客” 博客,请务必保留此出处/article/4538652.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: