如何使用 librbd 连接到 Ceph 集群 (Python)

How to connect to Ceph cluster using librbd (Python)

我正在尝试使用 librbd 和 Python 连接到我的 Ceph 集群。如果我尝试 Ceph 文档中的 this 示例,我会收到一条错误消息 "error connecting to the cluster: error code 95"。请参阅下面的代码示例。

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.    
>>> import rados
>>> cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
>>> cluster.connect()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rados.pyx", line 785, in rados.Rados.connect (/build/ceph-10.2.6/src/build/rados.c:10073)
rados.Error: error connecting to the cluster: error code 95

Ceph 集群正常运行 (HEALTH_OK)。这个错误代码是什么意思,我该如何解决?

好的,我找到了解决办法。问题是 /etc/ceph/ 中的 ceph 客户端密钥 ceph.client.admin.keyring 只能由 sudo 用户读取。根据您的情况,您可以:

  • 更新文件权限

  • 运行 进程为 sudo

  • 或者将当前用户添加到sudoers

我通过更新文件权限解决了这个问题。这允许客户端节点上的所有用户 运行 ceph 命令:

$ sudo chmod 644 /etc/ceph/ceph.client.admin.keyring