【ceph】CEPH RGW初使用-RGW1

 

原文《Getting started with CEPH RGW》:https://soumyakoduri.wordpress.com/2019/02/14/getting-started-with-ceph-rgw/

在这篇文章中,我记录在fedora-28 虚拟机上创建最小 CEPH RGW 集群的粗略的笔记和命令。

操作系统版本:

# cat /etc/redhat-release
Fedora release 28 (Twenty Eight)

系统要求:

  • >25 GB storage space where ceph source code needs to be built
  • preferably >8GB ram

从源代码手动安装:

To build ceph code:

Source: http://docs.ceph.com/docs/mimic/install/build-ceph/

  • git clone https://github.com/ceph/ceph.git
  • cd ceph/
  • git status
  • git submodule update –force –init –recursive
  • ./install-deps.sh  #安装依赖
  • ./do_cmake.sh
  • cd build/
  • make
  • make install
  • ln -s /usr/local/lib64/librado* /usr/lib64/

在虚拟机上本地启动 ceph 集群:

  • cd /../ceph/build
  • MON=1 OSD=1 MDS=1 MGR=1 RGW=1 ..//src/vstart.sh -n -d
    • 所列的每项服务都创建一个
  • ps aux | grep ceph

现在创建 rgw 用户/子用户 users/sub-users:

Source:- (http://docs.ceph.com/docs/mimic/radosgw/admin/)

我们需要为 S3 访问创建用户和为 SWIFT 创建子用户。
radosgw-admin user create –uid=rgwuser –display-name=”RGW user”
#默认情况下生成访问密钥和秘密密钥(access-key and secret key)。检查用户信息

  • radosgw-admin subuser create –uid=rgwuser –subuser=rgwuser:swift –access=full
  • radosgw-admin caps add –uid=rgwuser –caps=”users=*;buckets=*”
    • (增加能力)
  • radosgw-admin 用户信息 –uid=rgwuser
    • 检查用户/子用户信息

测试 s3 访问:(使用 python-boto)

Source: http://docs.ceph.com/docs/mimic/radosgw/s3/python/

  • dnf 安装 python-boto
  • 以下是各种功能的示例脚本 -
import boto
import boto.s3.connection

access_key = "ZGX5BVGID059T7DJLM0S"
secret_key = "koe8DFgGwNk5sQTRVxHaDiEgYQDVj8XVXMdZ4ULd"

boto.config.add_section('s3')
boto.config.set('s3', 'use-sigv4', 'True')

#create connection
conn = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = 's3.localhost',
port = 8000,
is_secure=False,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)

#create bucket
bucket = conn.create_bucket('my-new-bucket')

#list buckets created
for bucket in conn.get_all_buckets():
print "{name}\t{created}".format(
name = bucket.name,
created = bucket.creation_date,
)

#insert file "hello.txt" as object into the bucket
key = bucket.new_key('hello.txt')
key.set_contents_from_string('Hello World!') #write contents

#list objects
for key in bucket.list():
print "{name}\t{size}\t{modified}".format(
name = key.name,
size = key.size,
modified = key.last_modified,
)

#connect to specific bucket and object
my_bucket = conn.get_bucket('my-new-bucket')
hello_key = my_bucket.get_key('hello.txt')

# make hello.txt object public
hello_key.set_canned_acl('public-read')

#generate web-url for the file hello.txt
hello_url = hello_key.generate_url(0, query_auth=False, force_http=True)
print hello_url

#copy hello.txt to local filesystem
key.get_contents_to_filename('/workspace/scripts/sample_hello.txt')

通过 SWIFT 访问进行测试:

Source: https://access.redhat.com/documentation/en-us/red_hat_ceph_storage/3/html/object_gateway_guide_for_red_hat_enterprise_linux/rgw-configuration-rgw#test-swift-access

  • dnf 安装 python-setuptools
  • easy_install pip
  • pip install – 升级安装工具
  • pip install –upgrade python-swiftclient
  • 列出已经创建的容器:
    • swift -A http://{IP ADDRESS}:{port}/auth/1.0 -U testuser:swift -K ‘{swift_secret_key}’ list
    • eg: 
      #swift -A http://localhost:8000/auth/1.0 -U rgwuser:swift -K '5euZSGD4ikdo4ppVYNiQ1czRXSACHkuO367S41Po' list
      my-new-bucket
  • 将对象插入容器:
# echo " swift access " > swift_file
# swift -A http://localhost:8000/auth/1.0 -U rgwuser:swift -K '5euZSGD4ikdo4ppVYNiQ1czRXSACHkuO367S41Po' upload my-new-bucket swift_file 
swift_file
# swift -A http://localhost:8000/auth/1.0 -U rgwuser:swift -K '5euZSGD4ikdo4ppVYNiQ1czRXSACHkuO367S41Po' list my-new-bucket
hello.txt
swift_file
  • 下载一个对象:
#  swift -A http://localhost:8000/auth/1.0 -U rgwuser:swift -K '5euZSGD4ikdo4ppVYNiQ1czRXSACHkuO367S41Po' download my-new-bucket hello.txt 
hello.txt [auth 0.003s, headers 0.008s, total 0.008s, 0.002 MB/s]
# cat hello.txt 
Hello World!

 

使用 Ceph-nano:

Source: http://docs.ceph.com/docs/mimic/install/build-ceph/

  • 确保 docker 已安装并正在运行。

#systemctl start docker

  • 运行示例泊坞窗图像以检查其是否正常工作

#docker run hello-world

对我来说,它起初在 VM 上工作..然后更新包“dnf update”并重新启动 VM..它工作了。

  • git clone https://github.com/ceph/cn.git
  • cd cn/
  • make
  • 创建容器并配置 ceph 集群:
    • ./cn cluster start -d /root/tmp my-first-cluster
    • ./cn cluster status my-first-cluster
    • docker ps
    • docker image ls
    • ./cn cluster ls
    • ./cn cluster enter my-first-cluster
  • 创建 S3 存储桶:
    • ./cn s3 mb my-first-cluster my-buc
    • ./cn s3 put my-first-cluster /etc/passwd my-buc

 

 

上一篇:sed常见报错


下一篇:Wpf实现图片自动轮播自定义控件