1

当尝试在名为“ceph”的通用 ceph 集群上运行 ceph-rest-api 时,它可以在 cli 中正常工作:

/bin/ceph-rest-api --cluster ceph --id admin
  * Running on http://0.0.0.0:5000/

但是,当我尝试在名为“test”的测试集群上运行它时,它会出错:

/bin/ceph-rest-api --cluster test --id test
Traceback (most recent call last):
  File "/bin/ceph-rest-api", line 59, in <module>
    rest,
  File "/usr/lib/python2.7/site-packages/ceph_rest_api.py", line 495, in generate_app
    addr, port = api_setup(app, conf, cluster, clientname, clientid, args)
  File "/usr/lib/python2.7/site-packages/ceph_rest_api.py", line 106, in api_setup
    app.ceph_cluster.connect()
  File "rados.pyx", line 785, in rados.Rados.connect (rados.c:8969)
rados.ObjectNotFound: error connecting to the cluster

我也尝试过使用变体并得到不同的错误:

/bin/ceph-rest-api --cluster test --name test
Traceback (most recent call last):
  File "/bin/ceph-rest-api", line 59, in <module>
    rest,
  File "/usr/lib/python2.7/site-packages/ceph_rest_api.py", line 495, in generate_app
    addr, port = api_setup(app, conf, cluster, clientname, clientid, args)
  File "/usr/lib/python2.7/site-packages/ceph_rest_api.py", line 104, in api_setup
    app.ceph_cluster = rados.Rados(name=clientname, conffile=conf)
  File "rados.pyx", line 525, in rados.Rados.__init__ (rados.c:5719)
  File "rados.pyx", line 425, in rados.requires.wrapper.validate_func (rados.c:4106)
  File "rados.pyx", line 557, in rados.Rados.__setup (rados.c:6237)
rados.Error: rados_initialize failed with error code: -22

对我做错的任何帮助将不胜感激。

4

2 回答 2

0

rados.ObjectNotFound: error connecting to the clusterfor/bin/ceph-rest-api --cluster test --id test表示测试用户不存在。此外,根据 ceph-rest-api 手册页,--name 以 client 开头,--id 不以 client 开头。即: ceph-rest-api --cluster test --name client.adminceph-rest-api --cluster test --id admin

于 2016-07-25T05:10:19.043 回答
0

您需要在应该启动 ceph-rest-api 的机器上放置一个密钥环文件。

  1. 创建一个restapi用户:
    ceph auth get-or-create client.rest-test mds 'allow' osd 'allow *' mon 'allow *

    输出应如下所示
    [client.rest-test] key = AQDPVTFZsiZjIRAAtLXWWlr8Q8t1PjhFKnOCyw==

  2. 创建其余用户密钥环文件/etc/ceph/ceph-client.<username>.keyring
    并将输出粘贴到ceph auth get-or-create该文件中或在执行命令时重定向输出。
    您可以随时重复该命令ceph auth get-or-create,当用户已经创建时,ceph auth 将以相同的方式获取用户密钥和名称


  3. ceph-rest-api --name client.rest-test
    用or启动 ceph-rest-api
    ceph-rest-api --id rest-test

研究

我用 strace 做了一些测试,以确定 ceph-rest-api 在开始之前打开和读取了哪些文件。
strace -e open ceph-rest-api -i rest-test 2>&1 | grep key

...
open("/etc/ceph/ceph.client.rest-test.keyring", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ceph/ceph.keyring", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ceph/keyring", O_RDONLY)     = -1 ENOENT (No such file or directory)
open("/etc/ceph/keyring.bin", O_RDONLY) = -1 ENOENT (No such file or directory)

如您所见,ceph-rest-api 尝试打开一些不同的密钥文件,在这种情况下,不存在密钥文件并且启动 ceph-rest-api 失败。如果您将代表您的 rest-user 的正确密钥文件放在 /etc/ceph 中,则该文件将被读取并且 rest-api 将启动。

strace -e open,connect ceph-rest-api  -i rest-test 2>&1  | grep -i 'key\|running'
open("/etc/ceph/ceph.client.rest-test.keyring", O_RDONLY) = 3
open("/etc/ceph/ceph.client.rest-test.keyring", O_RDONLY) = 3
* Running on http://0.0.0.0:5000/
于 2017-06-02T12:41:24.523 回答