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

Centos6.5 PXE自动化安装

2014-07-30 21:04 357 查看
Centos6.5 PXE自动化安装




首先我们将根据此图说明PXE自动安装的过程:
主机1开机以网卡方式启动,发现自己没有IP地址, 那么网卡rom中的dhcp客户端会发起discovery的广播请求,dhcp服务器发现请求后会给网卡分配一个ip地址告诉客户端TFTP服务器的地址及pxelinux.0所在的路径(相对路径)。于是客户端启动网络卡rom中的tftp客户端到TFTP服务器下载pxelinux.0及其配置文件pxelinux.cfg/default 和相关文件【此配置文件会告诉pxelinux.0如何及以何种方式引导界面】然后在内存中展开运行。显示如下图引导界面:



然后开始加载kernel(vmlinuz)和ramdisk(initrd.img),其中initrd.img在default中添加附加选项例如:ks配置文件的位置是否使用dhcp获取地址等。在内存展开后会运行会运行/init 。init会调用/bin/loader根据附加选项中提供的ks地址去下载ks配置文件 根据ks配置文件提供的信息去下载服务器主机提供的安装树上image/install.image 这个文件中包含anaconda应用程序 然后启动anaconda 。anaconda根据ks配置文件至此安装过程启动下面将详细介绍整个过程的配置
实验网络拓扑图


配置dhcp服务器:
Vim /etc/dhcp/dhcpd.conf
内容如下:
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "hefeng.com";
option domain-name-servers 172.16.34.1;

default-lease-time 86400;
max-lease-time 100000;

log-facility local7;

subnet 172.16.0.0  netmask 255.255.0.0 {
range 172.16.34.2 172.16.34.100;
option routers 172.16.34.1;
next-server 172.16.34.1;  ------>tftp服务器地址
filename "pxelinux.0";   ------->引导文件相对位置
}

启用dhcp服务




安装httpd服务器 yum install httpd -y
挂载光盘镜像至/var/www/html/
Mount /dev/cdrom /var/www/html/centos
cp ~/anaconda-ks.cfg /var/www/html/ks.cfg
Ks内容如下:
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
url --url=http://172.16.34.1/centos/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted           $6$NpvdMIOj$9IIqXQ05uucKanibRIrjXP/Dn2dr3yX3xleCtp8HFj91ilMalqijSWHJnqnp9Ew07M.Lf2hMzrGi9bwXqEMhM0# Reboot after installation
reboot
firewall --disabled
authconfig --useshadow  --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
zerombr yes
clearpart --all

part /boot --fstype=ext4 --size=200
part pv.008002 --size=61440

volgroup vg0 --pesize=8192 pv.008002
logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480
logvol swap --name=swap --vgname=vg0 --size=2048
logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240   注意:分区大小自行调整
logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480

repo --name="CentOS"  --baseurl=http://172.16.34.1/centos/

%packages
@Base
@Core
@base
@basic-desktop
@chinese-support
@client-mgmt-tools
@core
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@legacy-x
@network-file-system-client
@perl-runtime
@remote-desktop-clients
@x11

%end
编辑配置文件vim /etc/httpd/conf.d/welcome.conf

#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
Options -Indexes  ----->将‘-’删除
ErrorDocument 403 /error/noindex.html
</LocationMatch>
启用httpd服务





打开浏览器测试是否正常访问



配置tftp服务器
依赖与xinetd
# 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  ---->dhcp中指定的相对路径的上半部分
disable                 = no    ----->将yes改为no
per_source              = 11
cps                     = 100 2
flags                   = IPv4
}

启用及查看服务是否启动

安装syslinux软件包 yum install syslinux -y
cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/
Cp /var/www/html/centos/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot
Cp /var/www/html/centos/isolinux/{boot.msg,splash.jpg,vesamenu.c32}/var/lib/tftpboot
Mkdir -p /var/lib/tftpboot/pxelinux.cfg
Cp /var/www/html/centos/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
编辑default
内容如下:

#prompt 1
timeout 600

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.5!
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 linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://172.16.34.1/ks.cfg text
label vesa
menu label Install system with ^basic video driver
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
配置过程完成。。
安装系统默认密码:12345
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息