Ceph实战(使用ceph存储提供的镜像作为硬盘)

时间:2024-03-15 13:31:29

Ceph实战:

安装KVM虚拟机,使用ceph存储提供的镜像作为硬盘

  1. 创建名为vm1-image的镜像,大小10GB

[[email protected]~]# rbd create vm1-image --size 10G --image-feature layering

[[email protected]~]# rbd info vm1-image

[[email protected]~]# qemu-img info rbd:rbd/vm1-image

  1. 物理主机作为客户端,安装软件包,拷贝配置文件

[[email protected]]# yum install -y ceph-common

[[email protected]]# scp /etc/ceph/ceph.c* 192.168.4.254:/etc/ceph/

  1. 正常创建一台KVM虚拟机,取名为myrhel7。向导结束之后,将其强制关机即可。

  2. 导出myrhel7虚拟的声明文件,将虚拟删掉。

[[email protected]]# virsh dumpxml myrhel7 > /tmp/myrhel7.xml

  1. 虚拟机使用CEPH存储,需要认证。方式是虚拟先生成secret,再将secretCEPH账户映射

  1. 编写账户信息文件

[[email protected]]# vim /tmp/secret.xml

<secretephemeral='no' private='no'>

<usagetype='ceph'>

<name>client.adminsecret</name>

</usage>

</secret>

  1. 生成secret

[[email protected]]# virsh secret-define --file /tmp/secret.xml

[[email protected]]# virsh secret-list 查看secret


  1. 将虚拟机软件的secretceph的管理员用户关联

  1. 查看管理员的**

[[email protected]]# cat /etc/ceph/ceph.client.admin.keyring

  1. 关联secretceph的管理员

[[email protected]]# virsh secret-set-value --secret60a71cb8-1c4f-4b14-9100-80c6355098eb --base64AQBFS0hbHuSGIBAAUErs4XIBDWEAXGHLEpcrOw==

  1. 修改虚拟机的配置文件/tmp/myrhel7.xml,把管理员信息写到该文件中,并指定虚拟机磁盘使用ceph的镜像

[[email protected]]# vim /tmp/myrhel7.xml

<disktype='network'device='disk'>

<drivername='qemu' type='raw'/>

<authusername='admin'>

<secrettype='ceph' uuid='60a71cb8-1c4f-4b14-9100-80c6355098eb'/>

</auth>

<sourceprotocol='rbd' name='rbd/vm1-image'>

<hostname='192.168.4.1' port='6789'/>

</source>

<targetdev='vda' bus='virtio'/>

<addresstype='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>

</disk>

  1. 利用xml文件生成虚拟机

[[email protected]]# virsh define /tmp/myrhel7.xml

9、启动虚拟机时,不能直接安装,需要在虚拟机设置中连接光盘文件,并且设置启动选项,将光盘设置为第一启动介质。


Ceph实战(使用ceph存储提供的镜像作为硬盘)

Ceph实战(使用ceph存储提供的镜像作为硬盘)

注意:安装完成强制关掉虚拟机,然后调整引导选项(让它先加载磁盘),然后启动虚拟机就OK。

Ceph实战(使用ceph存储提供的镜像作为硬盘)