KVM_install and shell

來源:互聯網
上載者:User

標籤: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網路服務搭建” 部落格,謝絕轉載!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.