1 案例1:块存储应用案例
1.1 问题
延续Day04的实验内容,演示块存储在KVM虚拟化中的应用案例,实现以下功能:
Ceph创建块存储镜像
客户端安装部署ceph软件
客户端部署虚拟机
客户端创建secret
设置虚拟机配置文件,调用ceph存储
- 1
- 2
- 3
- 4
- 5
1.2 方案
使用Ceph存储创建镜像。
KVM虚拟机调用Ceph镜像作为虚拟机的磁盘。
1.3 步骤
实现此案例需要按照如下步骤进行。
1)创建磁盘镜像。
[root@node1 ~]# rbd create vm1-image --image-feature layering --size 10G
[root@node1 ~]# rbd create vm2-image --image-feature layering --size 10G
[root@node1 ~]# rbd list
[root@node1 ~]# rbd info vm1-image
[root@node1 ~]# qemu-img info rbd:rbd/vm1-image
image: rbd:rbd/vm1-image
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: unavailable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
2)Ceph认证账户。
Ceph默认开启用户认证,客户端需要账户才可以访问,
默认账户名称为client.admin,key是账户的密钥,
可以使用ceph auth添加新账户(案例我们使用默认账户)。
[root@node1 ~]# cat /etc/ceph/ceph.conf //配置文件
[global]
mon_initial_members = node1, node2, node3
mon_host = 192.168.2.10,192.168.2.20,192.168.2.30
auth_cluster_required = cephx //开启认证
auth_service_required = cephx //开启认证
auth_client_required = cephx //开启认证
[root@node1 ~]# cat /etc/ceph/ceph.client.admin.keyring //账户文件
[client.admin]
key = AQBTsdRapUxBKRAANXtteNUyoEmQHveb75bISg==
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
3)部署客户端环境。
注意:这里使用真实机当客户端!!!
客户端需要安装ceph-common软件包,拷贝配置文件(否则不知道集群在哪),
拷贝连接密钥(否则无连接权限)。
[root@room9pc01 ~]# yum -y install ceph-common
[root@room9pc01 ~]# scp 192.168.4.11:/etc/ceph/ceph.conf /etc/ceph/
[root@room9pc01 ~]# scp 192.168.4.11:/etc/ceph/ceph.client.admin.keyring \
/etc/ceph/
- 1
- 2
- 3
- 4
4)创建KVM虚拟机。
使用virt-manager创建2台普通的KVM虚拟机。
5)配置libvirt secret。
编写账户信息文件(真实机操作)
[root@room9pc01 ~]# vim secret.xml //新建临时文件,内容如下
<secret ephemeral='no' private='no'>
<usage type='ceph'>
<name>client.admin secret</name>
</usage>
</secret>
#使用XML配置文件创建secret
[root@room9pc01 ~]# virsh secret-define --file secret.xml
733f0fd1-e3d6-4c25-a69f-6681fc19802b
//随机的UUID,这个UUID对应的有账户信息
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
编写账户信息文件(真实机操作)
[root@room9pc01 ~]# ceph auth get-key client.admin
//获取client.admin的key,或者直接查看密钥文件
[root@room9pc01 ~]# cat /etc/ceph/ceph.client.admin.keyring
- 1
- 2
- 3
设置secret,添加账户的密钥
[root@room9pc01] virsh secret-set-value \
--secret 733f0fd1-e3d6-4c25-a69f-6681fc19802b \
--base64 AQBTsdRapUxBKRAANXtteNUyoEmQHveb75bISg
//这里secret后面是之前创建的secret的UUID
//base64后面是client.admin账户的密码
//现在secret中既有账户信息又有密钥信息
- 1
- 2
- 3
- 4
- 5
- 6
6)虚拟机的XML配置文件。
每个虚拟机都会有一个XML配置文件,包括:
虚拟机的名称、内存、CPU、磁盘、网卡等信息
[root@room9pc01 ~]# vim /etc/libvirt/qemu/vm1.xml
//修改前内容如下
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vm1.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
不推荐直接使用vim修改配置文件,推荐使用virsh edit修改配置文件,效果如下:
[root@room9pc01] virsh edit vm1 //vm1为虚拟机名称
<disk type='network' device='disk'>
<driver name='qemu' type='raw’/>
<auth username='admin'>
<secret type='ceph' uuid='733f0fd1-e3d6-4c25-a69f-6681fc19802b’/>
</auth>
<source protocol='rbd' name='rbd/vm1'> <host name='192.168.4.11' port='6789’/> </source>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
<img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{"mod":"popu_379"}" target="_blank">解启超</a></span>
</div>
<div class="text"><span>发布了355 篇原创文章</span> · <span>获赞 52</span> · <span>访问量 3万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm attented bt-button personal-watch" data-report-click="{"mod":"popu_379"}">已关注</a>
</div>
</div>
</div>
</article>