kickstart+kvm批量产生测试机

kickstart+kvm批量产生测试机

1.可以使用RHEL6.0自带kickstart工具创建模板:ks.cfg
******************************************************
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="ftp://192.168.0.254/pub/rhel6/dvd"
# Root password
rootpw --plaintext westos
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System authorization information
auth  --useshadow  --passalgo=md5
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Chongqing
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel 
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=6000
part swap --fstype="swap" --size=1000

%post
cd /etc/yum.repos.d/;
cat > test.repo << end
[server]
name=server
baseurl=http://192.168.0.254/pub/rhel6/
gpgckeck=0
end
mkdir  -p  /var/cache/yum/x86_64/6Server ;
yum clean all ;
yum install lftp -y
%end

%packages
@base
@dial-up

%end
******************************************************

2.使用virt-intall测试:
   使用dd命令产生虚拟机硬盘
   dd if=/dev/zero of=/var/lib/libvirt/images/server.img bs=1G count=8
   virt-install --vnc --noautoconsole --name=server --ram=512 --arch=x86_64 --vcpus=1 --os-type=linux --os-variant=rhel6 --hvm --accelerate --disk=/var/lib/libvirt/images/server.img size=8G --location=ftp://192.168.0.254/pub/rhel6/dvd  --extra-args="ks=http://192.168.0.158/ks.cfg" && virt-install --autostart server

3.批量产生虚拟机shell
#!/bin/bash
#function: add test servers

echo "input servers Num you need :"
read Num;

i=1;
for((i=1;i<=$Num;i++))
do
   dd if=/dev/zero of=/var/lib/libvirt/images/server$i.img bs=1G count=8
   virt-install --vnc \
                --noautoconsole \
                --name=server$i \
                --ram=512 --arch=x86_64 \
                --vcpus=1 --os-type=linux \
                --os-variant=rhel6 \
                --hvm --accelerate \
                --disk=/var/lib/libvirt/images/server$i.img size=8G \
                --location=ftp://192.168.0.254/pub/rhel6/dvd \
                --extra-args="ks=http://192.168.0.158/ks.cfg" > /dev/null
    echo "server$i created ok!"
done

你可能感兴趣的:(kickstart+kvm批量产生测试机)