searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

基于libvirt的虚拟机迁移步骤

2023-10-27 06:24:35
46
0

1.准备环境,首先是共享存储,这里以nfs为例:

1.1 nfs server上配置/etc/exports权限,如下:

# cat /etc/exports /var/lib/libvirt/nfs 14.5.72.26(rw,sync,no_root_squash) /var/lib/libvirt/nfs 14.5.72.28(rw,sync,no_root_squash)

启动nfs服务

1.2 在两个机器上分别挂载nfs

“# mount 14.5.72.56: /var/lib/libvirt/nfs  /var/lib/libvirt/nfs/”

1.3 hosts

# cat /etc/hosts 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 14.5.72.28 test-env-nm05-compute-14e5e72e28 14.5.72.26 test-env-nm05-compute-14e5e72e26

1.4 添加ssh免密登录

分别在两个节点加入public key免密登录,因为内蒙环境不支持ssh通过输入密码方式登录,所以需要配置公钥免密访问,配置好了以后验证ssh是否成功。

2. 准备虚拟机

copy vm disk 到目录nfs目录,/var/lib/libvirt/nfs/,当前环境中网络使用nat配置,虚拟机配置yum源与host一致 , define /start vm

[root@test-env-nm05-compute-14e5e72e26 secure]# virsh list  Id   Name             State --------------------------------  1    centos7_yuping   running

3. 开始迁移,在节点1运行如下命令:

# virsh migrate centos7_yuping --live --p2p --unsafe --persistent --undefinesource qemu+ssh://14.5.72.26:10000/system

4. 在节点2上检查虚拟机状态

[root@test-env-nm05-compute-14e5e72e28 ~]# virsh list --all
Id Name State
-------------------------------------
1 centos7_yuping running

如遇虚拟机高负载情况下,让虚拟机一直有大量的脏内存存在,用上面的命令会一直卡住不能完成迁移,可以加参数--auto-converge force convergence during live migration 这个参数会降低vcpu的工作频率,让虚机内部产生的脏数据慢慢变少。以下是在压力测试下迁移的命令以及所用时间。

time virsh migrate centos7_yuping --live --p2p --unsafe --persistent --undefinesource qemu+ssh://14.5.72.28:10000/system --auto-converge real        19m53.173s user        0m0.036s sys        0m0.017s

常见问题及解决办法:

如果使用qemu+ssh迁移成功,使用qemu+tcp方式迁移报错:

[root@test-env-nm05-compute-14e5e72e38 secure]# virsh migrate test2 --live --undefinesource --persistent --unsafe --auto-converge  --p2p --tls --tls-destination 14.5.72.37 qemu+tcp://14.5.72.37/system error: operation failed: Failed to connect to remote libvirt URI qemu+tcp://14.5.72.37/system: authentication failed: authentication failed

可以用以下方式解决:

(1)修改/etc/libvirt/libvirtd.conf,添加配置 auth_tcp = "none" --否则可能出现没有权限连接远端的情况

(2)新版本6.9,需启动libvirtd-tcp.socket服务(服务状态为active且16509端被监听)

现网一般走tcp:

libvirt打开tcp监控:

vim /etc/libvirt/libvirtd.conf

listen_tcp = 1 --老版本该参数有效,新版本中无效了,被注释掉了。取而代之的是启动libvirtd-tcp.socket服务即可,启动后就会监听16509端口。

--migrateuri tcp://{MIGRATE_NET_IP} 迁移网络,如内存和磁盘数据流量

qemu+tcp://{DST_IP}/system 迁移控制信息走的网络,若不指定--migrateuri,这样数据和控制信息都走一个网络!

libvirtd-tcp服务无法启动的解决办法:可参考《libvirt服务启动配置与说明》

systemctl stop libvirtd.service 先停掉libvirtd服务

systemctl start libvirtd-tcp.socket 再启动libvirtd-tcp服务

systemctl start libvirtd.service 再启动libvirtd服务

systemctl status libvirtd-tcp.socket 检查ibvirtd-tcp.socket服务状态是否为active

netstat -anp | grep 16509 检查是否在监听16509端口

0条评论
0 / 1000
张****萍
2文章数
1粉丝数
张****萍
2 文章 | 1 粉丝
张****萍
2文章数
1粉丝数
张****萍
2 文章 | 1 粉丝
原创

