ceph对象存储服务、高可用安装配置

简介:
    Ceph本质上就是一个rados,利用命令rados就可以访问和使用ceph的对象存储,但作为一个真正产品机的对象存储服务,通常使用的是Restfulapi的方式进行访问和使用。而radosgw其实就是这个作用,安装完radosgw以后,就可以使用api来访问和使用ceph的对象存储服务了。
    首先明白一下架构,radosgw其实名副其实,就是rados的一个网关,作用是对外提供对象存储服务。本质上radosgw(其实也是一个命令)和rbd命令一样,其实是ceph集群的客户端。只不过,radosgw即作为rados的客户端,同时又提供http restful接口,作为服务端供用户使用。Radosgw对用户而言就是一个http restful的应用,因此本质上来讲,对其进行使用就是通过http的方式,但显然每次都要用户构建http访问的url和headers不是一个很方便的方式,因此radosgw兼容了通用的对象存储接口,分别是亚马逊的s3和openstack的swift,这也就是说你可以用swift或者s3的客户端来访问radosgw。
    Radosgw包含两个命令行工具:
    一个是radosgw,这个是用来启动radosgw服务的脚b本,是一个二进制文件;
    另外一个是radosgw-admin,这是用来管理radosgw的账号的一个命令行工具,主要用来创建、查看、修改radosgw的账号信息。

注意,radowgw的账号信息仅仅是对radosgw的用户而言,这个和ceph中的用户不是一个概念。
    Radosgw作为ceph集群(rados)的客户端,因此他在ceph中有一个账号,通常叫做client.radosgw.gateway。在启动radosgw这个服务时,会读取ceph.conf中[client.radosgw.gateway]这个section。

RGW业务处理流程:

http reqest --> apache 转 FastCgi module

FastCgi module --> radosgw  通过socket请求实现

radosgw --> ceph集群  通过socket实现,调用rados接口


一:配置部署环境介绍:
1:系统版本:
[root@node242 ~]# more /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)

2:内核版本:
[root@node242 ~]# uname  -a
Linux node242 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

3:ceph 版本:
[root@node242 ~]# ceph --version
ceph version 0.94.5 (9764da52395923e0b32908d83a9f7304401fee43)

4:集群节点数和osd 情况:
[root@node242 ~]# ceph osd tree
ID WEIGHT  TYPE NAME            UP/DOWN REWEIGHT PRIMARY-AFFINITY
-6       0 host node01                                            
-1 1.35999 root default                                           
-2 0.09000     host ceph-deploy                                   
 0 0.09000         osd.0             up  1.00000          1.00000
-3 0.09000     host node241                                       
 1 0.09000         osd.1             up  1.00000          1.00000
-4 0.09000     host node242                                       
 2 0.09000         osd.2             up  1.00000          1.00000
-5 1.00000     host node243                                       
 3 1.00000         osd.3             up  1.00000          1.00000
-7 0.09000     host node245                                       
 5 0.09000         osd.5             up  1.00000          1.00000
 
 
 二:部署
1:安装Apache服务
    在Apache 2.4发行版(如RHEL 7,CentOS7),mod_proxy_fcgi默认已经会安装。 httpd 安装完成,mod_proxy_fcgi可用的服务器上使用。

yum install httpd -y

2:修改httpd服务,先清理一下配置文件的无用注释;
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
sed -i '/^#/d' /etc/httpd/conf/httpd.conf

vim /etc/httpd/conf/httpd.conf

修改配置中的LISTEN字段,将网关所在主机的IP地址添加进去

Listen 192.168.2.42:80

添加ServerName项,添加上自己服务器的IP地址

ServerName 192.168.2.42:80

3:在配置尾部增加如下信息,加载mod_proxy_fcgi
首先确认一下模块存在
[root@node242 ~]# ll /etc/httpd/modules/mod_proxy_fcgi.so
-rwxr-xr-x 1 root root 19360 Nov 20 05:44 /etc/httpd/modules/mod_proxy_fcgi.so

添加内容如下:

<IfModule !proxy_fcgi_module>
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
</IfModule>

