设为首页 收藏本站
查看: 1423|回复: 0

[经验分享] OpenStack: Perform Consistent Snapshots With Qemu Guest Agent

[复制链接]

尚未签到

发表于 2015-10-11 08:33:44 | 显示全部楼层 |阅读模式
  http://www.sebastien-han.fr/blog/2015/02/09/openstack-perform-consistent-snapshots-with-qemu-guest-agent/
  

A while back, I wrote
an article about taking consistent snapshots of your virtual machines in your OpenStack environment. However this method was really intrusive since
it required to be inside the virtual machine and to manually summon a filesystem freeze. In this article, I will use a different approach to achieve the same goal without the need to be inside
the virtual machine.
The only requirement is to have a virtual machine running the qemu-guest-agent.






OpenStack Nova and QEMU guest agent



The QEMU guest support landed in Nova during the
Havana cycle, so basically we are two release ahead. This functionality is based on Glance properties.

But how does that work?

The principle is quite easy. A virtual machine boots with a new virtio device attached pointing to unix socket on the hypervisor. Inside the virtual machine this socket will appear as a new character device, commonly under /dev/virtio-ports/.

A picture is always better:

DSC0000.png






Configure the QEMU agent



For Ubuntu, you need to apply this fix since AppArmor will not allow the creation of the socket:



