首页 > 代码库 > KVM_install and shell
KVM_install and shell
#!/bin/bash
/etc/init.d/NetworkManager stop
chkconfig NetworkManager off
service iptables stop
chkconfig iptables off
setenforce 0
LANG=en.UF-8
yum -y groupinstall "Virtualization" "Virtualization Client" "Virtualization Platform" "Virtualization Tools"
sed -r ‘s/(SELINUX=)(.*)/\1disabled/‘ /etc/selinux/config
# cd /var/lib/libvirt/images/
# qemu-img create -f qcow2 server6.img 20G //install first server name si server6.4 size 20G
# qemu-img create -b /var/lib/libvirt/images/server6.img -f qcow2 rhel6basenode1.img
mimic server name is rhel6basenode1.img
Shell:
#!/bin/bash
LANG=C
read -p "plese enter start a number{01-99}:" a
read -p "plese enter end a number{01-99}:" b
vers=Centos_Server6.img
name=Centos_Server6
soufile=/var/lib/libvirt/images/$vers
dump=/var/lib/libvirt/wgl.xml
ERROR=/var/lib/libvirt/images/error.log
for ((num=$a;$num<=$b;num++))
do
UUID=`uuidgen`
rm -rf /var/lib/libvirt/wgl.xml
kl=/var/lib/libvirt/images/Centos6_${num}.img
qemu-img create -b $soufile -f qcow2 $kl &> /dev/null
/usr/bin/virsh dumpxml $name > $dump 2>/$ERROR >&1
sed -i "s/$name/Centos6_${num}/" $dump
sed -i "/<uuid>/s/<uuid>.*<\/uuid>/<uuid>${UUID}<\/uuid>/" $dump
sed -i "/source file/s/<source file=‘.*‘\/>/<source file=‘\/var\/lib\/libvirt\/images\/Centos6_${num}.img‘\/>/" $dump
if [ "$num" -lt 10 ];then
sed -i "/mac address/s/f/${num}/" $dump
else
sed -i "/mac address/s/ef/${num}/" $dump
fi
virsh define $dump &> /dev/null
echo -e "$Centos_${num} \t\t [OK]"
done
Network:
# cat ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT="yes"
BRIDGE="public"
TYPE="Ethernet"
BOOTPROTO="none
# cat ifcfg-public
DEVICE="public"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO=static
IPADDR=192.168.3.56
NETMASK=255.255.252.0
DNS1=192.168.1.6
DNS2=192.168.1.7
DELAY="0"
本文出自 “linux网络服务搭建” 博客,谢绝转载!