4:重启apache服务

systemctl start httpd

5:配置apache ssl配置
    此选项主要为了对应,一些resetful客户端默认使用https;如果公司有信任机构颁发的证书,可以直接使用,如果没有可以自己做一个自认证的证书,网上有很多配置参考文档,本次演示直接使用公司的正式ssl证书。

6:安装apache ssl证书相关依赖软件包安装

yum install mod_ssl openssl -y

##########################
需要做自签名证书的参照信息如下:
http://docs.ceph.com/docs/master/install/install-ceph-gateway/
Enable SSL  ==》步骤 2~6
############################

7:上传公司ssl证书到服务器 (本次演示直接使用公司的正式ssl证书)

[root@node242 ceph]# ll
-rw-r--r-- 1 root root 6335 Dec 23 15:48 ptengine.cn.crt
-rw-r--r-- 1 root root 1704 Dec 23 15:48 ptengine.cn.key

copy文件到相关目录
cp -rp ptengine.cn.crt  /etc/pki/tls/certs/ptengine.cn.crt
cp -rp ptengine.cn.key /etc/pki/tls/private/ptengine.cn.key

验证文件是否就位
ll  /etc/pki/tls/certs/ptengine.cn.crt
ll /etc/pki/tls/private/ptengine.cn.key

8:配置文件修改/etc/httpd/conf.d/ssl.conf
首先清理配置文件注释项;
cp -rp /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak

sed -i '/^#/d' /etc/httpd/conf.d/ssl.conf

9:修改配置项如下:
vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile  /etc/pki/tls/certs/ptengine.cn.crt
SSLCertificateKeyFile /etc/pki/tls/private/ptengine.cn.key


10:配置修改完成,重启apache
systemctl restart httpd

三:安装Ceph对象存储网关服务
    ceph网关其实是ceph集群的一个客户端,用户通过这个网关间接访问ceph集群,

1:软件包安装:
yum install ceph-radosgw -y

2:配置Ceph的对象存储准备信息

    ceph网关其实是ceph集群的一个客户端,用户通过这个网关间接访问ceph集群,作为客户端,它需要准备如下内容:
网关名称,此处用gateway称呼、
一个可以访问存储集群的用户以及对应的KEYRING
数据资源池,这个由ceph集群提供
为网关服务示例准备一个数据存放空间
在ceph.conf配置文件中设置gateway信息

3:创建访问用户及权限设置
创建gateway keyring,
ceph-authtool --create-keyring /etc/ceph/ceph.client.radosgw.keyring
chmod +r /etc/ceph/ceph.client.radosgw.keyring

4:创建网关用户名以及key 此处名字为 client.radosgw.gateway
ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n client.radosgw.gateway --gen-key

5:验证:
[root@node242 ceph]# more ceph.client.radosgw.keyring
[client.radosgw.gateway]
        key = AQBXI3lWoOC7MBAAWMHg+sNAelf8S3Hm3S5BiQ==

6:为KEYRING添加权限
ceph-authtool -n client.radosgw.gateway --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring

7:验证授权:
[root@node242 ceph]# more ceph.client.radosgw.keyring
[client.radosgw.gateway]
        key = AQBXI3lWoOC7MBAAWMHg+sNAelf8S3Hm3S5BiQ==
        caps mon = "allow rwx"
        caps osd = "allow rwx"
        

8:将key添加到集群中
ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.radosgw.gateway -i /etc/ceph/ceph.client.radosgw.keyring


备注:如果想在多节点安装对象存储服务,将相关的KEYRING文件拷贝到rados-gateway所在的主机 /etc/ceph/目录下

9:手动创建pool
Ceph的对象网关要求Ceph的存储集群池存储特定网关的数据。 如果您创建的用户有权限,网关将自动创建池,但是有些可能创建不成功。
手工创建方式如下:  参考命令:ceph osd pool create {poolname} {pg-num} {pgp-num}

