小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

KVM虛擬機的創(chuàng)建、管理與遷移

 浸心閣 2015-05-08

KVM虛擬機管理

一、環(huán)境
role         hostname    ip                  OS
kvm_server   target      192.168.32.40/24    rhel6.0_x64
vir_guest1   node4       192.168.32.34/24    rhel5.5_i386
vir_guest2   node5       192.168.32.35/24    rhel5.5_i386
manager      manager     192.168.32.33/24    rhel5.5_i386
ESXi         ESXi        192.168.2.251/24    ESXi 3.5
二、安裝kvm
[root@target ~]# yum install -y qemu-kvm.x86_64 qemu-kvm-tools.x86_64  #安裝kvm內(nèi)核
[root@target ~]# yum install libvirt.x86_64 libvirt-cim.x86_64 libvirt-client.x86_64 libvirt-java.noarch  libvirt-python.x86_64 #安裝virt管理工具
[root@target ~]# modprobe kvm         #加載kvm內(nèi)核
[root@target ~]# modprobe kvm-intel   #intel cpu加載kvm-intel內(nèi)核,要支持全虛擬化,必須開啟;要求cpu支持,通過bios可設(shè)置。
[root@target ~]# modprobe kvm-amd     #amd cpu加載kvm-intel


[root@target ~]# modprobe -ls | grep kvm   #查看內(nèi)核是否開啟
kernel/arch/x86/kvm/kvm.ko
kernel/arch/x86/kvm/kvm-intel.ko
kernel/arch/x86/kvm/kvm-amd.ko
[root@target ~]# modprobe -ls | grep kvm-intel
kernel/arch/x86/kvm/kvm-intel.ko

三、安裝guest虛擬機

1、直接通過virt-manager安裝、管理虛擬機(略)

2、通過命令行安裝guest虛擬機
[root@target ~]# yum install virt-viewer   #開啟圖形控制臺安裝虛擬客戶機需要,
[root@target ~]# virt-install \            #安裝選項可用virt-install --help查看
--name node4 \           #虛擬機名
--ram=1024 \             #分配內(nèi)存大小,MB
--arch=x86_64 \          #模擬的CPU 構(gòu)架
--vcpus=1 \              #配置虛擬機的vcpu 數(shù)目
--check-cpu \            #檢查確定vcpu是否超過物理 CPU數(shù)目,如果超過則發(fā)出警告。
--os-type=linux \        #要安裝的操作系統(tǒng)類型,例如:'linux'、'unix'、'windows'
--os-variant=rhel5 \     #操作系統(tǒng)版本,如:'Fedora6', 'rhel5', 'solaris10', 'win2k'
--disk path=/virhost/node7.img,device=disk,bus=virtio,size=20,sparse=true \   #虛擬機所用磁盤或鏡像文件,size大小G
--bridge=br0 \           #指定網(wǎng)絡(luò),采用透明網(wǎng)橋
--noautoconsole \        #不自動開啟控制臺
--pxe                    #網(wǎng)絡(luò)安裝

四、利用virsh對虛擬機管理
1、開關(guān)機
[root@target ~]# virsh start node4      #開機
[root@target ~]# virsh create /etc/libvirt/qemu/node4.xml #直接通過主機配置文檔啟動主機
[root@target ~]# virsh shutdown node4   #關(guān)機
[root@target ~]# virsh destroy node4    #強制關(guān)閉電源
[root@target ~]# virsh list --all       #查看虛擬機狀態(tài)         
 Id 名稱               狀態(tài)
----------------------------------
 18 node4                running
  - node5                關(guān)閉
  - win8                 關(guān)閉


2、添加刪除虛擬機
[root@target ~]# virsh define /etc/libvirt/qemu/node5.xml   #根據(jù)主機配置文檔添加虛擬機
[root@target ~]# virsh list --all        #node5已經(jīng)添加
 Id 名稱               狀態(tài)
----------------------------------
 18 node4                running
  - node5                關(guān)閉
  - win8                 關(guān)閉
 
[root@target ~]# virsh undefine node5     #移除虛擬機
[root@target ~]# ls /etc/libvirt/qemu
networks  node4.xml  win8.xml
[root@target ~]# virsh list --all         #node5已經(jīng)被移除
 Id 名稱               狀態(tài)
----------------------------------
 18 node4                running
  - win8                 關(guān)閉


3、遠程管理虛擬機(qemu+ssh連接)
[root@target ~]# yum install virt-viewer
[root@target ~]# export DISPLAY=192.168.40.18:0.0
[root@target ~]# virt-viewer -c qemu///system node4                          #本地管理虛擬機,system:獲取system權(quán)限,注意qemu后是三個/
[root@manager ~]# virt-viewer -c qemu+ssh://root@192.168.32.40/system node4  #遠程linux通過virt-viewer+ssh管理虛擬機
Xlib:  extension "RANDR" missing on display "192.168.40.18:0.0".
root@192.168.32.40's password:
root@192.168.32.40's password:
#會彈出virt-viwer的gtk管理界面


4、使用已存在的虛擬機配置文檔安裝新的虛擬機
[root@target ~]# qemu-img create -f qcow2 /virhost/kvm_node/node6.img 20G
#為新建虛擬機生產(chǎn)磁盤鏡像文件


[root@target ~]# virsh list
 Id 名稱               狀態(tài)
----------------------------------
 18 node4                running


[root@target ~]# virsh dumpxml node4 >/etc/libvirt/qemu/node6.xml
#導出虛擬機node6的硬件配置信息為/etc/libvirt/qemu/node6.xml


[root@target ~]# vim /etc/libvirt/qemu/node6.xml 
<domain type='kvm' id='20'>    #修改node6的id號
  <name>node6</name>           #虛擬機node6的name
  <uuid>4b7e91eb-6521-c2c6-cc64-c1ba72707fc7</uuid>  #uuid必須修改,否則會和node4的沖突
  <memory>524288</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64' machine='rhel5.4.0'>hvm</type>
    <boot dev='network'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/virhost/node4.img'/>         #指定新虛擬機的硬盤文件
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <mac address='54:52:00:69:d5:c7'/>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
    </interface>
    <interface type='bridge'>
      <mac address='54:52:00:69:d5:d7'/>
      <source bridge='br0'/>
      <target dev='vnet1'/>
      <model type='virtio'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/4'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5900' autoport='yes' keymap='en-us'/>
  </devices>
</domain>

[root@target ~]# virsh define /etc/libvirt/qemu/node6.xml
#使用虛擬描述文檔建立虛擬機,可用virsh edit node6修改node6的配置文件

[root@target ~]# virsh start node6
#啟動虛擬機

5 為虛擬機開啟vnc
[root@target ~]# virsh edit node4     #編輯node4的配置文件;不建議直接通過vim node4.xml修改。
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
   #port='-1' autoport='yes':port自動分配,監(jiān)聽回環(huán)網(wǎng)絡(luò)(virt-manager管理需要listen='127.0.0.1'),無密碼
改為
<graphics type='vnc' port='5904' autoport='no' listen='0.0.0.0' keymap='en-us' passwd='xiaobai'/>
   #固定vnc管理端口5904,不自動分配,vnc密碼xiaobai,監(jiān)聽所有網(wǎng)絡(luò)

2. 遠程vnc訪問地址:192.168.32.40:5904

linux

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多