虚拟化管理控制台:Hypervisor;有些Hypervisor可以直接运行在计算机的裸硬件上,如KVM、IBM z/VM、VMware ESX Server等;另一类是通过宿主操作系统实现的,如VMware Workstation,Virtual Server等,红帽企业版5中使用的XEN虚拟化技术的Hypervisor是一种混合型的管理控制台,它可以直接运行在硬件上,但是需要相关的驱动支持。

域:在Hypervisor运行的虚拟机也称为域,也称为客户机(Guest),而管理这些客户机的平台通常称为管理域,它是操作系统的一部分。在XEN的虚拟化中,这个管理域都是第一个启动的,由于其ID编号始终为0,所以也称这个管理域为Domain0

客户机管理通过三种标识符进行区分:域名,域名ID,UUID号

红帽虚拟化硬件要求:Inel系列的CPU需要vmx的指令集,AMD系列的CPU需要支持svm命令集,查询方式:[root@szm repodata]# grep "vmx|svm" /proc/cpuinfo

 

 

 

 

 

第一步:安装虚拟化组件:[root@szm repodata]# yum groupinstall "Virtualization"

 

 

第二步:修改启动内核[root@szm ~]# cat /etc/sysconfig/kernel 

 

# UPDATEDEFAULT specifies if new-kernel-pkg should make

# new kernels the default

UPDATEDEFAULT=yes

 

# DEFAULTKERNEL specifies the default kernel package type

DEFAULTKERNEL=kernel--------------修改为:kernel-xen

 

第三步:修改grub.conf配置文件:[root@szm ~]# cat /boot/grub/grub.conf 

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE:  You have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version ro root=/dev/mapper/vg_szm-lv_root

#          initrd /initrd-[generic-]version.img

#boot=/dev/sda

default=0

timeout=5

splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

password --dm5 $1$.Ze.11$6IW7iPiuL6N/.UzD9IQwc/

title CentOS (2.6.32-358.0.1.el6.i686)

root (hd0,0)

kernel /vmlinuz-2.6.32-358.0.1.el6.i686 ro root=/dev/mapper/vg_szm-lv_root rd_LVM_LV=vg_szm/lv_root rd_LVM_LV=vg_szm/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto--修改为xen.gz-2.6.18-164.el
        module /vmlinuz-2.6.18-164.el5xen ro root=/dev/GLSvg/GLSroot rhgb quiet
        module /initrd-2.6.18.el5xen.img

initrd /initramfs-2.6.32-358.0.1.el6.i686.img

title CentOS (2.6.32-279.22.1.el6.i686)

root (hd0,0)

kernel /vmlinuz-2.6.32-279.22.1.el6.i686 ro root=/dev/mapper/vg_szm-lv_root rd_LVM_LV=vg_szm/lv_root rd_LVM_LV=vg_szm/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto

initrd /initramfs-2.6.32-279.22.1.el6.i686.img

title CentOS (2.6.32-279.19.1.el6.i686)

root (hd0,0)

kernel /vmlinuz-2.6.32-279.19.1.el6.i686 ro root=/dev/mapper/vg_szm-lv_root rd_LVM_LV=vg_szm/lv_root rd_LVM_LV=vg_szm/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=zh_CN.UTF-8 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto

initrd /initramfs-2.6.32-279.19.1.el6.i686.img

title centos (2.6.32-71.el6.i686)

root (hd0,0)

kernel /vmlinuz-2.6.32-71.el6.i686 ro root=/dev/mapper/vg_szm-lv_root rd_LVM_LV=vg_szm/lv_root rd_LVM_LV=vg_szm/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=zh_CN.UTF-8 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet

initrd /initramfs-2.6.32-71.el6.i686.img

第四步作用Virtual Machine Manager(VMM)管理虚拟机:

 

 半虚拟化仅支持从网络安装Linux操作系统,完全虚拟化技术可以选择从本地介质安装或使用PXE方式安装操作系统,而且还可以选择安装不同的操作系统,如Windows;

使用简单文件作为虚拟机的存储默认存放位置为:/var/lib/xen/p_w_picpaths

