模板网站会员,做网站是干嘛,网站的后期运营及维护费用,网站建设伍际网络Ceph对象存储系统之RGW接口详解 1.创建Ceph对象存储系统RGW接口2. 开启httphttps,更改监听端口3. 更改监听端口4.S3接口访问测试5.实验中遇到的故障案例 接上文基于ceph-deploy部署Ceph集群详解 1.创建Ceph对象存储系统RGW接口
#xff08;1#xff09;对象存储概念
对象存… Ceph对象存储系统之RGW接口详解 1.创建Ceph对象存储系统RGW接口2. 开启httphttps,更改监听端口3. 更改监听端口4.S3接口访问测试5.实验中遇到的故障案例 接上文基于ceph-deploy部署Ceph集群详解 1.创建Ceph对象存储系统RGW接口
1对象存储概念
对象存储object storage是非结构数据的存储方法对象存储中每一条数据都作为单独的对象存储拥有唯一的地址来识别数据对象通常用于云计算环境中。 不同于其他数据存储方法基于对象的存储不使用目录树。
虽然在设计与实现上有所区别但大多数对象存储系统对外呈现的核心资源类型大同小异。从客户端的角度来看分为以下几个逻辑单位
Amazon S3
提供了 1用户User 2存储桶Bucket 3对象Object
三者的关系是
1User将Object存储到系统上的Bucket 2存储桶属于某个用户并可以容纳对象一个存储桶用于存储多个对象 3同一个用户可以拥有多个存储桶不同用户允许使用相同名称的Bucket因此User名称即可做为Bucket的名称空间
OpenStack Swift
提供了user、container和object分别对应于用户、存储桶和对象不过它还额外为user提供了父级组件account用于表示一个项目或用户因此一个account中可以包含一到多个user它们可共享使用同一组container并为container提供名称空间
RadosGW
提供了user、subuser、bucket和object其中的user对应于S3的user而subuser则对应于Swift的user不过user和subuser都不支持为bucket提供名称空间因此不同用户的存储桶不允许同名不过自jewel版本起RadosGW引入了tenant租户用于为user和bucket提供名称空间但他是个可选组件
从上可以看出大多数对象存储的核心资源类型大同小异如Amazon S3、OpenStack Swift与RadosGw。其中 S3 与 Swift 互不兼容RadosGw为了兼容S3与Swift Ceph在RadosGW集群的基础上提供了RGWRadosGateway数据抽象层和管理层它可以原生兼容 S3 和 Swift 的 API。 S3和Swift它们可基于http或https完成数据交换由RadosGW内建的Civetweb提供服务它还可以支持代理服务器包括nginx、haproxy等以代理的形式接收用户请求再转发至RadosGW进程。 RGW的功能依赖于对象网关守护进程实现负责向客户端提供 REST API接口。出于冗余负载均衡的需求一个 Ceph集群上通常不止一个RadosGW守护进程。
2创建RGW接口
如果需要使用到类似S3或者Swift接口时候才需要部署/创建RadosGW接口RadosGW通常作为对象存储Object Storage使用类于阿里云OSS。
在管理节点创建一个RGW守护进程
cd /etc/ceph
ceph-deploy rgw create node01ceph -s创建成功后,默认情况下会自动创建一系列用于RGW的存储池
ceph osd pool ls
rgw.root
default.rgw.control #控制器信息
default.rgw.meta #记录元数据
default.rgw.log #日志信息
default.rgw.buckets.index #为 rgw 的 bucket 信息写入数据后生成
default.rgw.buckets.data #是实际存储的数据信息写入数据后生成默认情况下RGW监听7480号端口
ssh rootnode01 netstat -lntp | grep 7480curl node01:74802. 开启httphttps,更改监听端口
RadosGW守护进程内部由Civetweb实现通过对Civetweb的配置,可以完成对RadosGW的基本管理。
要在Civetweb上启用SSL首先需要一个证书在admin节点生成证书
1生成CA证书私钥
openssl genrsa -out civetweb.key 20482生成CA证书公钥
openssl req -new -x509 -key civetweb.key -out civetweb.crt -days 3650 -subj /CN192.168.80.303将生成的证书合并为pem
cat civetweb.key civetweb.crt /etc/ceph/civetweb.pem4在admin管理节点将生成合并的证书civetweb.pem推送到RGW节点中 scp civetweb.pem node02:pwd3. 更改监听端口
Civetweb默认监听7480端口并提供http协议。在管理节点编辑ceph.conf配置文件可以修改Civetweb监听的端口号
vim /etc/ceph/ceph.conf
......
[client.rgw.node02]
rgw_host node02
rgw_frontends civetweb port80443s ssl_certificate/etc/ceph/civetweb.pem num_threads500 request_timeout_ms60000------------------------------------------------------------
●rgw_host对应的RadosGW名称或者IP地址
●rgw_frontends这里配置监听的端口是否使用https以及一些常用配置
•port如果是https端口需要在端口后面加一个s。
•ssl_certificate指定证书的路径。
•num_threads最大并发连接数默认为50根据需求调整通常在生产集群环境中此值应该更大
•request_timeout_ms发送与接收超时时长以ms为单位默认为30000
•access_log_file访问日志路径默认为空
•error_log_file错误日志路径默认为空
------------------------------------------------------------修改完ceph.conf配置文件后需要重启对应的RadosGW服务再推送配置文件
ceph-deploy --overwrite-conf config push node0{1..3}ssh rootnode02 systemctl restart ceph-radosgw.target
ssh rootnode02 systemctl status ceph-radosgw.target在rgw节点上查看端口
netstat -lntp | grep -w 80
netstat -lntp | grep 443在客户端访问验证
curl http://192.168.80.30:80
curl -k https://192.168.80.30:443创建RadosGW账户
在管理节点使用radosgw-admin命令创建RadosGW账户
radosgw-admin user create --uidrgwuser --display-namergw test user
-------------------------------------------------------keys: [{user: rgwuser,access_key: 1HXE9W5NNID7BWGW0JCE,secret_key: Oq7UOSE6eTs03e7lqClN8J9iSD7QcKycVbh52gSj}],创建成功后将输出用户的基本信息其中最重要的两项信息为access_key和secret_key 。用户创建成功后如果忘记用户信息可以使用下面的命令查看
radosgw-admin user info --uidrgwuser4.S3接口访问测试
创建以及使用存储桶的脚本文件;
vim /etc/ceph/test.py #coding:utf-8
#boto s3手册http://boto.readthedocs.org/en/latest/ref/s3.html
#boto s3快速入门http://boto.readthedocs.org/en/latest/s3_tut.html
#如果脚本长时间阻塞请检查集群状态开启的端口等
import ssl
import boto.s3.connection
from boto.s3.key import Key
#异常抛出
try:_create_unverified_https_context ssl._create_unverified_context
except AttributeError:pass
else:ssl._create_default_https_context _create_unverified_https_context
#test用户的keys信息为在admin节点使用radosgw-admin命令创建RadosGW账户
access_key 1HXE9W5NNID7BWGW0JCE
secret_key Oq7UOSE6eTs03e7lqClN8J9iSD7QcKycVbh52gSj
#rgw的ip与端口此处的IP地址为kgw节点的IP地址
host 192.168.80.30
#如果使用443端口下述链接应设置is_secureTrue
port 443
#如果使用80端口下述链接应设置is_secureFalse
#port 80
conn boto.connect_s3(aws_access_key_idaccess_key,aws_secret_access_keysecret_key,hosthost,portport,is_secureTrue,validate_certsFalse,calling_formatboto.s3.connection.OrdinaryCallingFormat()
)#一:创建存储桶
conn.create_bucket(bucket_namebucket01)
conn.create_bucket(bucket_namebucket02)#二判断是否存在不存在返回None
exists conn.lookup(bucket01)
print(exists)
exists conn.lookup(bucket02)
print(exists)#三获得一个存储桶
bucket1 conn.get_bucket(bucket01)
bucket2 conn.get_bucket(bucket02)#四查看一个bucket下的内容
print(list(bucket1.list()))
print(list(bucket2.list()))#五向s3上存储数据数据来源可以是file、stream、or string
#5.1、上传文件
bucket1 conn.get_bucket(bucket01)
# name的值是数据的key
key Key(bucketbucket1, namemyfile)
key.set_contents_from_filename(rD:\PycharmProjects\ceph\123.txt)
# 读取 s3 中文件的内容返回 string 即文件 123.txt 的内容
print(key.get_contents_as_string())#5.2、上传字符串
#如果之前已经获取过对象此处不需要重复获取
bucket2 conn.get_bucket(bucket02)
key Key(bucketbucket2, namemystr)
key.set_contents_from_string(hello world)
print(key.get_contents_as_string())#六删除一个存储桶在删除存储桶本身时必须删除该存储桶内的所有key
bucket1 conn.get_bucket(bucket01)
for key in bucket1:key.delete()
bucket1.delete()
#bucket1.get_all_keys()[0].delete() #删除某一个 key#迭代遍历删除 buckets and keys
for bucket in conn:for key in bucket:print(key.name,key.get_contents_as_string())
#—个判断文件夹中是否有文件的方法
bucket1 conn.get_bucket(bucket01)
res bucket1.get_all_keys()
if len(res) 0:print(有文件)
else:print(为空)1在客户端安装python3、python3-pip
yum install -y python3 python3-pippython3 -V
pip3 -V2安装boto模块用于测试连接S3
pip3 install boto3测试访问S3接口
脚本判断存储桶是否存在
#一:创建存储桶
conn.create_bucket(bucket_namebucket01)
conn.create_bucket(bucket_namebucket02)#二判断是否存在不存在返回None
exists conn.lookup(bucket01)
print(exists)
exists conn.lookup(bucket02)
print(exists)
exists conn.lookup(bucket03)
print(exists)将指定文件内容上传到bucket01存储桶中;
##5.1、上传文件
bucket1 conn.get_bucket(bucket01)
## name的值是数据的key
key Key(bucketbucket1, namegzy)
key.set_contents_from_filename(r/opt/123.txt)
## 读取 s3 中文件的内容返回 string 即文件 123.txt 的内容
print(list(bucket1.list()))
print(key.get_contents_as_string())上传指定字符串内容到bucket02存储桶中;
##5.2、上传字符串
##如果之前已经获取过对象此处不需要重复获取
bucket2 conn.get_bucket(bucket02)
key Key(bucketbucket2, nameAyu)
key.set_contents_from_string(hello world is you ooo)
print(list(bucket2.list()))print(key.get_contents_as_string())删除指定存储桶bucket01;
---------需要取消打印存储桶的注释否则将不返回任何数据内容
#二判断是否存在不存在返回None
exists conn.lookup(bucket01)
print(exists)
exists conn.lookup(bucket02)
print(exists)
exists conn.lookup(bucket03)
print(exists)##六删除一个存储桶在删除存储桶本身时必须删除该存储桶内
的所有key
bucket1 conn.get_bucket(bucket01)
for key in bucket1:key.delete()
bucket1.delete()
##bucket1.get_all_keys()[0].delete() #删除某一个 key 5.实验中遇到的故障案例
问题
OSD服务被down掉健康状态显示WARN. 解决方法
产生该问题的原因是数据在均衡或者回滚等操作的时候导致其某个守护进程崩溃了且没有及时归档所以集群产生告警。 在OSD节点重启osd和mgr服务
systemctl restart ceph-osd.target
systemctl restart ceph-mgr.target在admin管理节点查看崩溃守护进程的详细信息
ceph crash ls #列出所有未归档崩溃守护进程
ceph crash archive id #查看某个崩溃守护进程的详细信息
ceph crash archive-all #将所有崩溃守护进程进行存档ceph -s