[color=#586E75!important]1
[color=#586E75!important]2
[color=#586E75!important]3
[color=#586E75!important]4


[color=#268BD2!important]$ sudo [color=#859900!important]echo [color=#2AA198!important]"/var/lib/libvirt/qemu/*.sock rw," | sudo tee -a /etc/apparmor.d/abstractions/libvirt-qemu
[color=#268BD2!important]$ sudo service libvirt-bin restart
[color=#268BD2!important]$ sudo service nova-compute restart
[color=#268BD2!important]$ sudo service apparmor reload



Configure your Glance image:



[color=#586E75!important]1
[color=#586E75!important]2
[color=#586E75!important]3
[color=#586E75!important]4
[color=#586E75!important]5
[color=#586E75!important]6
[color=#586E75!important]7


[color=#268BD2!important]$ glance image-create --name cirros [color=#DC322F!important]\
--disk-format raw [color=#DC322F!important]\
--container-format bare [color=#DC322F!important]\
--file cirros-0.3.3-x86_64-disk.raw [color=#DC322F!important]\
--is-public True [color=#DC322F!important]\
--property [color=#268BD2!important]hw_qemu_guest_agent=yes [color=#DC322F!important]\
--progress



Boot your virtual machine:



[color=#586E75!important]1


[color=#268BD2!important]$ nova boot ...



Verify that the agent is in the virtual machine:



[color=#586E75!important]1
[color=#586E75!important]2


ubuntu@agent:~[color=#268BD2!important]$ file /dev/virtio-ports/org.qemu.guest_agent.0
/dev/virtio-ports/org.qemu.guest_agent.0: symbolic link to `../vport2p1[color=#DC322F!important]'



Install the QEMU agent inside your VM:



[color=#586E75!important]1
[color=#586E75!important]2
[color=#586E75!important]3
[color=#586E75!important]4
[color=#586E75!important]5
[color=#586E75!important]6
[color=#586E75!important]7
[color=#586E75!important]8
[color=#586E75!important]9
[color=#586E75!important]10


ubuntu@agent:~[color=#268BD2!important]$ sudo apt-get install -y qemu-guest-agent
ubuntu@agent:~[color=#268BD2!important]$ sudo mkdir /var/log/qemu-agent
ubuntu@agent:~[color=#268BD2!important]$ sudo tee /etc/default/qemu-guest-agent > /dev/null [color=#2AA198!important]<<EOF
[color=#2AA198!important]DAEMON_ARGS=&quot;--logfile /var/log/qemu-agent/org.qemu.guest_agent.0.log --fsfreeze-hook --verbose&quot;
[color=#2AA198!important]EOF
ubuntu@agent:~[color=#268BD2!important]$ sudo service qemu-guest-agent restart
* Restarting QEMU Guest Agent qemu-qa
   ...done
ubuntu@agent:~[color=#268BD2!important]$ sudo ls /var/log/qemu-agent/
org.qemu.guest_agent.0.log



Now go back on the hypervisor and check that the socket file is present (it must here since we have the character device inside the virtual machine):



[color=#586E75!important]1
[color=#586E75!important]2
[color=#586E75!important]3
[color=#586E75!important]4
[color=#586E75!important]5


[color=#268BD2!important]$ sudo bash -c  [color=#2AA198!important]&quot;ls /var/lib/libvirt/qemu/*.sock&quot;
/var/lib/libvirt/qemu/capabilities.monitor.sock  /var/lib/libvirt/qemu/org.qemu.guest_agent.0.instance-00000007.sock

[color=#268BD2!important]$ sudo file /var/lib/libvirt/qemu/org.qemu.guest_agent.0.instance-00000007.sock
/var/lib/libvirt/qemu/org.qemu.guest_agent.0.instance-00000007.sock: socket



Test if the QEMU agent responds:



[color=#586E75!important]1
[color=#586E75!important]2


[color=#268BD2!important]$ sudo virsh qemu-agent-command instance-00000007 [color=#2AA198!important]'{&quot;execute&quot;:&quot;guest-ping&quot;}'
{[color=#2AA198!important]&quot;return&quot;:{}}








Iced that guy!



DSC0001.png

Full reference of the image available here :D.





Setup the fsfreeze hook mechanism, on Red Hat systems the file already exists:



[color=#586E75!important]1
[color=#586E75!important]2


ubuntu@agent:~[color=#268BD2!important]$ sudo wget -O /etc/qemu/fsfreeze-hook https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-guest-agent/fsfreeze-hook
ubuntu@agent:~[color=#268BD2!important]$ sudo chmod &#43;x /etc/qemu/fsfreeze-hook



Configure a basic hook, it will be executed either during the freeze or thaw operation:



[color=#586E75!important]1
[color=#586E75!important]2
[color=#586E75!important]3
[color=#586E75!important]4
[color=#586E75!important]5
[color=#586E75!important]6
[color=#586E75!important]7
[color=#586E75!important]8
[color=#586E75!important]9
[color=#586E75!important]10
[color=#586E75!important]11
[color=#586E75!important]12
[color=#586E75!important]13
[color=#586E75!important]14
[color=#586E75!important]15
[color=#586E75!important]16
[color=#586E75!important]17


ubuntu@agent:~[color=#268BD2!important]$ sudo mkdir /etc/qemu/fsfreeze-hook.d
ubuntu@agent:~[color=#268BD2!important]$ sudo tee > /etc/qemu/fsfreeze-hook.d/foo.sh > /dev/null [color=#2AA198!important]<<EOF
[color=#2AA198!important]#!/bin/bash

[color=#2AA198!important]case &quot;$1&quot; in
[color=#2AA198!important]    freeze)
[color=#2AA198!important]        echo &quot;I'm frozen&quot; > /tmp/freeze
[color=#2AA198!important]        ;;
[color=#2AA198!important]    thaw)
[color=#2AA198!important]        echo &quot;I'm thawed&quot; >> /tmp/freeze
[color=#2AA198!important]        ;;
[color=#2AA198!important]    *)
[color=#2AA198!important]        exit 1
[color=#2AA198!important]        ;;
[color=#2AA198!important]esac
[color=#2AA198!important]EOF
ubuntu@agent:~[color=#268BD2!important]$ sudo chmod &#43;x /etc/qemu/fsfreeze-hook.d/foo.sh



Now let’s freeze ad thaw the filesystem:



[color=#586E75!important]1
[color=#586E75!important]2


[color=#268BD2!important]$ sudo virsh qemu-agent-command instance-00000008 [color=#2AA198!important]'{&quot;execute&quot;:&quot;guest-fsfreeze-freeze&quot;}'
[color=#268BD2!important]$ sudo virsh qemu-agent-command instance-00000008 [color=#2AA198!important]'{&quot;execute&quot;:&quot;guest-fsfreeze-thaw&quot;}'



Did the hook work as expected? Yes!



[color=#586E75!important]1
[color=#586E75!important]2
[color=#586E75!important]3


ubuntu@agent:~[color=#268BD2!important]$ sudo cat /tmp/freeze
I[color=#2AA198!important]'m frozen
[color=#2AA198!important]I'm thawed



For a more concrete example, have a look
at this work for a database from Chromium.






OpenStack Nova and Snapshots



Several patches have been submitted to quiesce the filesystem prior to run the snapshot. The initial work to support fs-freeze while performing a snapshot of an instance was introduced in Juno with a spec.
However the commit only got merged in
December…
This will be available in Kilo. Another effort to support this feature while booting from a volume is currently under review.

The original blueprint can be found here.
Ultimately this option will be available via a Glance property:



[color=#586E75!important]1


[color=#268BD2!important]$ glance image-update 53bd9dbe-23db-412b-81d5-9743aabdfeb5 --property [color=#268BD2!important]os_require_quiesce=yes



When this option will be set and the virtual machine running the QEMU guest agent, when a user will snapshot an instance, the filesystem will get frozen and thawed after the operation.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-125264-1-1.html 上篇帖子: Fuel 30 分钟快速安装OpenStack(转) 下篇帖子: openstack+xen,使用glance命令镜像的下载和上传
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表