背景

背景

(CentOS 7、Ceph Incunabulus,所有内容均已修补至最新)

背景

我有一个工作的融合 Ceph/qemu/kvm 集群,并启用了 cephx 进行身份验证。我正在尝试使用它来存储 qemu/kvm 虚拟机的块设备 - 这不是一个不常见的配置。我想在 ceph 中为虚拟磁盘设置一个池,定义该池并在 libvirt 中对其进行身份验证,然后使用该池创建虚拟机。所有教程和示例似乎都显示直接在每个磁盘文件上设置 cephx 身份验证。到目前为止,我开始明白为什么了!

问题

当我尝试以下操作时,qemu-kvm 似乎通过了配置为file=rbd:vmlive/testguest-vda:auth_supported=none.这应该是auth_supported=cephx,但由于某种原因它没有发生!

我可以根据需要将所有身份验证放入池中,还是必须将身份验证部分放入每个虚拟磁盘的 XML 中?如果我能做到这一点,我下面的错误在哪里?

我现在正在尝试什么

语境

我有两个节点:test1 和 test2。每个都有两个 OSD,每个也是一个监视器(是的,我知道使用偶数个监视器运行是一个坏主意)。每个都安装了 libvirt,因此是 qemu/kvm。我在 test1 上以 root 身份运行以下命令。 UUID 已更改,您会看到我没有在下面显示任何键!

创建 Ceph 池和 client.kvm 用户

SENSIBLE_PGS=512 # Calculate as OSDs * 100 / number of replicas, rounded up to next power of 2
ID=kvm
POOL=vmlive
ceph osd pool create $POOL $SENSIBLE_PGS $SENSIBLE_PGS
KEY=`ceph auth get-or-create client.$ID | grep -v '^\[' | awk '{print $3}'`
ceph auth caps client.$ID mon "allow r" osd "allow rwx pool=$POOL"

创建一个包含 Ceph 用户密钥的 libvirt 密钥

SECRET_DEFINITION_FILE=~/secret-$ID.xml
SECRET_UUID=12345678-1234-1234-1234-123456789abc
cat > $SECRET_DEFINITION_FILE << EOF
<secret ephemeral='no' private='no'>
  <uuid>$SECRET_UUID</uuid>
  <usage type='ceph'>
    <name>ceph client.$ID key</name>
  </usage>
</secret>
EOF
virsh secret-define --file $SECRET_DEFINITION_FILE
rm -f $SECRET_DEFINITION_FILE
virsh secret-set-value "$SECRET_UUID" "$KEY"

创建libvirt存储池,尝试使用cephx认证

POOL_DEFINITION_FILE=~/pool-$POOL.xml
cat > $POOL_DEFINITION_FILE << EOF
<pool type="rbd">
  <name>$POOL</name>
  <source>
    <name>$POOL</name>
    <host name="test1" port="6789" />
    <host name="test2" port="6789" />
    <auth username='$ID' type='ceph'>
      <secret uuid='$SECRET_UUID'/>
    </auth>
  </source>
</pool>
EOF
virsh pool-define $POOL_DEFINITION_FILE
rm -f $POOL_DEFINITION_FILE
virsh pool-autostart $POOL
virsh pool-start $POOL

使用 virt-install 创建来宾

NAME=testguest
DEV=vda
SIZE=8G
IMAGE=CentOS-7-x86_64-Minimal-1503-01.iso
VCPUS=1
RAM=512
MACLAST_HEX=10
IPLAST_DECIMAL=16

FILE=$NAME-$DEV
qemu-img create -f rbd rbd:$POOL/$FILE $SIZE
sudo virsh net-update default add-last ip-dhcp-host \
  --xml "<host mac='52:54:00:00:00:$MACLAST_HEX' ip='192.168.122.$IPLAST_DECIMAL' name='$NAME'/>" --live --config
sudo virt-install \
  --connect qemu:///system \
  --virt-type kvm \
  --name $NAME \
  --ram $RAM \
  --vcpus=$VCPUS \
  --disk vol=$POOL/$FILE \
  --location /var/lib/libvirt/images/$IMAGE \
  --vnc \
  --noautoconsole \
  --os-type linux \
  --os-variant rhel7 \
  --network=bridge:virbr0,model=virtio,mac=52:54:00:00:00:$MACLAST_HEX \
  --autostart

结果

WARNING  vmlive/testguest-vda may not be accessible by the hypervisor. You will need to grant the 'qemu' user search permissions for the following directories: ['vmlive', '']

