利用PXE技术部署RHEV 3.0 hypervisor(附脚本)

又过了一年了,红帽已经发布了RHEV 3.0的正式版本,详细的可以看这个链接 https://www.redhat.com/apps/store/rhev/

先说一下我的环境吧,RHEL 6.2 (CentOS 6.2我也试过了,可以使用),配好YUM源,然后运行脚本,然后用ifconfig 把一块网卡的IP临时配置成固定的,最后用启动DHCP服务就可以了。

为了实验的方便,我是在VMWARE虚拟机中做的实验。

脚本是根据RHEVH光盘里面的脚本改写的,执行格式是

sh pxe.sh ISO镜像

ISO镜像的下载地址在

相关阅读:

尝鲜RHEV 3.0——RHEV-M安装篇

尝鲜RHEV 3.0——RHEV-H安装篇

尝鲜RHEV 3.0——浏览器登录管理中心

脚本的主要内容:

#!/bin/bash

#author suzezhi 

#based on RedHat livecd-iso-to-pxeboot script

export PATH=/sbin:/usr/sbin:$PATH

if [ $(id -u) != 0 ]; then

echo "You need to be root to run this script."

exit 1

fi

if [ $# != 1 ];then

echo ""

echo "usage: sh $0 path/file-name.iso "

echo ""

exit 1

fi

ISO="$1"

install_package() {

yum -y install tftp-server dhcp syslinux 

if [ $? != 0 ];then

echo "please check your yum repo!!"

exit 1

fi

}

setup_dhcpd() {

cat >> /etc/dhcp/dhcpd.conf << EOF

option domain-name-servers 192.168.0.254;

max-lease-time 7200;

authoritative;

subnet 192.168.0.0 netmask 255.255.255.0 {

range 192.168.0.1 192.168.0.253;

next-server 192.168.0.254;

filename "pxelinux.0";

}

EOF

#sed -i 's/DHCPDARGS=/DHCPDARGS=eth1/' /etc/sysconfig/dhcpd

}

exitclean() {

echo "Cleaning up to exit..."

[ -d "$CDMNT" ] && umount $CDMNT && rmdir $CDMNT

exit 1

}

prepare_file(){

CDMNT=$(mktemp -d /tmp/cdtmp.XXXXXX)

echo $ISO

echo $CDMNT

mount -o loop "$ISO" $CDMNT || exitclean

if [ ! -d $CDMNT/isolinux -o ! -f $CDMNT/isolinux/initrd0.img ]; then

echo "The ISO image doesn't look like a LiveCD ISO image to me."

exitclean

fi

#create the initrd image

mkdir tftpboot

ISOBASENAME=`basename "$ISO"`

ISODIRNAME=`dirname "$ISO"`

( cd "$ISODIRNAME" && echo "$ISOBASENAME" | cpio -H newc --quiet -L -o ) |

gzip -9 |

cat $CDMNT/isolinux/initrd0.img - > tftpboot/initrd0.img

# Kernel image.

cp $CDMNT/isolinux/vmlinuz0 tftpboot/vmlinuz0

# pxelinux bootloader.

if [ -f /usr/share/syslinux/pxelinux.0 ]; then

cp /usr/share/syslinux/pxelinux.0 tftpboot

elif [ -f /usr/lib/syslinux/pxelinux.0 ]; then

cp /usr/lib/syslinux/pxelinux.0 tftpboot

fi

#get the boot append line from original cd image

if [ -f $CDMNT/isolinux/isolinux.cfg ]; then

APPEND=$(grep -m1 append $CDMNT/isolinux/isolinux.cfg | sed -e "s#CDLABEL=[^ ]*#/$ISOBASENAME#" -e "s/ *append *//")

fi

umount $CDMNT

rmdir $CDMNT

}

setup_tftp(){

# pxelinux configuration.

mkdir tftpboot/pxelinux.cfg

cat > tftpboot/pxelinux.cfg/default <<EOF

DEFAULT pxeboot

TIMEOUT 20

PROMPT 0

LABEL pxeboot

KERNEL vmlinuz0

APPEND rootflags=loop $APPEND

ONERROR LOCALBOOT 0

EOF

mv tftpboot  /var/lib/

# All done, clean up.

sed -i '/disable/c\\tdisable\t\t\t= no' /etc/xinetd.d/tftp

}

setenforce 0

service iptables stop

install_package

prepare_file

setup_tftp

setup_dhcpd

service xinetd restart

echo 'you can set your ip address to 192.168.0.254 and start your dhcp service ,then you can start your dhcp'

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pxgwy.html