• KVM虚拟化技术


    一、kvm虚拟化介绍及资料链接

      KVM详解:http://www.cnblogs.com/sammyliu/p/4543110.html

      KVM视频教程:https://pan.baidu.com/s/11NNqa-fjXCWQRqszZvaqVQ

      Libvirt官网:https://libvirt.org/downloads.html

    virinstall 安装

    #!/bin/bash
    virt-install 
        --name=ubuntu
        --ram=512 
        --vcpus=1,maxvcpus=4 
        --os-type=linux 
        --cdrom=/home/ubuntu-16.04.2-server-amd64.iso 
        --disk path=/var/lib/libvirt/images/xp64_1.img,size=8,format=qcow2 
        --network bridge=virbr0 
        --vnc 
        --vncport=5950 
        --vnclisten=0.0.0.0,keymap=en_us 
        --autostart

    二、Linux  KVM 安装

    1、ubuntu安装KVM:

      1)查看CPU是否支持KVM

    egrep "(svm|vmx)" /proc/cpuinfo
    

      2)KVM相关依赖包

    sudo apt-get install qemu-kvm
    sudo apt-get install qemu
    sudo apt-get install virt-manager
    sudo apt-get install virt-viewer 
    sudo apt-get install libvirt-bin 
    sudo apt-get install bridge-utils
    View Code

    2、centos 安装KVM:

      1)查看CPU是否支持KVM

    egrep "(svm|vmx)" /proc/cpuinfo

      2)KVM相关依赖包

    yum install qemu-kvm qemu-img libvirt  virt-install libvirt-python virt-manager python-virtinst libvirt-client virt-viewer  -y

    三、KVM核心基础功能

      1、CPU配置

        1.1 环境安装及命令

         1.1.1 numactl 管理工具安装    

    ubuntu 安装
    下载安装包:https://launchpad.net/ubuntu/+source/numactl
    
    centos 安装
    yum install numactl -y
    View Code

         1.1.2 numactl 命令介绍

    numactl - 用于控制 进程与共享存储的 NUMA 技术机制
    
    语法:
    
    numactl [--interleave nodes] [--preferred node] [--membind nodes]
      [--cpunodebind nodes] [--physcpubind cpus] [--localalloc] [--] {arguments ...}
    numactl --show
    numactl --hardware
    numactl [--huge] [--offset offset] [--shmmode shmmode] [--length length] [--strict]
    [--shmid id] --shm shmkeyfile | --file tmpfsfile
    [--touch] [--dump] [--dump-nodes] memory policy
    
    主要参数:
    
    --interleave=nodes, -i nodes
    
    
              这个选项用于设定内存的交织分配模式。 也就是说系统在为多个节点分配内存空间的时候,将会以轮询分发的方式被分配给这多个节点.
              如果在当前众多的交织分配内存节点中的目标节点无法正确的分配内存空间的话,内存空间将会由其他的节点来分配。
    
    
    --membind=nodes, -m nodes
               选项 '--membind' 仅用来从节点中分配内存空间所用。 如果在这些节点中无法分配出所请求的空间大小的话该分配操作将会失败.
               上述命令中指定需要分配空间的 nodes 的方式可以遵照上述 N,N,N , N-N ,N 这种方式来指定.
    
    
    --cpunodebind=nodes, -N nodes
              上述命令仅用于施加在运行与 cpu 上的进程。这个命令用于显示 cpu 的个数,cpu 数目信息同样记录在系统中的存放处理器领域信息的 /proc/cpuinfo 文件夹下,
              或者是按照关联的中央处理器信息 在当前的中央处理器集中所存放.          
       
    --localalloc , -l
               这个命令选项通常是为当前的节点分配内存的
    
    
    --preferred=node
                   该命令由于指定优先分配内存空间的节点,如果无法将空间分配给该节点的话,应该分配给该节点上的空间将会被分发到其他的节点上               
                    该命令选项后面仅接收一个单独的节点标号.  相关的表示方式也可以使用.
    
    
    --show,-s
               该命令用于显示 NUMA 机制作用在当前运行的那些进程上
    
    
    --hardware , -H
    
    
                该命令用于显示当前系统中有多少个可用的节点.
    
    
    --huge
                当创建一个基于大内存页面的系统级的共享内存段的时候,使用 --huge 这个选项。
               --huge 选项仅在 --shmid 或是 --shm 命令的后面使用才有效.
    --offset
               该参数选项用于指定共享内存段中的位移量的偏移。 默认的情况下偏移量是 0 。 有效的偏移量单位是 m (用于表示 MB)
                g (用于表示 GB) , k (用于表示 KB ), 其他没有指定的被认为是以字节为单位.
    
    
    --strict 
                 这个参数选项 当施加了 NUMA 调度机制的共享内存段区域的页面被施加了另一个机制而导致错误的时候,
                使用 --strict 选项将会把错误信息显示出来. 默认情况是不使用该选项的。
    
    
    --shmmode shmmode
              该选项仅在 --shmid 或是 --shm 之前使用才会生效。 当创建一个共享内存段的时候,通过整型数值来指定
               共享内存的共享的模式类型.
    
    
    --length length
                Apply policy to length range in the shared memory segment or make the segment length long Default is to use the remaining
               length Required when a shared memory segment is created and specifies the length of the new segment then .
                Valid units are m ( for MB ) , g( for GB) , k ( for KB) , otherwise it specifies bytes.
    
    
    --shmid id
                 通过ID 号码来创建或使用一个共享内存段。
                   (如果共享内存段已经存在,那么通过 shmid 来指定下面要使用某个 ID 的共享内存段 ;  如果该 ID 对应的共享内存段并不存在的话,那么就创建一个)
    
    
    --shm shmkeyfile
                 通过存放在 shmkeyfile(共享内存-键文件)中的 ID 号码来创建或者是使用一个共享内存段。
                 访问 shmkeyfile 文件的进程是通过 fork(3 arguments) 方法来实现的.
    
    
    --file tmpfsfile
             将 numa 机制施加于文件上面, 这个文件属于 tmpfs或者是 hugetlbfs 这种特殊的文件系统
    
    
    --touch
             通过将 numa 机制施加于刚刚页面上来实现内存的早期 numa 化。
             默认情况下是不使用该选项,如果存在映射或是访问页面的应用的话,将会使用该早期实行 NUMA 机制的这种方法.
    
    
    --dump
             该选项用于废除将已经 numa 化的特定区域上的 NUMA性质.
    
    
    (--dump ) 选项后,有效指定 node 的书写方式
             all  用于将所有的节点上的 NUMA 特性移除
             number  通过指定 node 后接的数值来废除该数字对应的 node
             number1(number2)  node number1(node number2)上的 NUMA 特性将会被移除
             number1-number2    node number1 -- node number2 区间上的所有存在的 node 的 NUMA 特性将会被移除
             !nodes                除了 nodes 所指定的节点以外的所有节点上的 NUMA 特性全都会被移除
    View Code

        2.1 Vcpu 虚拟 介绍

          详细介绍链接地址:https://blog.csdn.net/tengyft/article/details/45619457

        

        

     

      2、内存配置

        1)EPT与VPID   (减少虚拟机内存与宿主机内存切换,提高内存访问性能)

        关键字说明:

         EPT:页表技术   虚拟机物理地址与宿主机物理地址转换技术 ;EPT加入CPU固件中 自动转化                             // KVM   虚拟机内存转换过程如:客户机虚拟内存空间---->客户机虚拟物理地址-------->宿主机内存物理地址

         VPID:虚拟处理器标识 ;  硬件上对TLB资源管理优化,通过硬件为每个TLB增加一个标识,用于不同虚拟处理器地址空间,从而区分hypervisor和不同处理器的TLB。

        监测 EPT与 VPID 是否启动:   

    cat /sys/module/kvm_intel/parameters/ept
    cat /sys/module/kvm_intel/parameters/vpid

        2)大页技术

          

        

      3)存储配置

      4)网络配置

      5)图像显示

    四、KVM高级功能详解

      1)半虚拟化驱动

      2)设备直接分配

      3)热插拔

      4)动态迁移

      5)嵌套虚拟化

      6)KSM技术

      7)KVM安全

      8)QEMU监控器

      9)qemu-kvm 命令行参数

      10)virsh 命令行参数

        virsh 参数详解:

    virsh [options]... [<command_string>]
    virsh [options]... <command> [args...]
    
    options:
    -c | --connect=URI hypervisor connection URI                                                //连接远程的主机
    -d | --debug=NUM debug level [0-4]                                                        
    -e | --escape <char> set escape sequence for console
    -h | --help this help                                                              //帮助
    -k | --keepalive-interval=NUM
    keepalive interval in seconds, 0 for disable
    -K | --keepalive-count=NUM
    number of possible missed keepalive messages
    -l | --log=FILE output logging to file
    -q | --quiet quiet mode
    -r | --readonly connect readonly
    -t | --timing print timing information
    -v short version
    -V long version
    --version[=TYPE] version, TYPE is short or long (default short)
    commands (non interactive mode)
    
    Domain Management (help keyword 'domain')
        attach-device                  attach device from an XML file                            //XML附加设备                          
        attach-disk                    attach disk device                                   //附加磁盘设备                              
        attach-interface               attach network interface                               //附加网络接口                 
        autostart                      autostart a domain                                   //自动启动域                                       
        blkdeviotune                   Set or query a block device I/O tuning parameters.                //设置或查询块设备I/O调谐参数
        blkiotune                      Get or set blkio parameters                             //获取或设置BLKIO参数
        blockcommit                    Start a block commit operation.                           //启动块提交操作。
        blockcopy                      Start a block copy operation.                            //启动块复制操作。
        blockjob                       Manage active block operations                           //管理活动块操作
        blockpull                      Populate a disk from its backing image.
        blockresize                    Resize block device of domain.
        change-media                   Change media of CD or floppy drive
        console                        connect to the guest console
        cpu-baseline                   compute baseline CPU
        cpu-compare                    compare host CPU with a CPU described by an XML file
        cpu-stats                      show domain cpu statistics
        create                         create a domain from an XML file
        define                         define (but don't start) a domain from an XML file
        desc                           show or set domain's description or title
        destroy                        destroy (stop) a domain
        detach-device                  detach device from an XML file
        detach-disk                    detach disk device
        detach-interface               detach network interface
        domdisplay                     domain display connection URI
        domfsfreeze                    Freeze domain's mounted filesystems.
        domfsthaw                      Thaw domain's mounted filesystems.
        domfsinfo                      Get information of domain's mounted filesystems.
        domfstrim                      Invoke fstrim on domain's mounted filesystems.
        domhostname                    print the domain's hostname
        domid                          convert a domain name or UUID to domain id
        domif-setlink                  set link state of a virtual interface
        domiftune                      get/set parameters of a virtual interface
        domjobabort                    abort active domain job
        domjobinfo                     domain job information
        domname                        convert a domain id or UUID to domain name
        domrename                      rename a domain
        dompmsuspend                   suspend a domain gracefully using power management functions
        dompmwakeup                    wakeup a domain from pmsuspended state
        domuuid                        convert a domain name or id to domain UUID
        domxml-from-native             Convert native config to domain XML
        domxml-to-native               Convert domain XML to native config
        dump                           dump the core of a domain to a file for analysis
        dumpxml                        domain information in XML
        edit                           edit XML configuration for a domain
        event                          Domain Events
        inject-nmi                     Inject NMI to the guest
        iothreadinfo                   view domain IOThreads
        iothreadpin                    control domain IOThread affinity
        iothreadadd                    add an IOThread to the guest domain
        iothreaddel                    delete an IOThread from the guest domain
        send-key                       Send keycodes to the guest
        send-process-signal            Send signals to processes
        lxc-enter-namespace            LXC Guest Enter Namespace
        managedsave                    managed save of a domain state
        managedsave-remove             Remove managed save of a domain
        managedsave-edit               edit XML for a domain's managed save state file
        managedsave-dumpxml            Domain information of managed save state file in XML
        managedsave-define             redefine the XML for a domain's managed save state file
        memtune                        Get or set memory parameters
        perf                           Get or set perf event
        metadata                       show or set domain's custom XML metadata
        migrate                        migrate domain to another host
        migrate-setmaxdowntime         set maximum tolerable downtime
        migrate-getmaxdowntime         get maximum tolerable downtime
        migrate-compcache              get/set compression cache size
        migrate-setspeed               Set the maximum migration bandwidth
        migrate-getspeed               Get the maximum migration bandwidth
        migrate-postcopy               Switch running migration from pre-copy to post-copy
        numatune                       Get or set numa parameters
        qemu-attach                    QEMU Attach
        qemu-monitor-command           QEMU Monitor Command
        qemu-monitor-event             QEMU Monitor Events
        qemu-agent-command             QEMU Guest Agent Command
        reboot                         reboot a domain
        reset                          reset a domain
        restore                        restore a domain from a saved state in a file
        resume                         resume a domain
        save                           save a domain state to a file
        save-image-define              redefine the XML for a domain's saved state file
        save-image-dumpxml             saved state domain information in XML
        save-image-edit                edit XML for a domain's saved state file
        schedinfo                      show/set scheduler parameters
        screenshot                     take a screenshot of a current domain console and store it into a file
        set-lifecycle-action           change lifecycle actions
        set-user-password              set the user password inside the domain
        setmaxmem                      change maximum memory limit
        setmem                         change memory allocation
        setvcpus                       change number of virtual CPUs
        shutdown                       gracefully shutdown a domain
        start                          start a (previously defined) inactive domain
        suspend                        suspend a domain
        ttyconsole                     tty console
        undefine                       undefine a domain
        update-device                  update device from an XML file
        vcpucount                      domain vcpu counts
        vcpuinfo                       detailed domain vcpu information
        vcpupin                        control or query domain vcpu affinity
        emulatorpin                    control or query domain emulator affinity
        vncdisplay                     vnc display
        guestvcpus                     query or modify state of vcpu in the guest (via agent)
        setvcpu                        attach/detach vcpu or groups of threads
        domblkthreshold                set the threshold for block-threshold event for a given block device or it's backing chain element
    
     Domain Monitoring (help keyword 'monitor')
        domblkerror                    Show errors on block devices
        domblkinfo                     domain block device size information
        domblklist                     list all domain blocks
        domblkstat                     get device block stats for a domain
        domcontrol                     domain control interface state
        domif-getlink                  get link state of a virtual interface
        domifaddr                      Get network interfaces' addresses for a running domain
        domiflist                      list all domain virtual interfaces
        domifstat                      get network interface stats for a domain
        dominfo                        domain information
        dommemstat                     get memory statistics for a domain
        domstate                       domain state
        domstats                       get statistics about one or multiple domains
        domtime                        domain time
        list                           list domains
    
     Host and Hypervisor (help keyword 'host')
        allocpages                     Manipulate pages pool size
        capabilities                   capabilities
        cpu-models                     CPU models
        domcapabilities                domain capabilities
        freecell                       NUMA free memory
        freepages                      NUMA free pages
        hostname                       print the hypervisor hostname
        maxvcpus                       connection vcpu maximum
        node-memory-tune               Get or set node memory parameters
        nodecpumap                     node cpu map
        nodecpustats                   Prints cpu stats of the node.
        nodeinfo                       node information
        nodememstats                   Prints memory stats of the node.
        nodesuspend                    suspend the host node for a given time duration
        sysinfo                        print the hypervisor sysinfo
        uri                            print the hypervisor canonical URI
        version                        show version
    
     Interface (help keyword 'interface')
        iface-begin                    create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
        iface-bridge                   create a bridge device and attach an existing network device to it
        iface-commit                   commit changes made since iface-begin and free restore point
        iface-define                   define an inactive persistent physical host interface or modify an existing persistent one from an XML file
        iface-destroy                  destroy a physical host interface (disable it / "if-down")
        iface-dumpxml                  interface information in XML
        iface-edit                     edit XML configuration for a physical host interface
        iface-list                     list physical host interfaces
        iface-mac                      convert an interface name to interface MAC address
        iface-name                     convert an interface MAC address to interface name
        iface-rollback                 rollback to previous saved configuration created via iface-begin
        iface-start                    start a physical host interface (enable it / "if-up")
        iface-unbridge                 undefine a bridge device after detaching its slave device
        iface-undefine                 undefine a physical host interface (remove it from configuration)
    
     Network Filter (help keyword 'filter')
        nwfilter-define                define or update a network filter from an XML file
        nwfilter-dumpxml               network filter information in XML
        nwfilter-edit                  edit XML configuration for a network filter
        nwfilter-list                  list network filters
        nwfilter-undefine              undefine a network filter
    
     Networking (help keyword 'network')
        net-autostart                  autostart a network
        net-create                     create a network from an XML file
        net-define                     define an inactive persistent virtual network or modify an existing persistent one from an XML file
        net-destroy                    destroy (stop) a network
        net-dhcp-leases                print lease info for a given network
        net-dumpxml                    network information in XML
        net-edit                       edit XML configuration for a network
        net-event                      Network Events
        net-info                       network information
        net-list                       list networks
        net-name                       convert a network UUID to network name
        net-start                      start a (previously defined) inactive network
        net-undefine                   undefine a persistent network
        net-update                     update parts of an existing network's configuration
        net-uuid                       convert a network name to network UUID
    
     Node Device (help keyword 'nodedev')
        nodedev-create                 create a device defined by an XML file on the node
        nodedev-destroy                destroy (stop) a device on the node
        nodedev-detach                 detach node device from its device driver
        nodedev-dumpxml                node device details in XML
        nodedev-list                   enumerate devices on this host
        nodedev-reattach               reattach node device to its device driver
        nodedev-reset                  reset node device
        nodedev-event                  Node Device Events
    
     Secret (help keyword 'secret')
        secret-define                  define or modify a secret from an XML file
        secret-dumpxml                 secret attributes in XML
        secret-event                   Secret Events
        secret-get-value               Output a secret value
        secret-list                    list secrets
        secret-set-value               set a secret value
        secret-undefine                undefine a secret
    
     Snapshot (help keyword 'snapshot')
        snapshot-create                Create a snapshot from XML
        snapshot-create-as             Create a snapshot from a set of args
        snapshot-current               Get or set the current snapshot
        snapshot-delete                Delete a domain snapshot
        snapshot-dumpxml               Dump XML for a domain snapshot
        snapshot-edit                  edit XML for a snapshot
        snapshot-info                  snapshot information
        snapshot-list                  List snapshots for a domain
        snapshot-parent                Get the name of the parent of a snapshot
        snapshot-revert                Revert a domain to a snapshot
    
     Storage Pool (help keyword 'pool')
        find-storage-pool-sources-as   find potential storage pool sources
        find-storage-pool-sources      discover potential storage pool sources
        pool-autostart                 autostart a pool
        pool-build                     build a pool
        pool-create-as                 create a pool from a set of args
        pool-create                    create a pool from an XML file
        pool-define-as                 define a pool from a set of args
        pool-define                    define an inactive persistent storage pool or modify an existing persistent one from an XML file
        pool-delete                    delete a pool
        pool-destroy                   destroy (stop) a pool
        pool-dumpxml                   pool information in XML
        pool-edit                      edit XML configuration for a storage pool
        pool-info                      storage pool information
        pool-list                      list pools
        pool-name                      convert a pool UUID to pool name
        pool-refresh                   refresh a pool
        pool-start                     start a (previously defined) inactive pool
        pool-undefine                  undefine an inactive pool
        pool-uuid                      convert a pool name to pool UUID
        pool-event                     Storage Pool Events
    
     Storage Volume (help keyword 'volume')
        vol-clone                      clone a volume.
        vol-create-as                  create a volume from a set of args
        vol-create                     create a vol from an XML file
        vol-create-from                create a vol, using another volume as input
        vol-delete                     delete a vol
        vol-download                   download volume contents to a file
        vol-dumpxml                    vol information in XML
        vol-info                       storage vol information
        vol-key                        returns the volume key for a given volume name or path
        vol-list                       list vols
        vol-name                       returns the volume name for a given volume key or path
        vol-path                       returns the volume path for a given volume name or key
        vol-pool                       returns the storage pool for a given volume key or path
        vol-resize                     resize a vol
        vol-upload                     upload file contents to a volume
        vol-wipe                       wipe a vol
    
     Virsh itself (help keyword 'virsh')
        cd                             change the current directory
        echo                           echo arguments
        exit                           quit this interactive terminal
        help                           print help
        pwd                            print the current directory
        quit                           quit this interactive terminal
        connect                        (re)connect to hypervisor
    View Code

     五、KVM管理工具

      1)libvirt

      2)virsh

      3)virt-manager

      4)virt-viewer、virt-install、virt-top

    六。KVM性能测试

      1)CPU性能测试

      2)内存性能测试

      3)网络性能测试、

      4)磁盘 I/O性能测试

      

     

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    暂到这里明天继续

  • 相关阅读:
    Code First 迁移更新数据库
    vs2013常用快捷键
    Uploadify v3.2.1 参数说明
    中文datepicker控件
    C#去掉HTML标记
    扩展HtmlHelper类实现Mvc4分页
    MVC4实现批量更新数据
    MVC4.0实现批量删除
    通知的多线程问题 iOS
    写一个 setter 方法用于完成 @property (nonatomic, retain) NSString *name,
  • 原文地址:https://www.cnblogs.com/jiejunwang/p/8689046.html
Copyright © 2020-2023  润新知