三種Ceph rgw前端的配置方式

rgw 概述

Ceph 通過radosgw提供RESTFul HTTP API接口支持對象存儲能力,radosgw構建在librados之上,兼容Amazon S3以及Opensack Swift。

radosgw本質上是一個客戶端程序,提供FastCGI 服務。作爲一個客戶端程序,需要滿足如下要求:

  • 一個實例名稱,默認爲:gateway
  • 一個合法用戶
  • 多個存儲池
  • 一個數據目錄
  • 在ceph.conf中添加一個配置項
  • 前端配置文件

radosgw支持以Apache、Civetweb、Nginx作爲前端。Civetweb是默認前端,通過修改ceph.conf配置文件能夠很容易的替換爲Apache,通過配置能也以nginx作爲前端。

下面分別給出centos7上rgw的安裝配置過程

安裝

通過ceph-deploy可以方便的在rgw node上安裝rgw包:

#> ceph-deploy --rgw install {rgw-node-name}

創建用戶

每個rgw實例都需要一個授權用戶及key,下面的例子中創建了一個名爲gateway的用戶,並將密鑰文件存儲在/etc/ceph目錄下

#> ceph auth get-or-create client.radosgw.gateway osd 'allow rwx' mon 'allow rwx' -o /etc/ceph/ceph.client.radosgw.keyring

創建存儲池

rgw需要存儲池來存儲數據,如果授權用戶具有相關權限,rgw將會自動創建存儲池,如果使用默認的區域(region)和可用區(zone),將包含如下的池:

.rgw.root
.rgw.control
.rgw.gc
.rgw.buckets
.rgw.buckets.index
.rgw.buckets.extra
.log
.intent-log
.usage
.users
.users.email
.users.swift
.users.uid

當然,您也可以手動創建各個存儲池:

#> ceph osd pool create {poolname} {pg-num} {pgp-num} {replicated | erasure} [{erasure-code-profile}]  {ruleset-name} {ruleset-number}

添加rgw配置

在ceph.conf中添加一個名爲gateway的實例。

Civetweb

如果以civetweb作爲前端,配置如下:

[client.radosgw.gateway]
host = {hostname}
keyring = /etc/ceph/ceph.client.radosgw.keyring
log file = /var/log/radosgw/client.radosgw.gateway-node1.log
rgw_frontends = civetweb port=80

civetweb默認監聽在7480端口,上述的配置中顯示指定監聽端口爲80(port=80)

Apache

如果以apache作爲前端,配置如下:

[client.radosgw.gateway]
host = {hostname}
keyring = /etc/ceph/ceph.client.radosgw.keyring
rgw socket path = ""
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

配置apache服務,創建/etc/httpd/conf.d/rgw.conf,並寫入如下內容:

<VirtualHost *:80>
ServerName localhost
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/

</VirtualHost>

配置好之後,重啓apache服務:systemctl restart httpd.service

Nginx

ceph.conf配置如下:

[client.radosgw.gateway]
rgw_frontends = fastcgi
host = {hostname}
keyring = /etc/ceph/ceph.client.radosgw.keyring
rgw_socket_path = /var/run/ceph/ceph.radosgw.gateway.sock
log_file = /var/log/ceph/radosgw.log
rgw_print_continue = false
rgw_content_length_compat = true

配置nginx服務,在/etc/nginx/nginx.conf文件的http段下添加如下內容:

http {
server {
        listen   80 default;
        server_name {hostname};
    location / {
            fastcgi_pass_header Authorization;
            fastcgi_pass_request_headers on;
            fastcgi_param QUERY_STRING  $query_string;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_param CONTENT_LENGTH $content_length;

            if ($request_method = PUT) {
                    rewrite ^ /PUT$request_uri;
            }

            include fastcgi_params;
            fastcgi_pass unix:/var/run/ceph/ceph.radosgw.gateway.sock;
        }

        location /PUT/ {
            internal;
            fastcgi_pass_header Authorization;
            fastcgi_pass_request_headers on;

            include fastcgi_params;
            fastcgi_param QUERY_STRING  $query_string;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_param  CONTENT_TYPE $content_type;
            fastcgi_pass unix:/var/run/ceph/ceph.radosgw.gateway.sock;
        }
}

注意: fastcgi_pass 指向的路徑需要與ceph.conf中配置的路徑一致

讓nginx配置生效:nginx -s reload

啓動rgw實例

通過上面的安裝->創建用戶->創建存儲池->配置過程,rgw也就準備就緒了,可以通過下面的命令啓動實例:

//radosgw -c {conf_file} -n {rgw-name}
#> radosgw -c /etc/ceph/ceph.conf -n client.radosgw.gateway

測試

ceph rgw的測試方式有:s3cmd, cosbench,也可以通過python庫boto自己寫測試程序。個人感覺cosbench很不錯,大家可以試試。

rgw多實例

有時爲了提高rgw的併發能力,需要部署多個rgw實例。其實也很簡單,在多個節點上部署多個rgw實例:只需要安裝rgw包,並將ceph.conf文件,密鑰文件,前端配置文件拷貝到相應的節點,然後啓動實例就好。

至此rgw的部署實踐過程就介紹完了,如有問題歡迎留言。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章