一、两台机器均做nfs
# 迁移机器 [root@localhost ~]# yum install nfs-utils [root@localhost ~]# systemctl start nfs-server [root@localhost ~]# systemctl enable nfs-server [root@localhost ~]# vim /etc/exports /opt/kvm/template/ 192.168.75.*(rw,sync,no_root_squash) [root@localhost ~]# exportfs -r # 迁移到的服务器 [root@localhost ~]# yum install nfs-utils [root@localhost ~]# mount 192.168.75.128:/opt/kvm/template/ /opt/kvm/template/ [root@localhost ~]# vim /etc/fstab # 开机启动 192.168.75.128:/opt/kvm/template/ /opt/kvm/template/ nfs defaults 0 0 [root@localhost ~]# hostnamectl set-hostname hello.com # 修改主机名,不修改报错如下 # error: internal error: hostname on destination resolved to localhost, but migration requires an FQDN # 迁移机器 [root@localhost ~]# vim /etc/hosts 192.168.75.129 hello.com [root@localhost ~]# virsh migrate --live --verbose --unsafe --persistent template qemu+ssh://hello.com/system
二、冷迁移
冷迁移是在虚拟机关机状态下进行的迁移。在进行冷迁移时,虚拟机的状态被保存到磁盘文件中,然后将虚拟机的磁盘镜像和配置文件从源主机复制到目标主机。迁移完成后,虚拟机会在目标主机上重新启动。
操作步骤:
关闭源主机上的虚拟机。
复制虚拟机的磁盘镜像和配置文件到目标主机。
在目标主机上创建虚拟机,并指向复制过来的磁盘镜像和配置文件。
启动虚拟机。
冷迁移适用于不需要中断虚拟机服务的情况,但需要在迁移过程中短暂停止虚拟机。
# 冷迁移需要手动拷贝镜像文件到迁移后的服务器 virsh migrate --offline --verbose --unsafe --persistent template qemu+ssh://hello.com/system