kvm迁移

12.3. 使​用​ virsh 进​行​实​时​ KVM 迁​移​

使​用​ virsh 命​令​可​将​客​户​端​迁​移​到​另​一​台​主​机​中​。​ migrate 命​令​接​受​以​下​格​式​的​参​数​:
# virsh migrate --live GuestName DestinationURL
The GuestName parameter represents the name of the guest which you want to migrate.
The DestinationURL parameter is the URL or hostname of the destination system. The destination system must run the same version of Fedora, be using the same hypervisor and have libvirt running.
Once the command is entered you will be prompted for the root password of the destination system.
示​例​:使​用​ virsh 进​行​实​时​迁​移​
这​个​示​例​是​从​ test1.bne.redhat.com 迁​移​至​ test2.bne.redhat.com。​请​为​您​的​环​境​更​改​主​机​名​。​这​个​示​例​迁​移​了​名​为​ CentOS4test 的​虚​拟​机​。​
This example assumes you have fully configured shared storage and meet all the prerequisites (listed here: 迁​移​要​求​).
  1. 确​定​客​户​端​正​在​运​行​

    在​源​系​统​ test1.bne.redhat.com 中​确​定​ CentOS4test 正​在​运​行​:
    [root@test1 ~]# virsh list
    Id Name                 State
    ----------------------------------
     10 CentOS4                running
    
    
  2. 迁​移​客​户​端​

    执​行​以​下​命​令​实​时​将​客​户​端​迁​移​至​目​的​地​ test2.bne.redhat.com。​在​目​的​地​ URL 结​尾​添​加​ /system 告​知​ libvirt 您​需​要​完​全​访​问​权​限​。​
    # virsh migrate --live CentOS4test qemu+ssh://test2.bne.redhat.com/system
    
    Once the command is entered you will be prompted for the root password of the destination system.
  3. 等​待​

    根​据​负​载​和​客​户​端​的​大​小​,迁​移​可​能​需​要​一​些​时​间​。​ virsh 只​报​告​出​错​信​息​。​客​户​端​仍​将​在​源​主​机​中​继​续​运​行​直​至​全​部​迁​移​完​成​。​
  4. 确​定​客​户​端​已​到​达​目​的​主​机​

    在​目​的​系​统​ test2.bne.redhat.com 中​确​认​ CentOS4test 正​在​运​行​:
    [root@test2 ~]# virsh list
    Id Name                 State
    ----------------------------------
     10 CentOS4                running 
    



虚拟机之间的热迁移可以在2-3秒内将虚拟机迁移到另外一台宿主机上,而且能保证正在运行的服务不重短。

为了让虚拟机尽快迁移,应该用共享存储来存储虚拟机的img文件,可以用nfs发布

在第一个宿主机上将储存img文件的文件夹通过nfs共享出来。当然也可以将存储独立出来

  
  
  1. yum install nfs-utils 
  2. vim /etc/exports 
  3. /var/lib/libvirt/images/        192.168.0.0/24(rw,sync,no_root_squash) 
  4. /etc/init.d/rpcbind start 
  5. /etc/init.d/nfs start 

在第二台宿主机上将第一台共享出来的文件夹挂载上去

  
  
  1. mount 192.168.0.31:/var/lib/libvirt/images /var/lib/libvirt/images 

在第二台宿主机上修改一个文件,否则会出现权限的问题

  
  
  1. vim /etc/libvirt/qemu.conf  #去掉下面两句话前的注释 
  2. user = "root" 
  3. group = "root" 
  4.  
  5. /etc/init.d/libvirtd restart 

然后在第一台宿主机的虚拟机管理器中添加一个连接,选择remote tunnel over ssh选择第二台宿主机,输入密码即可连接上去

打开一个虚拟机,右键选择migrate,选择第二台宿主及,几秒中之后虚拟机就运行在第二台宿主机上了,而且没有中断过


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值