zpjx 发表于 2015-10-10 10:38:36

kvm虚拟机在线迁移

  本次实验环境示意图如下图图1所示:


  图意解析:
  三台VMware虚拟机Original、Destination和Nfsrv,把Original上的KVM虚拟机在线迁移到
  Destination上
  
  注:离线迁移本次实验不做演示,只演示基于NFS共享的在线迁移
  
  一NFS服务端配置
  1.设置共享目录
  # hostname
  Nfsrv.wjcyf.com
  # cat /etc/exports
  /share 192.168.78.0/24(rw,sync,no_root_squash)
  #
  2.启动nfs服务
  # chkconfig nfs on ;/etc/init.d/nfs start
  Starting NFS services:                                       [ OK]
  Starting NFS mountd:                                       
  Starting NFS daemon:                                       
  Starting RPC idmapd:                                       
  # showmount -e localhost
  Export list for localhost:
  /share 192.168.78.0/24
  #
  
  二:Original端配置
  1.设置主机名,IP,hosts文件等
  # hostname
  Original.wjcyf.com
  # cat /etc/hosts |grep ^[^$]
  127.0.0.1Originallocalhost.localdomain localhost4 localhost4.localdomain4
  ::1      Originallocalhost.localdomain localhost6 localhost6.localdomain6
  192.168.78.11   Original.wjcyf.com
  192.168.78.12   Destination.wjcyf.com
  #
  2.挂载nfs共享
  # mkdir /nfs
  # mount 192.168.78.100:/share /nfs
  # cat /etc/fstab |grep nfs
  192.168.78.100:/share   /nfs                  nfs   defaults      0 0
  #
  
  3.安装KVM,设置桥接并安装虚拟机
  安装虚拟机
  # virt-install \
  > --name rhel6.5-1 \                        //虚拟机名称而不是主机名
  > --ram 1024 \
  > --vcpus 1 \
  > --network bridge=br0 \                   //桥接已设置在eth0上
  > --file /nfs/rhel6.5-1.img \
  >--file-size 5 \
  >--nonsparse \
  > --location /dev/cdrom/                   //本地安装
  
  注:具体安装步骤请参考我的这边博文,链接如下:
  http://blog.iyunv.com/wjciayf/article/details/40679289

  
  3.设置KVM虚拟机IP地址,并安装httpd服务
  # virsh console rhel6.5-1
  Connected to domain rhel6.5-1
  Escape character is ^]
  
  Red Hat Enterprise Linux Server release 6.5(Santiago)
  Kernel 2.6.32-431.el6.x86_64 on an x86_64
  
  localhost.localdomain login: root
  Password:
  Last login: Thu Oct 30 23:15:24 from192.168.78.11
  #
  # ip a |grep eth0
  2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
  inet 192.168.78.20/24 brd 192.168.78.255 scope global eth0
  # yum -y install httpd
  # cat /var/www/html/index.html
  This is web page for KVM VirtualMachine!
  # /etc/init.d/httpd start
  输入ctrl&#43;]退出控制
  
  三:Destination端配置
  1.设置主机名,IP,hosts文件(内容同Original端)
  2.挂载nfs共享(操作同Original端)
  3.安装KVM并设置好桥接(不需要安装虚拟机)
  4.设置Original和Destination无密码访问(不是必须,但是建议)
  
  四:在线迁移(在Original端操作)
  1.查看目前虚拟机状态
  # virsh list --all
  Id   Name                        State
  ----------------------------------------------------
  5    rhel6.5-1                     running
  #
  2.打开&quot;VirtualMachine Manager&quot;,依次选择“File”—“Add Connection”打开“Add Connection”对话框,填写要连接的远程Hypervisor这里是Destination.wjcyf.com,如下图所示


  3.确认无误后,点击“Connect”后就可以连接到远端的Hypervisor,如下图所示


  4.选择欲迁移的虚拟机----右击,再选择“Migrate”,如下图所示


  5.随后就会弹出“迁移虚拟机”对话框,而且会自动选择好我们所设置的远端Hypervisor主机,如下图所示


  6.确认无误后,点击“Migrate”后迁移开始,如下图所示


  在迁移的同时一直ping 192.168.78.20发现只丢了一次包后又转为正常回复了,也说明在迁移的过程中只有很短暂的时间停止对外提供服务,对用户来说感觉不到
  
  7.转移完成后,可以看到虚拟机已经运行在了Destination上了,如下图所示


  8.删除本机的虚拟机,卸载掉/nfs挂载后本机就可以关闭处理了
  # virsh list --all
  Id   Name                        State
  ----------------------------------------------------
  -    rhel6.5-1                     shut off
  
  # virsh undefine rhel6.5-1
  Domain rhel6.5-1 has been undefined
  
  # virsh list --all
  Id   Name                        State
  ----------------------------------------------------
  
  # umount /nfs
         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: kvm虚拟机在线迁移