基于libvirt的虚拟机迁移步骤

2023-10-27 06:24:35
46
0

1.准备环境,首先是共享存储,这里以nfs为例:

1.1 nfs server上配置/etc/exports权限,如下:

# cat /etc/exports /var/lib/libvirt/nfs 14.5.72.26(rw,sync,no_root_squash) /var/lib/libvirt/nfs 14.5.72.28(rw,sync,no_root_squash)

启动nfs服务

1.2 在两个机器上分别挂载nfs

“# mount 14.5.72.56: /var/lib/libvirt/nfs  /var/lib/libvirt/nfs/”

1.3 hosts

# cat /etc/hosts 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 14.5.72.28 test-env-nm05-compute-14e5e72e28 14.5.72.26 test-env-nm05-compute-14e5e72e26

1.4 添加ssh免密登录

分别在两个节点加入public key免密登录,因为内蒙环境不支持ssh通过输入密码方式登录,所以需要配置公钥免密访问,配置好了以后验证ssh是否成功。

2. 准备虚拟机

copy vm disk 到目录nfs目录,/var/lib/libvirt/nfs/,当前环境中网络使用nat配置,虚拟机配置yum源与host一致 , define /start vm

[root@test-env-nm05-compute-14e5e72e26 secure]# virsh list  Id   Name             State --------------------------------  1    centos7_yuping   running

3. 开始迁移,在节点1运行如下命令:

# virsh migrate centos7_yuping --live --p2p --unsafe --persistent --undefinesource qemu+ssh://14.5.72.26:10000/system

4. 在节点2上检查虚拟机状态

[root@test-env-nm05-compute-14e5e72e28 ~]# virsh list --all
Id Name State
-------------------------------------
1 centos7_yuping running

如遇虚拟机高负载情况下,让虚拟机一直有大量的脏内存存在,用上面的命令会一直卡住不能完成迁移,可以加参数--auto-converge force convergence during live migration 这个参数会降低vcpu的工作频率,让虚机内部产生的脏数据慢慢变少。以下是在压力测试下迁移的命令以及所用时间。

time virsh migrate centos7_yuping --live --p2p --unsafe --persistent --undefinesource qemu+ssh://14.5.72.28:10000/system --auto-converge real        19m53.173s user        0m0.036s sys        0m0.017s

常见问题及解决办法:

如果使用qemu+ssh迁移成功,使用qemu+tcp方式迁移报错:

[root@test-env-nm05-compute-14e5e72e38 secure]# virsh migrate test2 --live --undefinesource --persistent --unsafe --auto-converge  --p2p --tls --tls-destination 14.5.72.37 qemu+tcp://14.5.72.37/system error: operation failed: Failed to connect to remote libvirt URI qemu+tcp://14.5.72.37/system: authentication failed: authentication failed

可以用以下方式解决:

(1)修改/etc/libvirt/libvirtd.conf,添加配置 auth_tcp = "none" --否则可能出现没有权限连接远端的情况

(2)新版本6.9,需启动libvirtd-tcp.socket服务(服务状态为active且16509端被监听)

现网一般走tcp:

libvirt打开tcp监控:

vim /etc/libvirt/libvirtd.conf

listen_tcp = 1 --老版本该参数有效,新版本中无效了,被注释掉了。取而代之的是启动libvirtd-tcp.socket服务即可,启动后就会监听16509端口。

--migrateuri tcp://{MIGRATE_NET_IP} 迁移网络,如内存和磁盘数据流量

qemu+tcp://{DST_IP}/system 迁移控制信息走的网络,若不指定--migrateuri,这样数据和控制信息都走一个网络!

libvirtd-tcp服务无法启动的解决办法:可参考《libvirt服务启动配置与说明》

systemctl stop libvirtd.service 先停掉libvirtd服务

systemctl start libvirtd-tcp.socket 再启动libvirtd-tcp服务

systemctl start libvirtd.service 再启动libvirtd服务

systemctl status libvirtd-tcp.socket 检查ibvirtd-tcp.socket服务状态是否为active

netstat -anp | grep 16509 检查是否在监听16509端口

文章来自个人专栏
底层测试
2 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0