[root@szm repodata]# virt-install --help
Usage: virt-install --name NAME --ram RAM STORAGE INSTALL [options]
 
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  --connect=URI         Connect to hypervisor with libvirt URI
 
  General Options:
    -n NAME, --name=NAME
                        Name of the guest instance---虚拟机名称
    -r MEMORY, --ram=MEMORY
                        Memory to allocate for guest instance in megabytes---分配内存
    --vcpus=VCPUS       Number of vcpus to configure for your guest. Ex:
                        --vcpus 5
                        --vcpus 5,maxcpus=10
                        --vcpus sockets=2,cores=4,threads=2
    --cpuset=CPUSET     Set which physical CPUs domain can use.
    --cpu=CPU           CPU model and features. Ex: --cpu coreduo,+x2apic
    --description=DESCRIPTION
                        Human readable description of the VM to store in the
                        generated XML.
    --security=SECURITY
                        Set domain security driver configuration.
    --numatune=NUMATUNE
                        Tune NUMA policy for the domain process.
 
  Installation Method Options:-----安装方法
    -c CDROM, --cdrom=CDROM
                        CD-ROM installation media
    -l LOCATION, --location=LOCATION
                        Installation source (eg, nfs:host:/path,
                        http://host/path, ftp://host/path)
    --pxe               Boot from the network using the PXE protocol
    --import            Build guest around an existing disk p_w_picpath
    --init=INIT         Path to init binary for container guest. Ex:
                        --init /path/to/app (to contain an application)
                        --init /sbin/init (for a full OS container)
    --livecd            Treat the CD-ROM media as a Live CD
    -x EXTRA, --extra-args=EXTRA
                        Additional arguments to pass to the install kernel
                        booted from --location
    --initrd-inject=INITRD_INJECTIONS
                        Add given file to root of initrd from --location
    --os-type=DISTRO_TYPE
                        The OS type being installed, e.g. 'linux', 'unix',
                        'windows'
    --os-variant=DISTRO_VARIANT
                        The OS variant being installed guests, e.g. 'fedora6',
                        'rhel5', 'solaris10', 'win2k'
    --boot=BOOTOPTS     Optionally configure post-install boot order, menu,
                        permanent kernel boot, etc.
 
  Storage Configuration:----存储参数(分区与文件)
    --disk=DISKOPTS     Specify storage with various options. Ex.
                        --disk path=/my/existing/disk
                        --disk path=/my/new/disk,size=5 (in gigabytes)
                        --disk vol=poolname:volname,device=cdrom,bus=scsi,...
    --nodisks           Don't set up any disks for the guest.
    --filesystem=FILESYSTEMS
                        Pass host directory to the guest. Ex:
                        --filesystem /my/source/dir,/dir/in/guest
                        --filesystem template_name,/,type=template
 
  Networking Configuration:--网络配置
    -w NETWORK, --network=NETWORK---NAT方式主网
                        Configure a guest network interface. Ex:
                        --network bridge=mybr0
                        --network network=my_libvirt_virtual_net
                        --network network=mynet,model=virtio,mac=00:11...
 -b BRIDGE   --bridge=BRIDGE-----设置网络连接为桥接
    --nonetworks        Don't create network interfaces for the guest.
 
  Graphics Configuration :-----图形支持
    --graphics=GRAPHICS
                        Configure guest display settings. Ex:
                        --graphics vnc
                        --graphics spice,port=5901,tlsport=5902
                        --graphics none
                        --graphics vnc,password=foobar,port=5910,keymap=ja
    --noautoconsole     Don't automatically try to connect to the guest
                        console
 
 
  Device Options:
    --serial=SERIALS    Configure a guest serial device
    --parallel=PARALLELS
                        Configure a guest parallel device
    --channel=CHANNELS  Configure a guest communication channel
    --console=CONSOLES  Configure a text console connection between the guest
                        and host
    --host-device=HOSTDEVS
                        Configure physical host devices attached to the guest
    --soundhw=SOUNDHW   Configure guest sound device emulation
    --watchdog=WATCHDOG
                        Configure a guest watchdog device
    --video=VIDEO       Configure guest video hardware.
    --smartcard=SMARTCARD
                        Configure a guest smartcard device. Ex:
                        --smartcard mode=passthrough
 
  Virtualization Platform Options:
    -v, --hvm           This guest should be a fully virtualized guest--完全虚拟化
    -p, --paravirt      This guest should be a paravirtualized guest---半虚拟化
    --container         This guest should be a container guest
    --virt-type=HV_TYPE
                        Hypervisor name to use (kvm, qemu, xen, ...)
    --arch=ARCH         The CPU architecture to simulate---设置虚拟机CPU架构
    --machine=MACHINE   The machine type to emulate
    --noapic            Disables APIC for fully virtualized guest (overrides
                        value in os-type/os-variant db)
    --noacpi            Disables ACPI for fully virtualized guest (overrides
                        value in os-type/os-variant db)
    -u UUID, --uuid=UUID
                        UUID for the guest.
 
  Miscellaneous Options:
    --autostart         Have domain autostart on host boot up.
    --print-xml         Print the generated domain XML rather than define the
                        guest.
    --print-step=XMLSTEP
                        Print XML of a specific install step (1, 2, 3, all)
                        rather than define the guest.
    --noreboot          Don't boot guest after completing install.
    --wait=WAIT         Time to wait (in minutes)
    --dry-run           Run through install process, but do not create devices
                        or define the guest.
    --force             Forces 'yes' for any applicable prompts, terminates
                        for all others
    -q, --quiet         Suppress non-error output
    --prompt            Request user input for ambiguous situations or
                        required options.----使用交互方式安装虚拟机
    -d, --debug         Print debugging information
 
[root@szm repodata]# virt-install --prompt
 
 
虚拟机的管理:
[root@szm ~]# virsh --help
 
virsh [options]... [<command_string>]
virsh [options]... <command> [args...]
 
  options:
    -c | --connect=URI      hypervisor connection URI
    -r | --readonly         connect readonly
    -d | --debug=NUM        debug level [0-4]
    -h | --help             this help
    -q | --quiet            quiet mode
    -t | --timing           print timing information
    -l | --log=FILE         output logging to file
    -v                      short version
    -V                      long version
         --version[=TYPE]   version, TYPE is short or long (default short)
    -e | --escape <char>    set escape sequence for console
 
  commands (non interactive mode):
 
 Domain Management (help keyword 'domain')
    attach-device                  attach device from an XML file
    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.
    blkiotune                      Get or set blkio parameters
    blockcommit                    Start a block commit operation.
    blockcopy                      Start a block copy operation.
    blockjob                       Manage active block operations
    blockpull                      Populate a disk from its backing p_w_picpath.
    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
    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
    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
    inject-nmi                     Inject NMI to the guest
    send-key                       Send keycodes to the guest
    managedsave                    managed save of a domain state
    managedsave-remove             Remove managed save of a domain
    maxvcpus                       connection vcpu maximum
    memtune                        Get or set memory parameters
    migrate                        migrate domain to another host
    migrate-setmaxdowntime         set maximum tolerable downtime
    migrate-setspeed               Set the maximum migration bandwidth
    migrate-getspeed               Get the maximum migration bandwidth
    numatune                       Get or set numa parameters
    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-p_w_picpath-define              redefine the XML for a domain's saved state file
    save-p_w_picpath-dumpxml             saved state domain information in XML
    save-p_w_picpath-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
    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
 
 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
    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
    list                           list domains
 
 Host and Hypervisor (help keyword 'host')
    capabilities                   capabilities
    connect                        (re)connect to hypervisor
    freecell                       NUMA free memory
    hostname                       print the hypervisor hostname
    node-memory-tune               Get or set node memory parameters
    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
    qemu-attach                    QEMU Attach
    qemu-monitor-command           QEMU Monitor Command
    qemu-agent-command             QEMU Guest Agent Command
    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 (but don't start) a physical host interface 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 (but don't start) a network from an XML file
    net-destroy                    destroy (stop) a network
    net-dumpxml                    network information in XML
    net-edit                       edit XML configuration for a network
    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 an inactive 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
 
 Secret (help keyword 'secret')
    secret-define                  define or modify a secret from an XML file
    secret-dumpxml                 secret attributes in XML
    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 (but don't start) a pool 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
 
 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 a volume 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 a file into 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
 
 
  (specify help <group> for details about the commands in the group)
 
  (specify help <command> for details about the command)
 
[root@szm repodata]# virsh 
Welcome to virsh, the virtualization interactive terminal.
 
Type:  'help' for help with commands
       'quit' to quit
 
virsh # help