Starting install...
Retrieving file .treeinfo...
Retrieving file vmlinuz...
Retrieving file initrd.img...
ERROR    internal error: process exited while connecting to monitor: 2016-01-06T15:16:54.639890Z qemu-kvm: -drive file=rbd:vmlive/testguest-vda:auth_supported=none:mon_host=test1\:6789,if=none,id=drive-virtio-disk0,format=raw: error connecting
2016-01-06T15:16:54.640574Z qemu-kvm: -drive file=rbd:vmlive/testguest-vda:auth_supported=none:mon_host=test1\:6789,if=none,id=drive-virtio-disk0,format=raw: could not open disk image rbd:vmlive/testguest-vda:auth_supported=none:mon_host=test1\:6789: Could not open 'rbd:vmlive/testguest-vda:auth_supported=none:mon_host=test1\:6789': Operation not supported

Domain installation does not appear to have been successful.

如果您已经读到这里...谢谢,恭喜您,并感谢您收到的所有帮助!

更新1

更新:这似乎是 virt-install 部分(但不完全)解析池的问题。如果我使用--print-xml为磁盘生成的部分 XML 为:

<disk type="network" device="disk">
  <driver name="qemu"/>
  <source protocol="rbd" name="vmlive/testguest-vda">
    <host name="test1" port="6789"/>
  </source>
  <target dev="vda" bus="virtio"/>
</disk>

...其中包括大部分池定义,但是不是auth

我会继续调查。

答案1

正如你所说,XML不包含auth节,这就是域安装失败的原因,但你可以添加auth部分手动
编辑/usr/share/virt-manager/virtinst/guest.py如下

#vim /usr/share/virt-manager/virtinst/guest.py
import re
...
#define the auth 
auth_secret = '''
      <auth username='libvirt'>
        <secret type='ceph' uuid='e63e4b32-280e-4b00-982a-9d3xxxxxxx'/>
      </auth>
'''
ceph_monitors = '''
        <host name='172.16.200.104' port='6789'/>
        <host name='172.16.200.105' port='6789'/>
        <host name='172.16.200.106' port='6789'/>
'''

#change func: _build_xml 
    def _build_xml(self, is_initial):
        log_label = is_initial and "install" or "continue"
        disk_boot = not is_initial

        start_xml = self._get_install_xml(install=True, disk_boot=disk_boot)
        final_xml = self._get_install_xml(install=False)

#add------------start
        rgx_qemu = re.compile('(<driver name="qemu"[^>]*?>)')
        rgx_auth = re.compile('(?<=<source protocol="rbd" name=")([^>]*?">).*?(?= *?</source>)',re.S)

        start_xml = rgx_qemu.sub('\\1' + auth_secret,start_xml)
        start_xml = rgx_auth.sub('\\1' + ceph_monitors,start_xml)

        final_xml = rgx_qemu.sub('\\1' + auth_secret,final_xml)
        final_xml = rgx_auth.sub('\\1' + ceph_monitors,final_xml)
#add------------end

        logging.debug("Generated %s XML: %s",
                      log_label,
                      (start_xml and ("\n" + start_xml) or "None required"))
        logging.debug("Generated boot XML: \n%s", final_xml)

        return start_xml, final_xml

然后,virt-install再次运行

sudo virt-install \
  --connect qemu:///system \
  --virt-type kvm \
  --name $NAME \
  --ram $RAM \
  --vcpus=$VCPUS \
  --disk vol=$POOL/$FILE \
  --location /var/lib/libvirt/images/$IMAGE \
  --vnc \
  --noautoconsole \
  --os-type linux \
  --os-variant rhel7 \
  --network=bridge:virbr0,model=virtio,mac=52:54:00:00:00:$MACLAST_HEX \
  --autostart

更多信息http://www.isjian.com/ceph/virt-install-create-vm-use-rbd-pool/

答案2

目前的方法(从 virt-inst 3.1 开始仍然被破坏):

  1. 与任何其他方法一样设置机密
  2. 使用 rbd 创建存储池。 XML 看起来像这样:
 <pool type='rbd'>
 <name>volumes</name> <!-- libvirt pool name -->
 <source>
  <host name='10.1.1.1' port='6789'/>
  <host name='10.1.1.2' port='6789'/>
  <host name='10.1.1.3' port='6789'/>
  <name>volumes</name><!-- ceph pool name -->
  <auth type='ceph' username='hypervisor'>
    <secret uuid='ff831b04-65a6-4b1b-ae53-9318e65158e6'/>
  </auth>
</source>
</pool>

为了简单起见,可能希望保持 libvirt 和 ceph 池名称相同

  1. 添加它(如果你想自动化它,复制 XML/etc/libvirt/storage并在目录中建立链接也可以,只需要重新启动 libvirtd)./autostart
virsh pool-define volumes.xml 
virsh pool-start volumes
  1. 从那时起,您只需传递vol=poolname/volumename--disk的选项即可virt-install指定它。

答案3

目前这是 virt-manager 中的一个已知错误 - 请参阅电子邮件线程https://www.redhat.com/archives/virt-tools-list/2016-January/msg00007.html

与此同时,我会寻找另一种方法来解决这个问题。

相关内容