ceph osd pool create .rgw 128 128
ceph osd pool create .rgw.root 128 128
ceph osd pool create .rgw.control 128 128
ceph osd pool create .rgw.gc 128 128
ceph osd pool create .rgw.buckets 128 128
ceph osd pool create .rgw.buckets.index 128 128
ceph osd pool create .log 128 128
ceph osd pool create .intent-log 128 128
ceph osd pool create .usage 128 128
ceph osd pool create .users 128 128
ceph osd pool create .users.email 128 128
ceph osd pool create .users.swift 128 128
ceph osd pool create .users.uid 128 128

如果pool已经存在,系统会给出提示
pool '.users.uid' already exists

10:查看pool
[root@node242 ceph]# ceph osd lspools
4 rbd,5 mypool,13 flask_test,16 .rgw,17 .rgw.root,18 .rgw.control,19 .rgw.gc,20 .rgw.buckets,21
.rgw.buckets.index,22 .log,23 .intent-log,24 .usage,25 .users,26 .users.email,27 .users.swift,28 .users.uid,


11:将网关配置信息添加到集群配置中,不同的主机注意需要修改host=后面的信息
[client.radosgw.gateway]
host=node242
keyring=/etc/ceph/ceph.client.radosgw.keyring
rgw socket path=/var/run/ceph/ceph.radosgw.gateway.fastcgi.sock
log file=/var/log/radosgw/client.radosgw.gateway.log
rgw frontends=fastcgi socket_port=9000 socket_host=0.0.0.0
rgw print continue=false

另外按需添加debgu 配置,辅助调试;添加位置为[global]  
注意:按需添加,非必须
[global]
#append the following in the global section.
debug ms = 1
debug rgw = 20

12:创建radosgw服务启动所需环境并修改权限

创建数据目录
mkdir -p /var/lib/ceph/radosgw/ceph-radosgw.gateway
   
调整apache运行权限
chown apache:apache /var/run/ceph

调整日志权限
touch /var/log/radosgw/client.radosgw.gateway.log
chown apache:apache /var/log/radosgw/client.radosgw.gateway.log

13:启动网关服务
/etc/init.d/ceph-radosgw start

14:验证,服务监听端口 9000
[root@node242 ceph]# netstat -tunlp
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN      9372/radosgw


 15:添加网关配置文件,用于web server和FastCGI之间的交互

官网演示配置信息如下(仅http):

vi /etc/httpd/conf.d/rgw.conf

<VirtualHost *:80>
ServerName localhost          《---如果内部有dns服务器可以写域名,没有dns也可以写本机ip地址,推荐写域名
DocumentRoot /var/www/html

ErrorLog /var/log/httpd/rgw_error.log
CustomLog /var/log/httpd/rgw_access.log combined

# LogLevel debug

RewriteEngine On

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

SetEnv proxy-nokeepalive 1

ProxyPass / unix:///var/run/ceph/ceph.radosgw.gateway.fastcgi.sock|fcgi://localhost:9000/

</VirtualHost>


本次测试环境将对http、https 同时进行配置,配置文件如下:

#########################测试环境配置###########################
#http访问配置
<VirtualHost *:80>
ServerName rgw.ptengine.cn
#DocumentRoot /var/www/html
ErrorLog /var/log/httpd/rgw_error.log
CustomLog /var/log/httpd/rgw_access.log combined
# LogLevel debug
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
SetEnv proxy-nokeepalive 1
ProxyPass / fcgi://localhost:9000/
#ProxyPass / unix:///var/run/ceph/ceph.radosgw.gateway.fastcgi.sock|fcgi://localhost:9000/
</VirtualHost>

#https访问配置

<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/ptengine.cn.crt
SSLCertificateKeyFile /etc/pki/tls/private/ptengine.cn.key
ServerName rgw.ptengine.cn
#DocumentRoot /var/www/html
ErrorLog /var/log/httpd/rgw_error.log
CustomLog /var/log/httpd/rgw_access.log combined
# LogLevel debug
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
SetEnv proxy-nokeepalive 1
ProxyPass / fcgi://localhost:9000/
#ProxyPass / unix:///var/run/ceph/ceph.radosgw.gateway.fastcgi.sock|fcgi://localhost:9000/
</VirtualHost>
####################################################

