The first thing to change here,is to comment out everything that is IP-related and tell the interface which interface will be the bridge. Resulting in /etc/sysconfig/network-scripts/ifcfg-eno16777736 to look like this:
 Next,we can create the config-script for the bridge interface virbr0 in/etc/sysconfig/network-scripts/ifcfg-virbr0. Most details can be copied from the original script foreno16777736:
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
       
         5 
        
       
         6 
        
       
         7 
        
        
     
 Last thing to check is if we can connect to KVM by asking for a simple list of systems:
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         -c 
        qemu 
        : 
        / 
        / 
        /system 
        list 
        
        
        Id 
        Name 
        State 
        
        
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        
        
     
    
   
  
 
 If it returns something else,then you should go trough the earlier steps to check where something went wrong.
 
 After completing the KVM installation,it’s time to start using the host. First thing we need to do is to create a new domain or VM.
 
 To create a new virtual machine using the CLI,we need to know which template we will use to install the system. To get a list of templates that are known in our KVM installation,you can do the following:
 
 
  
  
  
   
  
 
 Virtual disk images for the KVM-guests can be placed in /var/lib/libvirt by default. In case you prefer to use another location to store the disk images,SELinux will,by default,prevent access and the security context of that location needs to be changed in order to use it for KVM. To change the SELinux context when storing the images in another location (/vm for example):
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        semanage 
        fcontext 
         -a 
         -t 
        virt 
        _image 
        _t 
         
        "/vm(/.*)?" 
        
        
         
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        restorecon 
         -R 
         
        /vm 
        
        
     
    
   
  
 
 Now,to add a new VM,we can use virt-install.
 
 Example to add a windows-guest:
 
 
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
       
         5 
        
        
     
 
       
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virt 
        -install 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
         -n 
        vmwin7 
         -r 
        1024 
         
        --vcpus 
        =2 
         
        --disk 
         
        path 
        = 
        /var 
        /lib 
        /libvirt 
        /images 
        /vmwin7 
        .img 
        ,size 
        =10 
         
        --graphics 
        vnc 
        ,listen 
        =0 
        .0 
        .0 
        .0 
         
        --noautoconsole 
         
        --os 
        - 
        type 
        windows 
         
        --os 
        -variant 
        win7 
         
        --accelerate 
         
        --network 
        =bridge 
        :virbr0 
         
        --hvm 
         
        --cdrom 
         
        /var 
        /X17 
        -59186 
        .iso 
        
        
        Starting 
        install 
        . 
        . 
        . 
        
        
        Allocating 
         
        'vmwin7.img' 
         
        | 
        10 
        GB 
        00 
        :00 
        :00 
        
        
        Creating 
        domain 
        . 
        . 
        . 
         
        | 
        0 
        B 
        00 
        :00 
        :00 
        
        
        Domain 
        installation 
        still 
         
        in 
        progress 
        . 
        Waiting 
         
        for 
        installation 
        to 
        complete 
        . 
        
        |  
     
    
   
  
 
 Explanation of the arguments that were given to virt-install:
 
 
 -  –connect qemu:///system : connect to KVM on the local system,we could also connect to another KVM-host and define our new VM there
  
 -  -n vmwin7 :name of the new VM: vmwin7
  
 -  -r 1024: amount of memory for the VM: 1GB
  
 -  –vcpus=2 : amount of virtual CPU’s for the VM: 2
  
 -  –disk path=/var/lib/libvirt/images/vmwin7.img,size=10 : where to store the virtual disk image of the VM and the size: 10GB
  
 -  –graphics vnc,listen=0.0.0.0 : how to display the VM’s console: via VNC accessible from outside
  
 -  –noautoconsole : do not automatically connect to the console
  
 -  –os-type windows –os-variant win7 : type of guest OS (from the list given above)
  
 -  –accelerate : use KVM HW-acceleration
  
 -  –network=bridge:virbr0 : network bridge to use
  
 -  –hvm : full virtualisation
  
 -  –cdrom /var/X17-59186.iso : location of the installation ISO
  
 
 After launching the above command,you should be able to connect with VNC to the host and get on the console-display of the VM. The console displays what would normally,on a physical machine,appear on the attached monitor.
 
 By default,VNC will use the first availablescreen on port 5900. To be sure which screen is used,we can use virsh to show the attached console-screens for VNC:
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
        vncdisplay 
        vmwin7 
        
        
        :0 
        
        
     
    
   
  
 
 :0 means the first screen and real port 5900 as you can also see when checking with netstat which ports are currently listening:
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        netstat 
         -tln 
        |grep 
         
        :59 
        
        
        tcp 
        0 
        0 
        0 
        .0 
        .0 
        .0 
        :5900 
        0 
        .0 
        .0 
        .0 
        : 
        * 
        LISTEN 
        
        
     
    
   
  
 
 
 
 From this point,we can complete the windows installation as if it would be a normal physical system:
 
 After completing the installation with VNC,we end up with a Windows-VM that is running on our KVM-host:
 
 As for the networking part,we use the earlier created bridge (virbr0) to do NAT. This means that the KVM-host NAT’s all our connections to the real network connected to the KVM-host. If DHCP is active on that network,it can be used in the VM. Otherwise you will have to configure a static IP in the same subnet.
 
 Example to add a Linux-guest: 
 To add a Linux guest,next to the already added Windows-guest is quite similar:
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
       
         5 
        
        
     
 
       
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virt 
        -install 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
         -n 
        vmdeb7 
         -r 
        512 
         
        --vcpus 
        =1 
         
        --disk 
         
        path 
        = 
        /var 
        /lib 
        /libvirt 
        /images 
        /vmdeb7 
        .img 
        ,size 
        =2 
         
        --graphics 
        vnc 
        ,listen 
        =0 
        .0 
        .0 
        .0 
         
        --noautoconsole 
         
        --os 
        - 
        type 
        linux 
         
        --os 
        -variant 
        debianwheezy 
         
        --accelerate 
         
        --network 
        =bridge 
        :virbr0 
         
        --hvm 
         
        --cdrom 
         
        /tmp 
        /debian 
        -7 
        .5 
        .0 
        -amd64 
        -netinst 
        .iso 
        
        
        Starting 
        install 
        . 
        . 
        . 
        
        
        Allocating 
         
        'vmdeb7.img' 
         
        | 
        2 
        .0 
        GB 
        00 
        :00 
        :00 
        
        
        Creating 
        domain 
        . 
        . 
        . 
         
        | 
        0 
        B 
        00 
        :00 
        :02 
        
        
        Domain 
        installation 
        still 
         
        in 
        progress 
        . 
        You 
        can 
        reconnect 
        to 
        the 
        console 
        to 
        complete 
        the 
        installation 
        process 
        . 
        
        |  
     
    
   
  
 
 As with the Windows-VM,after launching this command,you should be able to connect with VNC to the host and get on the console of the VM to complete theDebian installation.
 
 To know which VNC-display number (and port) is used for a certain VM,the same command as used earlier should do:
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
        vncdisplay 
        vmdeb7 
        
        
         
        :1 
        
        
     
    
   
  
 
 Above command gives :1 as result,meaning that the guest vmdeb7 can be contacted with VNC on port 5901:
 
 After finishing the installation,weend up with a Linux guest running on top of our KVM-host. Which Linux distro we are using doesn’t matter since we’re doing full virtualization.
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
       
         5 
        
        
     
 
       
        
        root 
        @deb 
        : 
        ~ 
        # 
        uname 
         -a 
        
        
        Linux 
        deb 
        3 
        .2 
        .0 
        -4 
        -amd64 
         
        #1 
        SMP 
        Debian 
        3 
        .2 
        .60 
        -1 
        +deb7u3 
        x86 
        _64 
        GNU 
        /Linux 
        
        
        root 
        @deb 
        : 
        ~ 
        # 
        cat 
         
        /proc 
        /cpuinfo 
         
        |grep 
        model 
        
        
        model 
         
        : 
        13 
        
        
        model 
        name 
         
        : 
        QEMU 
        Virtual 
        CPU 
        version 
        1 
        .5 
        .3 
        
        |  
     
    
   
  
 
 Considering network,the same as with the Windows VM applies here. Our connections are NATted trough the KVM-host and we can use the DHCP-server of our real network.
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
       
         5 
        
       
         6 
        
       
         7 
        
       
         8 
        
       
         9 
        
       
         10 
        
       
         11 
        
       
         12 
        
        
     
 
       
        
        root 
        @deb 
        : 
        ~ 
        # 
        ping 
         -c1 
        8 
        .8 
        .8 
        .8 
        
        
        PING 
        8 
        .8 
        .8 
        .8 
         
        (8 
        .8 
        .8 
        .8 
        ) 
        56 
        (84 
        ) 
        bytes 
        of 
        data 
        . 
        
       
         64 
        bytes 
        from 
        8 
        .8 
        .8 
        .8 
        : 
        icmp 
        _req 
        =1 
        ttl 
        =128 
         
        time 
        =23 
        .8 
        ms 
        
        
        -- 
        - 
        8 
        .8 
        .8 
        .8 
        ping 
        statistics 
         
        -- 
        - 
        
       
         1 
        packets 
        transmitted 
        , 
        1 
        received 
        , 
        0 
        % 
        packet 
        loss 
        , 
         
        time 
        0ms 
        
        
        rtt 
        min 
        /avg 
        /max 
        /mdev 
         
        = 
        23 
        .855 
        /23 
        .855 
        /23 
        .855 
        /0 
        .000 
        ms 
        
        
        root 
        @deb 
        : 
        ~ 
        # 
        ip 
        a 
        show 
        eth0 
        
       
         2 
        : 
        eth0 
        : 
         
        < 
        ;BROADCAST 
        ,LOWER 
        _UP 
        > 
        ; 
        mtu 
        1500 
        qdisc 
        pfifo 
        _fast 
        state 
        UP 
        qlen 
        1000 
        
        
        link 
        /ether 
        52 
        :54 
        :00 
        :33 
        :65 
        :75 
        brd 
        ff 
        :ff 
        :ff 
        :ff 
        :ff 
        :ff 
        
        
        inet 
        192 
        .168 
        .202 
        .140 
        /24 
        brd 
        192 
        .168 
        .202 
        .255 
        scope 
        global 
        eth0 
        
        
        inet6 
        fe80 
        ::5054 
        :ff 
        :fe33 
        :6575 
        /64 
        scope 
        link 
        
        
        valid_lft 
        forever 
        preferred 
        _lft 
        forever 
        
        |  
     
    
   
  
 
 More KVM actions 
 Besides creating VM’s,it’s a good thing to know some basic operations regarding VM-managent.
 
 List the active virtual machines:
 
 
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        list 
        
        
        Id 
        Name 
        State 
        
        
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        -- 
        
        
        7 
        vmwin7 
        running 
        
        
        8 
        vmdeb7 
        running 
        
        
     
    
   
  
 
 Get more information about a guest: 
 
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
       
         5 
        
       
         6 
        
       
         7 
        
       
         8 
        
       
         9 
        
       
         10 
        
       
         11 
        
       
         12 
        
       
         13 
        
       
         14 
        
       
         15 
        
       
         16 
        
        
     
 
       
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
        dominfo 
        vmwin7 
        
        
        Id 
        : 
        7 
        
        
        Name 
        : 
        vmwin7 
        
        
        UUID 
        : 
        f913c6fa 
        -b597 
        -437d 
        -b6f5 
        -797314e34847 
        
        
        OS 
         
        Type 
        : 
        hvm 
        
        
        State 
        : 
        running 
        
        
        CPU 
        (s 
        ) 
        : 
        2 
        
        
        CPU 
         
        time 
        : 
        20955 
        .1s 
        
        
        Max 
        memory 
        : 
        1048576 
        KiB 
        
        
        Used 
        memory 
        : 
        1048576 
        KiB 
        
        
        Persistent 
        : 
        yes 
        
        
        Autostart 
        : 
        disable 
        
        
        Managed 
        save 
        : 
        no 
        
        
        Security 
        model 
        : 
        selinux 
        
        
        Security 
        DOI 
        : 
        0 
        
        
        Security 
         
        label 
        : 
        system 
        _u 
        :system_r 
        :svirt_t 
        :s0 
        :c638 
        ,c926 
         
        (enforcing 
        ) 
        
        |  
     
    
   
  
 
 Stop a running guest: 
 To stop a running VM in a clean way (as you would press the power button to start the shutdown sequence):
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        shutdown 
        vmdeb7 
        
        
        Domain 
        vmdeb7 
        is 
        being 
        shutdown 
        
        
     
    
   
  
 
 This triggers a normal,clean,shutdown on the guest:
 
 
       
       
         1 
        
       
         2 
        
       
         3 
        
       
         4 
        
        
     
 
       
        
        root 
        @deb 
        : 
        ~ 
        # 
        
        
        Broadcast 
        message 
        from 
        root 
        @deb 
         
        (Wed 
        Aug 
        27 
        09 
        :09 
        :16 
        2014 
        ) 
        : 
        
        
        Power 
        button 
        pressed 
        
        
        The 
        system 
        is 
        going 
        down 
         
        for 
        system 
        halt 
        NOW 
        ! 
        
        |  
     
    
   
  
 
 To force stop a running VM that doesn’t want to shutdown in a clean way:
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        destroy 
        vmdeb7 
        
        
        Domain 
        vmdeb7 
        destroyed 
        
        
     
    
   
  
 
 Start aguest: 
 
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
         
        start 
        vmdeb7 
        
        
        Domain 
        vmdeb7 
        started 
        
        
     
    
   
  
 
 Delete aguest: 
 First we need to make sure that the guest is stopped before it can be deleted. In case you don’t want the virtual disk image anymore either,you’ll have to delete it manually after undefining the guest.
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        destroy 
        vmcen6 
        
        
        Domain 
        vmcen6 
        destroyed 
        
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        undefine 
        vmcen6 
        
        
        Domain 
        vmcen6 
        has 
        been 
        undefined 
        
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        rm 
         -f 
         
        /var 
        /lib 
        /libvirt 
        /images 
        /vmcen6 
        .img 
        
        
     
    
   
  
 
 After removing a disk-image,it’s a good thing to refresh the storage pool of KVM:
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
        pool 
        -refresh 
        default 
        
        
        Pool 
        default 
        refreshed 
        
        
     
    
   
  
 
 Automatically let a guest start when the host starts 
 When rebooting your host,you probably want some or all the guests that are defined on thathost to start at the same time. By default,the guest are not automatically started.
 
 
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        autostart 
        vmdeb7 
        
        
        Domain 
        vmdeb7 
        marked 
        as 
        autostarted 
        
        
        [jensd 
        @kvmhost 
         
        ~ 
        ] 
        $ 
        sudo 
        virsh 
         
        --connect 
        qemu 
        : 
        / 
        / 
        /system 
        dominfo 
        vmdeb7 
        |grep 
        Auto 
        
        
        Autostart 
        : 
        enable 
        
        
     
    
   
  
 
 
 
 Part 3: Using KVM with the virt-manager GUI
 
 Starting the GUI
 
 Managing KVM with the CLI is not so difficult and it can be very handy to script certain day-to-day tasks. Sometimes,you just need to keep an overview and require a little more user-friendliness. For that,you can use virt-manager,which is a graphical interface for libvirt and is mainly built for KVM. When you want to manage your guest with virt-manager,you can either do it on the host itself,by starting an X-server locally or use X11 forwarding on a headless server (more informationhere).
 
 Make sure that you have enough permissions to use virt-manager and simply execute virt-manager from the command line:
 
 
       
       
         1 
        
        
     
 
       
        
        [root 
        @kvmhost 
         
        ~ 
        ] 
        # 
        virt 
        -manager 
        
        |  
     
    
   
  
 
 If all goes well,you should be presented with the virt-manager GUI:
 
 Basic actions 
 From the initial start-up screen,you can immediately see a list of configured guests on this host and take actions on them like: Run,Pause,Shutdown,Reboot,Force off,…
 
 When selecting a guest,you can also click on Open to display the console as we did earlier using VNC:
 
 Advanced actions 
 Other possibilities using the virt-manager interface:
 
 Connect to another host-system to manage the VM’s running there,using File -> Add connection (like using the –connect on the CLI)
 
 Migrate a VM to another KVM-host: right click on the VM and choose Migrate…
 
 Clone a VM to the same or another KVM-host: right click on the VM and choose Clone…
 
 As you can see,the virt-manager interface is not very complicated and most of the basic tasks don’t need any explanation.
 
 After completing all of the above steps,basic installation and using KVM shouldn’t have any secrets anymore for you. The next thing to do is experiment and test a little more with KVM and hopefully start to use it in your production environment.
 
 
 
 url---http://jensd.be/207/linux/install-and-use-centos-7-as-kvm-virtualization-host
                        (编辑:莱芜站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!