16:重启apache服务
systemctl restart httpd

以上配置将对象存储网关配置完成,下面将进行对象存储网关相关功能演示;


四:对象存储功能测试;

1:radosgw-admin命令简要介绍

命令可以是以下选项之一:

创建一个新用户
user create

修改用户
user modify

显示信息的用户,以及任何潜在的可用子用户和秘钥
user info

删除用户
user rm

修改一个子用户
subuser modify

删除子用户
subuser RM

查看存储空间列表
radosgw-admin bucket list
[
    "rgw",
    "my-new-bucket",
    "ptmind-test-bucket
查看所有的bucket

删除bucket
radosgw-admin bucket rm  s3://my-new-bucket

获取s3用户名:
rados -p .users.uid ls

获取用户详细信息:
for user in `rados -p .users.uid ls` ;do radosgw-admin metadata get user:$user;done;

删除一个bucket:
radosgw-admin bucket unlink --bucket=foo

删除一个用户和所有相关的bucket与他们的内容:
radosgw-admin user rm --uid=johnny --purge-data

删除用户命令:
radosgw-admin user rm --uid=pttest

2:创建s3类型访问用户
radosgw-admin user create --uid=ptmind --display-name="ptmind for ceph" --email=kevin@ptmind.com
返回信息如下:
{
    "user_id": "ptmind",
    "display_name": "ptmind for ceph",
    "email": "kevin@ptmind.com",
    "suspended": 0,
    "max_buckets": 1000,
    "auid": 0,
    "subusers": [],
    "keys": [
        {
            "user": "ptmind",
            "access_key": "CLAV9B0BEAAA6XF17P2Y",
            "secret_key": "DbiQnQGuC7HMadOuptFgVMOMJhnMKKG2UNtePbS5"
        }
    ],
    "swift_keys": [],
    "caps": [],
    "op_mask": "read, write, delete",
    "default_placement": "",
    "placement_tags": [],
    "bucket_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "user_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "temp_url_keys": []
}

3:创建SWIFT类型USER

radosgw-admin subuser create --uid=ptmind --subuser=ptmind :swift --access=full
{
    "user_id": "ptmind",
    "display_name": "ptmind for ceph",
    "email": "kevin@ptmind.com",
    "suspended": 0,
    "max_buckets": 1000,
    "auid": 0,
    "subusers": [
        {
            "id": "ptmind:ptmind",
            "permissions": "full-control"
        }
    ],
    "keys": [
        {
            "user": "ptmind:ptmind",
            "access_key": "3O61RZPCIR5Y4YCKBKP2",
            "secret_key": ""
        },
        {
            "user": "ptmind",
            "access_key": "CLAV9B0BE9BA6XF17P2Y",
            "secret_key": "DbiQnQGuC7HMadOuptFgVMOMJhnMKKG2UNtePbS5"
        }
    ],
    "swift_keys": [],
    "caps": [],
    "op_mask": "read, write, delete",
    "default_placement": "",
    "placement_tags": [],
    "bucket_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "user_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "temp_url_keys": []
}



4:实际验证访问
下面是官网一段python代码,用于访问网关,并创建bucket,并通过list方法罗列出当前所有的bucket。

5:依赖库安装
yum install python-boto -y


6:保存脚本内容:
注意:修改host= 后面ip地址
vi s3test.py

import boto
import boto.s3.connection
access_key = 'CLAV9B0BE9BA6XF17P2Y'                       
secret_key = 'DbiQnQGuC7HMadOuptFgVMOMJhnMKKG2UNtePbS5'
conn = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = '192.168.2.42',
is_secure=False,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
bucket = conn.create_bucket('ptmind-test-bucket')
for bucket in conn.get_all_buckets():
        print "{name}\t{created}".format(
                name = bucket.name,
                created = bucket.creation_date,
)



7:运行脚本,查看结果;
python s3test.py
ptmind-test-bucket   2015-10-10T06:23:48.000Z

至此,Ceph集群的对象存储网关安装设置完毕

五:对象存储调试工具推荐:
调试对象存储,推荐式s3cmd

1:安装和配置s3cmd
yum install s3cmd -y

2:配置s3cmd进行S3接口测试,初始化 s3cmd本地环境  将之前radosgw-admin创建的user的access_key和secret_key,根据本机实际进行赋值;

vim ~/.s3cfg

[default]
access_key = 6FIZEZBT3LUBTPC60Z33
bucket_location = US
cloudfront_host = ceph.ptengine.cn
cloudfront_resource = /2015-12-15/distribution
default_mime_type = binary/octet-stream
delete_removed = False
dry_run = False
encoding = UTF-8
encrypt = False
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = ceph-100-80
host_bucket = %(*)s.ceph-100-80
human_readable_sizes = False
list_md5 = False
log_target_prefix =
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
recursive = False
recv_chunk = 4096
reduced_redundancy = False
secret_key = DbiQnQGuC7HMadOuptFgVMOMJhnMKKG2UNtePbS5
send_chunk = 4096
simpledb_host = rgw.ptengine.cn
skip_existing = False
socket_timeout = 10
urlencoding_mode = normal
use_https = False
verbosity = WARNING

3:测试是否配置成功:

s3cmd --configure
将会问你一系列问题:
    AWS S3的访问密钥和安全密钥
    对AWS S3双向传输的加密密码和加密数据
    为加密数据设定GPG程序的路径(例如,/usr/bin/gpg)
    是否使用https协议
    如果使用http代理,设定名字和端口

配置将以保存普通文本格式保存在 ~/.s3cfg.
一路选确定,因为我们已经配置过了,直到最后一步Test选y:

########################本人测试环境配置,s3cmd自测ok#############################
[root@ceph-100-80 ceph]# more ~/.s3cfg
[default]
access_key = 6FIZEZBT3LUBTPC60Z33
access_token =
add_encoding_exts =
add_headers =
bucket_location = US
ca_certs_file =
cache_file =
check_ssl_certificate = True
check_ssl_hostname = True
cloudfront_host = rgw.ptengine.cn
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encoding = UTF-8
encrypt = False
expiry_date =
expiry_days =
expiry_prefix =
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = rgw.ptengine.cn
host_bucket = %(*)s.rgw.ptengine.cn
human_readable_sizes = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
kms_key =
limitrate = 0
list_md5 = False
log_target_prefix =
long_listing = False
max_delete = -1
mime_type =
multipart_chunk_size_mb = 15
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 4096
reduced_redundancy = False
requester_pays = False
restore_days = 1
secret_key = DbiQnQGuC7HMadOuptFgVMOMJhnMKKG2UNtePbS5
send_chunk = 4096
server_side_encryption = False
signature_v2 = False
simpledb_host = rgw.ptengine.cn
skip_existing = False
socket_timeout = 10
stop_on_error = False
storage_class =
urlencoding_mode = normal
use_https = False
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://rgw.ptengine.cn/
website_error =
website_index = index.html

#####################################################

4:s3cmd命令参数介绍:

帮助命令:
s3cmd --help
使用方法

1:配置,主要是 Access Key ID 和 Secret Access Key
s3cmd --configure

2:列举所有 Buckets。(bucket 相当于根文件夹)
s3cmd ls

3:创建 bucket,且 bucket 名称是唯一的,不能重复。
s3cmd mb s3://my-bucket-name

4:删除空 bucket
s3cmd rb s3://my-bucket-name

5:列举 Bucket 中的内容
s3cmd ls s3://my-bucket-name

6:上传 file.txt 到某个 bucket,
s3cmd put file.txt s3://my-bucket-name/file.txt

7:上传并将权限设置为所有人可读
s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt

8:批量上传文件
s3cmd put ./* s3://my-bucket-name/

9:下载文件
s3cmd get s3://my-bucket-name/file.txt file.txt

10:批量下载
s3cmd get s3://my-bucket-name/* ./

11:删除文件
s3cmd del s3://my-bucket-name/file.txt

12:来获得对应的bucket所占用的空间大小
s3cmd du -H s3://my-bucket-name


######目录处理规则########


以下命令都能将dir1 中的文件上传至my-bucket-name,但效果只截然不同的。

1:dir1 不带"/"斜杠,那么dir1会作为文件路径的一部分,相当于上传整个dir1目录,即类似 "cp -r dir1/"

~/demo$ s3cmd put -r dir1 s3://my-bucket-name/
dir1/file1-1.txt -> s3://my-bucket-name/dir1/file1-1.txt  [1 of 1]

2:带"/"斜杠的 dir1,相当于上传dir1目录下的所有文件,即类似 "cp ./* "

~/demo$ s3cmd put -r dir1/ s3://my-bucket-name/
dir1/file1-1.txt -> s3://my-bucket-name/file1-1.txt  [1 of 1]


########同步方法########

这是s3cmd 使用难点,但却是最实用的功能。官方使用说明见《s3cmd sync HowTo》http://s3tools.org/s3cmd-sync
首先明确,同步操作是要进行MD5校验的,只有当文件不同时,才会被传输。
常规同步操作

1:同步当前目录下所有文件
s3cmd sync  ./  s3://my-bucket-name/

s3cmd sync    s3://my-bucket-name/  ./

2:加 "--dry-run"参数后,仅列出需要同步的项目,不实际进行同步。
s3cmd sync  --dry-run ./  s3://my-bucket-name/

3:加 " --delete-removed"参数后,会删除本地不存在的文件。
s3cmd sync  --delete-removed ./  s3://my-bucket-name/

s3cmd sync --delete-removed --force ./  s3://test.bucket


4:加 " --skip-existing"参数后,不进行MD5校验,直接跳过本地已存在的文件。
s3cmd sync  --skip-existing ./  s3://my-bucket-name/

4.2、高级同步操作

4.2.1、排除、包含规则(--exclude 、--include)

file1-1.txt被排除,file2-2.txt同样是txt格式却能被包含。
~/demo$ s3cmd sync --dry-run --exclude '*.txt' --include 'dir2/*' ./  s3://my-bucket-name/
exclude: dir1/file1-1.txt
upload: ./dir2/file2-2.txt -> s3://my-bucket-name/dir2/file2-2.txt

4.2.2、从文件中载入排除或包含规则。(--exclude-from、--include-from)
s3cmd sync  --exclude-from pictures.exclude ./  s3://my-bucket-name/

pictures.exclude 文件内容

# Hey, comments are allowed here ;-)
*.jpg
*.gif

4.2.3、排除或包含规则支持正则表达式
--rexclude 、--rinclude、--rexclude-from、--rinclude-from


六:多节点部署对象存储服务

1:安装相关软件包
yum install httpd mod_ssl openssl ceph-radosgw python-boto s3cmd -y

2:copy文件到相关目录
ceph rgw key文件、apache配置文件、ssl证书等
rsync -avp --delete /etc/ceph root@172.16.100.81:/etc/ceph
scp -rp /etc/httpd/conf/httpd.conf root@172.16.100.81:/etc/httpd/conf/
scp -rp /etc/pki/tls/certs/ptengine.cn.crt root@172.16.100.81:/etc/pki/tls/certs/ptengine.cn.crt
scp -rp /etc/pki/tls/private/ptengine.cn.key root@172.16.100.81:/etc/pki/tls/private/ptengine.cn.key
scp -rp /etc/httpd/conf.d/ssl.conf root@172.16.100.81:/etc/httpd/conf.d/ssl.conf
scp -rp /etc/httpd/conf.d/rgw.conf root@172.16.100.81:/etc/httpd/conf.d/rgw.conf
scp -rp  ~/.s3cfg root@172.16.100.81: ~/.s3cfg

3:创建目录及日志文件
mkdir -p /var/lib/ceph/radosgw/ceph-radosgw.gateway
chown apache:apache /var/run/ceph
touch /var/log/radosgw/client.radosgw.gateway.log
chown apache:apache /var/log/radosgw/client.radosgw.gateway.log

4:将网关配置信息添加到集群配置中,如果是从配置成功的节点copy过来的配置文件,只要修改host=项为本机ip地址即可
[client.radosgw.gateway]
host=ceph-100-81
keyring=/etc/ceph/ceph.client.radosgw.keyring
rgw socket path=/var/run/ceph/ceph.radosgw.gateway.fastcgi.sock
log file=/var/log/radosgw/client.radosgw.gateway.log
rgw frontends=fastcgi socket_port=9000 socket_host=0.0.0.0
rgw print continue=false

5:修改http监听ip地址为本机
vim /etc/httpd/conf/httpd.conf
Listen 172.16.100.82:80
ServerName 172.16.100.82:80

6:重启httpd 服务
 systemctl restart httpd

7:启动radosgw 服务

[root@ceph-100-82 ceph]# /etc/init.d/ceph-radosgw start
Starting ceph-radosgw (via systemctl):  [  OK  ]

8:验证监听端口
[root@ceph-100-82 ceph]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 172.16.100.82:80        0.0.0.0:*               LISTEN      20328/httpd         

9:运行脚本,查看结果;
python s3test.py
ptmind-test-bucket   2015-10-10T06:23:48.000Z

如需再次添加节点,按照以上步骤操作即可;

七:对象存储高可用、负载均衡配置;
本次测试环境,3台服务器配置radosgw服务,信息如下:

 172.16.100.80                
 172.16.100.81
 172.16.100.82

实现功能目标:
1:多接点负载请求压力;
2:单节点故障实现自动冗余;
3:提供http、https 请求;

使用nginx服务配置反向代理负载均衡;详细配置如下:

#########################nginx 反向代理配置###########################

nginx——apache/fastcgi/ceph


#port 80
      upstream  rgwstream80 {                                                                   
        ip_hash;                                                                       
        server   172.16.100.80 max_fails=2 fail_timeout=10s;                 
        server   172.16.100.81 max_fails=2 fail_timeout=10s;
        server   172.16.100.82 max_fails=2 fail_timeout=10s;                     
        }                                                                   
      upstream  rgwstream443 {
        ip_hash;
        server   172.16.100.80:443 max_fails=2 fail_timeout=10s;
        server   172.16.100.81:443 max_fails=2 fail_timeout=10s;
        server   172.16.100.82:443 max_fails=2 fail_timeout=10s;
        }
      server                                                                           
      {                                                                                
        listen  80;
        server_name   rgw.ptengine.cn;
       access_log       /data/nginxlog/rgw.ptengine.cn.log etllog;
        proxy_redirect off;                                                          
        location / {                                                             
#                   proxy_next_upstream  error timeout invalid_header http_500 http_503 http_404;
                    proxy_pass        http://rgwstream80;                                     
                    proxy_set_header   Host             $host;                       
                    proxy_set_header   X-Real-IP        $remote_addr;                
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                    #允许客户端请求的最大单个文件字节数
                    client_max_body_size     10m;
                    #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本再传给用户
                    client_body_buffer_size  256k;
                    #跟后端服务器连接的超时时间_发起握手等候响应超时时间
                    proxy_connect_timeout    6m;
                    #连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之等候处理
                    proxy_read_timeout       6m;
                    #后端服务器数据回传时间_就是在规定时间内后端服务器必须传完所有的数据
                    proxy_send_timeout       6m;
                    #代理请求缓存区_这个缓存区间会保存用户的头信息以供Nginx进行则处理_一般只要能保存下头信息即可
                    proxy_buffer_size        64k;
                    #同上 告诉Nginx保存单个用的几个Buffer 最大用多大空间
                    proxy_buffers            4 256k;
                    #如果系统很忙的时候可以申请更大的proxy_buffers 官方推荐*2    
                    proxy_busy_buffers_size 256k;
                    #proxy缓存临时文件的大小
                    proxy_temp_file_write_size 256k;
                    # redirecet server error pages to the static pag !
                    error_page  502 503 504        /502.html;
                    }
    }

      server
      {
        listen  443;
        server_name  rgw.ptengine.cn;
        access_log       /data/nginxlog/rgw.ptengine.cn.log etllog;
        ssl                  on;
        ssl_certificate  /usr/local/nginx/ssl/www.ptengine.cn.crt;
        ssl_certificate_key  /usr/local/nginx/ssl/www.ptengine.cn.key;
        proxy_redirect off;
        location / {
                    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
                    proxy_pass        https://rgwstream443;
                    proxy_set_header   Host             $host;
                    proxy_set_header   X-Real-IP        $remote_addr;
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                    #允许客户端请求的最大单个文件字节数
                    client_max_body_size     10m;
                    #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本再传给用户
                    client_body_buffer_size  256k;
                    #跟后端服务器连接的超时时间_发起握手等候响应超时时间
                    proxy_connect_timeout    6m;
                    #连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之等候处理
                    proxy_read_timeout       6m;
                    #后端服务器数据回传时间_就是在规定时间内后端服务器必须传完所有的数据
                    proxy_send_timeout       6m;
                    #代理请求缓存区_这个缓存区间会保存用户的头信息以供Nginx进行则处理_一般只要能保存下头信息即可
                    proxy_buffer_size        64k;
                    #同上 告诉Nginx保存单个用的几个Buffer 最大用多大空间
                    proxy_buffers            4 256k;
                    #如果系统很忙的时候可以申请更大的proxy_buffers 官方推荐*2    
                    proxy_busy_buffers_size 256k;
                    #proxy缓存临时文件的大小
                    proxy_temp_file_write_size 256k;
                    error_page  502 503 504        /502.html;
                    }                                     
          
        }


外围主机需要使用s3cmd调用存储网关上传下载文件,操作步骤如下:

安装软件包:
yum install mod_ssl openssl python-boto s3cmd -y

生成配置文件:
vim ~/.s3cfg
[default]
access_key = 6FIZEZBT3LUBTPC60Z33
access_token =
add_encoding_exts =
add_headers =
bucket_location = US
ca_certs_file =
cache_file =
check_ssl_certificate = True
check_ssl_hostname = True
cloudfront_host = rgw.ptengine.cn
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encoding = UTF-8
encrypt = False
expiry_date =
expiry_days =
expiry_prefix =
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = rgw.ptengine.cn
host_bucket = %(*)s.rgw.ptengine.cn
human_readable_sizes = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
kms_key =
limitrate = 0
list_md5 = False
log_target_prefix =
long_listing = False
max_delete = -1
mime_type =
multipart_chunk_size_mb = 15
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 4096
reduced_redundancy = False
requester_pays = False
restore_days = 1
secret_key = pTh23YAx8aXFBdFlhPV4lTTrQweYNprDyQj0Ff3n
send_chunk = 4096
server_side_encryption = False
signature_v2 = False
simpledb_host = rgw.ptengine.cn
skip_existing = False
socket_timeout = 10
stop_on_error = False
storage_class =
urlencoding_mode = normal
use_https = False
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://rgw.ptengine.cn/
website_error =
website_index = index.html

测试是否配置成功:

s3cmd --configure
将会问你一系列问题:
    AWS S3的访问密钥和安全密钥
    对AWS S3双向传输的加密密码和加密数据
    为加密数据设定GPG程序的路径(例如,/usr/bin/gpg)
    是否使用https协议
    如果使用http代理,设定名字和端口

配置将以保存普通文本格式保存在 ~/.s3cfg.
一路选确定,因为我们已经配置过了,直到最后一步Test选y:

最终验证:
[root@lvs-3-65 tmp]# s3cmd ls

正常返回结果为ok;
2015-12-28 09:23  s3://rgw
2016-01-04 10:49  s3://synctest
2016-01-04 09:55  s3://test.bucket
You have new mail in /var/spool/mail/root


参考文档:
http://docs.ceph.com/docs/master/man/8/radosgw/
http://www.ithao123.cn/content-8387956.html
http://my.oschina.net/myspaceNUAA/blog/515261
my.oschina.net/myspaceNUAA/blog/515261