Project

General

Profile

Create a Scalable and Resilient Object Gateway with Ceph and VirtualBox » History » Version 6

Jessica Mack, 06/22/2015 11:50 PM

1 1 Jessica Mack
h1. Create a Scalable and Resilient Object Gateway with Ceph and VirtualBox
2
3
{{toc}}
4
5
h3. Introducing the Ceph Object Gateway
6
7
Ceph is a highly reliable distributed storage system, with self-healing and self-managing characteristics. One of its unique characteristics is its unified storage interface, which supports object storage, block device storage and file system storage all in the same Ceph cluster. Of course, it's also open source, so you can freely download and experiment with it at your leisure.
8 6 Jessica Mack
The "Ceph Object Gateway":http://ceph.com/docs/master/radosgw/ provides a way to host scalable data storage "buckets", similar to those provided by "Amazon Simple Storage Service (Amazon S3)":http://aws.amazon.com/s3/ and "OpenStack Swift":http://docs.openstack.org/developer/swift/. These objects are accessible via a REST API, making them ideal for cloud-based applications, big data storage and processing, and many other use cases. And because the underlying cluster infrastructure is managed by Ceph, fault-tolerance and scalability are guaranteed.
9 1 Jessica Mack
Setting up a Ceph object gateway can be a little complex, especially if you're unfamiliar with how scalable object storage works. That's where this tutorial comes in. Over the next few pages, I'll walk you through the process of setting up a Ceph-based object gateway and adding data to it. We'll set up the cluster using VirtualBox, so you'll get a chance to see Ceph's object storage features in action in a "real" environment where you have total control, but which doesn't cost you anything to run or scale out with new nodes.
10
Sounds good? Keep reading.
11
12
h3. Assumptions and Requirements
13
14 6 Jessica Mack
For this tutorial, I'll be using "VirtualBox":https://www.virtualbox.org/, which provides an easy way to set up independent virtual servers, with "CentOS":http://www.centos.org/ as the operating system for the virtual servers. VirtualBox is available for Windows, Linux, Macintosh, and Solaris hosts. I'll make the following assumptions:
15
* You have a working knowledge of CentOS, VirtualBox and VirtualBox networking.
16
* You have downloaded and installed the latest version of VirtualBox.
17
* You have either already configured 5 virtual CentOS servers, or you have downloaded an ISO installation image for the latest version of CentOS (CentOS 7.0 at the time of writing). These servers must be using kernel version 3.10 or later
18
* You're familiar with installing software using the yum, the CentOS package manager.
19
* You’re familiar with SSH-based authentication.
20
* You're familiar with object storage in the cloud.
21
22 1 Jessica Mack
In case you’re not familiar with the above topics, look in the “Read More” section at the end of this tutorial, which has links to relevant guides.
23
To set up a Ceph storage cluster with VirtualBox, here are the steps you'll follow:
24 6 Jessica Mack
# Create cluster nodes
25
# Install the Ceph deployment toolkit
26
# Configure authentication between cluster nodes
27
# Configure and activate a cluster monitor
28
# Prepare and activate OSDs
29
# Verify cluster health
30
# Test the cluster
31
# Install the Ceph object gateway
32
# Configure the Ceph object gateway
33
# Start working with buckets and objects
34
35 1 Jessica Mack
The next sections will walk you through these steps in detail.
36
37
h3. Step 1: Create Cluster Nodes
38
39
If you already have 5 virtual CentOS servers configured and talking to each other, you can skip this step. If not, you must first create the virtual servers that will make up your Ceph cluster. To do this:
40
41 6 Jessica Mack
1. Launch VirtualBox and use the _Machine -> New_ menu to create a new virtual server.
42
43 1 Jessica Mack
!image1.jpg!
44 2 Jessica Mack
45 6 Jessica Mack
2. Keeping in mind that you will need 5 virtual servers running simultaneously, calculate the available RAM on the host system and set the server memory accordingly.
46 1 Jessica Mack
47
!image2.jpg!
48
49 6 Jessica Mack
3. Add a virtual hard drive of at least 10 GB.
50 1 Jessica Mack
51
!image3.jpg!
52
53 6 Jessica Mack
4. Ensure that you have an IDE controller with a virtual CD/DVD drive (to enable CentOS installation) and at least two network adapters, one NAT (to enable download of required software) and one bridged adapter or internal network adapter (for internal communication between the cluster nodes).
54
5. Once the server basics are defined, install CentOS to the server using the ISO installation image. Ensure that your kernel version is at least 3.10 or later.
55
6. Once the installation process is complete, log in to the server and configure the second network interface with a static IP address, by editing the appropriate template file in the _/etc/sysconfig/network-scripts/_ directory. Here's a sample of what the interface configuration might look like:
56
57
p(. @HWADDR=08:00:27:AE:14:41
58 1 Jessica Mack
TYPE=Ethernet
59
BOOTPROTO=static
60
DEFROUTE=yes
61
PEERDNS=yes
62
PEERROUTES=yes
63
IPV4_FAILURE_FATAL=no
64
IPV6INIT=yes
65
IPV6_AUTOCONF=yes
66
IPV6_DEFROUTE=yes
67
IPV6_PEERDNS=yes
68
IPV6_PEERROUTES=yes
69
IPV6_FAILURE_FATAL=no
70
NAME=enp0s8
71
UUID=5fc74119-1ab2-4c0c-9aa1-284fd484e6c6
72
ONBOOT=no
73
IPADDR=192.168.1.25
74
NETMASK=255.255.255.0
75
GATEWAY=192.168.1.1
76
DNS1=192.168.1.1
77 6 Jessica Mack
DNS2=8.8.8.8@
78
79
Should any of the above steps be unfamiliar to you, refer to the "VirtualBox manual":https://www.virtualbox.org/manual/UserManual.html, especially the "VirtualBox networking guide":https://www.virtualbox.org/manual/ch06.html, and to the networking section of the "CentOS deployment guide":http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-networkscripts-interfaces.html.
80
81
Repeat this process until you have 5 virtual servers. Of these, identify one as the cluster administration node and assign it the hostname _admin-node_. The remaining servers may be identified with hostnames such as _node1_, _node2_, and so on. Here's an example of what the final cluster might look like (note that you should obviously modify the IP addresses to match your local network settings).
82 1 Jessica Mack
 
83 6 Jessica Mack
|*Server host name*|*IP address*|*Purpose*|
84
|admin-node|192.168.1.25|Administration node for cluster|
85
|node1|	192.168.1.26|Monitor|
86
|node2|	192.168.1.27|OSD daemon|
87
|node3|	192.168.1.28|OSD daemon|
88
|node4|	192.168.1.29|Object gateway host / PHP client|
89 1 Jessica Mack
90 6 Jessica Mack
Before proceeding to the next step, ensure that all the servers are accessible by pinging them using their host names. If you don't have a local DNS server, add the host names and IP addresses to each server's _/etc/hosts_ file to ease network access.
91
92 1 Jessica Mack
h3. Step 2: Install the Ceph Deployment Toolkit
93
94
The next step is to install the Ceph deployment toolkit on the administration node. This toolkit will help install Ceph on the nodes in the cluster, as well as prepare and activate the cluster.
95 6 Jessica Mack
1. Log in to the administration node as the root user.
96
2. Add the package to the yum repository by creating a new file at /etc/yum.repos.d/ceph.repo with the following content:
97
98
p(. @[ceph-noarch]
99 1 Jessica Mack
name=Ceph noarch packages
100
baseurl=http://ceph.com/rpm-firefly/el7/noarch
101
enabled=1
102
gpgcheck=1
103
type=rpm-md
104 6 Jessica Mack
gpgkey=https://ceph.com/git/?p=ceph.git;a=b...ys/release.asc@
105
106
3. Update the repository.
107
@shell> yum update@
108
4. Install the Ceph deployment toolkit.
109
@shell> yum install ceph-deploy@
110 1 Jessica Mack
 
111
!image4.jpg!
112
113
h3. Step 3: Configure Authentication between Cluster Nodes
114
115 6 Jessica Mack
Now, you need to create a _ceph_ user on each server in the cluster, including the administration node. This user account will handle performing cluster-related operations on each node. Perform the following steps on each of the 5 virtual servers:
116
1. Log in as the _root_ user.
117
2. Create a _ceph_ user account.
118
@shell> useradd ceph
119
shell> passwd ceph@
120
3. Give the _ceph_ user account root privileges with _sudo_.
121
@shell> echo "ceph ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/ceph
122
shell> chmod 0440 /etc/sudoers.d/ceph@
123
4. Disable 'requiretty' for the _ceph_ user.
124
@shell> sudo visudo@
125
5. In the resulting file, locate the line containing
126
@Defaults requiretty@
127 2 Jessica Mack
and change it to read
128 6 Jessica Mack
@Defaults:ceph !requiretty@
129
130 1 Jessica Mack
Now, set up passphraseless SSH between the nodes:
131 6 Jessica Mack
1. Log in to the administration node as the _ceph_ user.
132
2. Generate an SSH key for the administration node.
133
@shell> ssh-keygen@
134 3 Jessica Mack
135
!image52.jpg!
136
137 6 Jessica Mack
3. Copy the generated public key to the _ceph_ user account of all the nodes in the cluster.
138
@shell> ssh-copy-id ceph@node1
139 3 Jessica Mack
shell> ssh-copy-id ceph@node2
140
shell> ssh-copy-id ceph@node3
141
shell> ssh-copy-id ceph@node4
142 6 Jessica Mack
shell> ssh-copy-id ceph@admin-node@
143 1 Jessica Mack
144
!image62.jpg!
145
146 6 Jessica Mack
4. Test that the _ceph_ user on the administration node can log in to any other node as _ceph_ using SSH and without providing a password.
147
@shell> ssh ceph@node1@
148 1 Jessica Mack
149
!image72.jpg!
150
151 6 Jessica Mack
5. Modify the administration node's SSH configuration file so that it can easily log in to each node as the ceph user. Create the _/home/ceph/.ssh/config_ file with the following lines:
152
153
p(. @Host node1
154 1 Jessica Mack
  Hostname node1
155
  User ceph
156
Host node2
157
  Hostname node2
158
  User ceph
159
Host node3
160
  Hostname node3
161
  User ceph
162 3 Jessica Mack
Host node4
163
  Hostname node4
164 1 Jessica Mack
  User ceph
165
Host admin-node
166
  Hostname admin-node
167 6 Jessica Mack
  User ceph@
168 1 Jessica Mack
169 6 Jessica Mack
6. Change the permissions of the _/home/ceph/.ssh/config_ file.
170
@shell> chmod 0400 ~/.ssh/config@
171
7. Test that the _ceph_ user on the administration node can log in to any other node using SSH and without providing a password or username.
172
@shell> ssh node1@
173
174 1 Jessica Mack
!image82.jpg!
175
 
176
Finally, create a directory on the administration node to store cluster information, such as configuration files and keyrings.
177 6 Jessica Mack
@shell> mkdir my-cluster
178
shell> cd my-cluster@
179 1 Jessica Mack
You're now ready to begin preparing and activating the cluster!
180
181 3 Jessica Mack
h3. Step 4: Configure and Activate a Cluster Monitor
182
183 1 Jessica Mack
A Ceph storage cluster consists of two types of daemons:
184 6 Jessica Mack
* Monitors maintain copies of the cluster map
185
* Object Storage Daemons (OSD) store data as objects on storage nodes
186
187
Apart from this, other actors in a Ceph storage cluster include metadata servers and clients such as Ceph block devices, Ceph object gateways or Ceph filesystems. "Read more about Ceph’s architecture":http://ceph.com/docs/master/architecture/.
188
189
All the commands in this and subsequent sections are to be run when logged in as the _ceph_ user on the administration node, from the _my-cluster/_ directory. Ensure that you are directly logged in as _ceph_ and are not using root with _su - ceph_.
190
191 1 Jessica Mack
A minimal system will have at least one monitor and two OSD daemons for data replication.
192 6 Jessica Mack
1. Begin by setting up a Ceph monitor on _node1_ with the Ceph deployment toolkit.
193
@shell> ceph-deploy new node1@
194 3 Jessica Mack
This will define the name of the initial monitor node and create a default Ceph configuration file and monitor keyring in the current directory.
195
196
!image92.jpg!
197 1 Jessica Mack
 
198 6 Jessica Mack
2. Change the number of replicas in the Ceph configuration file at _/home/ceph/my-cluster/ceph.conf_ from 3 to 2 so that Ceph can achieve a stable state with just two OSDs. Add the following line in the [global] section:
199
@osd pool default size = 2
200
osd pool default min size = 2@
201
3. In the same file, set the OSD journal size. A good general setting is 10 GB; however, since this is a simulation, you can use a smaller amount such as 4 GB. Add the following line in the [global] section:
202
@osd journal size = 4000@
203
4. In the same file, set the default number of placement groups for a pool. Since we’ll have less than 5 OSDs, 128 placement groups per pool should suffice. Add the following line in the [global] section:
204
@osd pool default pg num = 128@
205
5. Install Ceph on each node in the cluster, including the administration node.
206
@shell> ceph-deploy install admin-node node1 node2 node3 node4@
207 1 Jessica Mack
The Ceph deployment toolkit will now go to work installing Ceph on each node. Here's an example of what you will see during the installation process.
208
209
!image102.jpg!
210
211 6 Jessica Mack
Create the Ceph monitor on _node1_ and gather the initial keys.
212
@shell> ceph-deploy mon create-initial node1@
213 4 Jessica Mack
214 1 Jessica Mack
!image112.jpg!
215 4 Jessica Mack
216
h3. Step 5: Prepare and Activate OSDs
217
218 1 Jessica Mack
The next set is to prepare and activate Ceph OSDs. We'll need a minimum of 2 OSDs, and these should be set up on node2 and node3, as it's not recommended to mix monitors and OSD daemons on the same host. To begin, set up an OSD on node2 as follows:
219
Log into node2 as the ceph user.
220
shell> ssh node2
221
Create a directory for the OSD daemon.
222
shell> sudo mkdir /var/local/osd
223
Log out of node2. Then, from the administrative node, prepare and activate the OSD.
224
shell> ceph-deploy osd prepare node2:/var/local/osd
225 4 Jessica Mack
226
!image122.jpg!
227
228 1 Jessica Mack
shell> ceph-deploy osd activate node2:/var/local/osd
229
230
!image132.jpg!
231
232
Repeat the above steps for node3.
233
At this point, the OSD daemons have been created and the storage cluster is ready.
234 4 Jessica Mack
235
h3. Step 6: Verify Cluster Health
236 1 Jessica Mack
237
Copy the configuration file and admin keyring from the administration node to all the nodes in the cluster.
238
shell> ceph-deploy admin admin-node node1 node2 node3 node4
239
240
!image142.jpg!
241
242
Log in to each node as the ceph user and change the permissions of the admin keyring.
243
shell> ssh node1
244
shell> sudo chmod +r /etc/ceph/ceph.client.admin.keyring
245
You should now be able to check cluster health from any node in the cluster with the ceph status command. Ideally, you want to see the status active + clean, as that indicates the cluster is operating normally.
246
shell> ceph status
247
248
!image152.jpg!
249
250
h3. Step 7: Test the Cluster
251
252 4 Jessica Mack
You can now perform a simple test to see the distributed Ceph storage cluster in action, by writing a file on one node and retrieving it on another:
253
Log in to node1 as the ceph user.
254 1 Jessica Mack
shell> ssh node1
255
Create a new file with some dummy data.
256
shell> echo "Hello world" > /tmp/hello.txt
257
Data is stored in Ceph within storage pools, which are logical groups in which to organize your data. By default, a Ceph storage cluster has 3 pools - data, metadata and rbd - and it's also possible to create your own custom pools. In this case, copy the file to the data pool with the rados put command and assign it a name.
258
shell> rados put hello-object /tmp/hello.txt --pool data
259
To verify that the Ceph storage cluster stored the object:
260
Log in to node2 as the ceph user.
261
Check that the file exists in the cluster's data storage pool with the rados ls command.
262
shell> rados ls --pool data
263
Copy the file out of the storage cluster to a local directory with the rados get command and verify its contents
264
shell> rados get hello-object /tmp/hello.txt --pool data
265
shell> cat hello.txt
266
267
!image162.jpg!
268
269
h3. Step 8: Install the Ceph Object Gateway
270
271
Now that the cluster is operating, it’s time to do something with it. First, you must install and configure an Apache Web server with FastCGI on node4, as described below.
272
Log into node4 as the ceph user.
273
shell> ssh node4
274
Install Apache and FastCGI from the Ceph repositories. To do this, you need to first install the yum priorities plugin, then add the repositories to your yum repository list.
275
shell> sudo yum install yum-plugin-priorities
276
Edit the /etc/yum/pluginconf.d/priorities.conf file and ensure it looks like this:
277
[main]
278
enabled = 1
279
Create a file at /etc/yum.repos.d/ceph-apache.repo and fill it with the following content:
280
[apache2-ceph-noarch]
281
name=Apache noarch packages for Ceph
282
baseurl=http://gitbuilder.ceph.com/apache2-r...sic/ref/master
283
enabled=1
284
priority=2
285
gpgcheck=1
286
type=rpm-md
287
gpgkey=https://ceph.com/git/?p=ceph.git;a=b.../autobuild.asc
288
[apache2-ceph-source]
289
name=Apache source packages for Ceph
290
baseurl=http://gitbuilder.ceph.com/apache2-r...sic/ref/master
291
enabled=0
292
priority=2
293
gpgcheck=1
294
type=rpm-md
295
gpgkey=https://ceph.com/git/?p=ceph.git;a=b.../autobuild.asc
296
Create a file at /etc/yum.repos.d/ceph-fastcgi.repo and fill it with the following content:
297
[fastcgi-ceph-basearch]
298
name=FastCGI basearch packages for Ceph
299
baseurl=http://gitbuilder.ceph.com/mod_fastc...sic/ref/master
300
enabled=1
301
priority=2
302
gpgcheck=1
303
type=rpm-md
304
gpgkey=https://ceph.com/git/?p=ceph.git;a=b.../autobuild.asc
305
[fastcgi-ceph-noarch]
306
name=FastCGI noarch packages for Ceph
307
baseurl=http://gitbuilder.ceph.com/mod_fastc...sic/ref/master
308
enabled=1
309
priority=2
310
gpgcheck=1
311
type=rpm-md
312
gpgkey=https://ceph.com/git/?p=ceph.git;a=b.../autobuild.asc
313
[fastcgi-ceph-source]
314
name=FastCGI source packages for Ceph
315
baseurl=http://gitbuilder.ceph.com/mod_fastc...sic/ref/master
316
enabled=0
317
priority=2
318
gpgcheck=1
319
type=rpm-md
320
gpgkey=https://ceph.com/git/?p=ceph.git;a=b.../autobuild.asc
321
Update the repository and install Apache and FastCGI.
322
shell> sudo yum update
323
shell> sudo yum install httpd mod_fastcgi
324
Edit the /etc/httpd/conf/httpd.conf file and modify the ServerName directive to reflect the server's host name. Uncomment the line if needed.
325
ServerName node4
326
Review the files in the /etc/httpd/conf.modules.d/* directory to ensure that Apache's URL rewriting and FastCGI modules are enabled. You should find the following entries in the files:
327
LoadModule rewrite_module modules/mod_rewrite.so
328
LoadModule fastcgi_module modules/mod_fastcgi.so
329
In case these entries don't exist, add them to the end of the /etc/httpd/conf/httpd.conf file.
330
Restart Apache.
331 5 Jessica Mack
shell> sudo service httpd restart
332 1 Jessica Mack
Amazon S3 lets you refer to buckets using subdomains, such as http://mybucket.s3.amazonaws.com. You can also accomplish this with Ceph, but you must first install a local DNS server like dnsmasq and add support for wildcard subdomains. Follow these steps:
333
Log into node4 as the ceph user.
334
shell> ssh node4
335
Install dnsmasq.
336
shell> yum install dnsmasq
337
Edit the dnsmasq configuration file at /etc/dnsmasq.conf and add the following line to the end of the file:
338
address=/.node4/192.168.1.29
339
Save the file and restart dnsmasq.
340
shell> sudo service dnsmasq restart
341
If necessary, update the /etc/resolv.conf file on the client host so that it knows about the new DNS server.
342
nameserver 192.168.1.29
343
You should now be able to successfully ping any subdomain of *.node4, such as mybucket.node4 or example.node4, as shown in the image below.
344
 
345
!image172.png!
346
 
347
TIP: If you're not able to configure wildcard subdomains, you can also simply decide a list of subdomains you wish to use and then add them as static entries to the client system's /etc/hosts file. Ensure that the entries resolve to the node4 virtual host.
348
The final step is to install radosgw on node4:
349
shell> ssh node4
350
shell> sudo yum install ceph-radosgw
351
At this point, you have a Web server running with the Ceph object gateway and FastCGI support, and subdomains that resolve to the object gateway host.
352
353
h3. Step 9: Configure the Ceph Object Gateway
354
355
The next step is to configure the Ceph Object Gateway daemon. Follow these steps:
356
Log into the administration node as the ceph user.
357
shell> ssh admin-node
358
Create a keyring for the gateway.
359 5 Jessica Mack
shell> sudo ceph-authtool --create-keyring /etc/ceph/ceph.client.radosgw.keyring
360
shell> sudo chmod +r /etc/ceph/ceph.client.radosgw.keyring
361
Generate a user name and key to use when accessing the gateway. For this example, the user name is client.radosgw.gateway.
362 1 Jessica Mack
shell> sudo ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n  client.radosgw.gateway --gen-key
363
Add read and write capabilities to the new key:
364
shell> sudo ceph-authtool -n  client.radosgw.gateway --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring
365
Add the new key to the storage cluster and distribute it to the object gateway node.
366
shell> sudo ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.radosgw.gateway -i /etc/ceph/ceph.client.radosgw.keyring
367
shell> sudo scp /etc/ceph/ceph.client.radosgw.keyring  ceph@node4:/home/ceph
368
shell> ssh node4
369
shell> sudo mv ceph.client.radosgw.keyring /etc/ceph/ceph.client.radosgw.keyring
370
shell> exit
371
This process should also have created a number of storage pools for the gateway. You can verify this by running the following command and verifying that the output includes various .rgw pools.
372
shell> rados lspools
373
374
!image182.png!
375
376
Change to your cluster configuration directory.
377
shell> cd ~/my-cluster
378
Edit the Ceph configuration file at ~/my-cluster/ceph/ceph.conf and add a new [client.radosgw.gateway] section to it, as below:
379
[client.radosgw.gateway]
380
host = node4
381
keyring = /etc/ceph/ceph.client.radosgw.keyring
382
rgw socket path = /var/run/ceph/ceph.radosgw.gateway.fastcgi.sock
383
log file = /var/log/radosgw/client.radosgw.gateway.log
384
rgw dns name = node4
385
rgw print continue = false
386
Transmit the new Ceph configuration file to all the other nodes in the cluster.
387
shell> ceph-deploy config push admin-node node1 node2 node3 node4
388
Log into node4 as the ceph user.
389
shell> ssh node4
390
Add a Ceph object gateway script, by creating a file at /var/www/html/s3gw.fcgi with the following content:
391
#!/bin/sh
392
exec /usr/bin/radosgw -c /etc/ceph/ceph.conf -n client.radosgw.gateway
393
Change the permissions of the script to make it executable.
394
shell> sudo chmod +x /var/www/html/s3gw.fcgi
395
Create a data directory for the radosgw daemon.
396
shell> sudo mkdir -p /var/lib/ceph/radosgw/ceph-radosgw.gateway
397
Add a gateway configuration file, by creating a file at /etc/httpd/conf.d/rgw.conf and filling it with the following content:
398
FastCgiExternalServer /var/www/html/s3gw.fcgi -socket /var/run/ceph/ceph.radosgw.gateway.fastcgi.sock
399
<VirtualHost *:80>
400
    ServerName node4
401
    ServerAlias *.node4
402
    ServerAdmin admin@localhost
403
    DocumentRoot /var/www/html
404
    RewriteEngine On
405
    RewriteRule  ^/(.*) /s3gw.fcgi?%{QUERY_STRING} [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
406
    <IfModule mod_fastcgi.c>
407
       <Directory /var/www/html>
408
            Options +ExecCGI
409
            AllowOverride All
410
            SetHandler fastcgi-script
411
            Order allow,deny
412
            Allow from all
413
            AuthBasicAuthoritative Off
414
        </Directory>
415
    </IfModule>
416
    AllowEncodedSlashes On
417
    ErrorLog /var/log/httpd/error.log
418
    CustomLog /var/log/httpd/access.log combined
419
    ServerSignature Off
420
</VirtualHost>
421
<VirtualHost *:443>
422
    ServerName node4
423
    ServerAlias *.node4
424
    ServerAdmin admin@localhost
425
    DocumentRoot /var/www/html
426
    RewriteEngine On
427
    RewriteRule  ^/(.*) /s3gw.fcgi?%{QUERY_STRING} [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
428
    <IfModule mod_fastcgi.c>
429
       <Directory /var/www/html>
430
            Options +ExecCGI
431
            AllowOverride All
432
            SetHandler fastcgi-script
433
            Order allow,deny
434
            Allow from all
435
            AuthBasicAuthoritative Off
436
        </Directory>
437
    </IfModule>
438
    AllowEncodedSlashes On
439 5 Jessica Mack
    ErrorLog /var/log/httpd/error.log
440
    CustomLog /var/log/httpd/access.log combined
441
    ServerSignature Off
442 1 Jessica Mack
  SSLEngine on
443
  SSLCertificateFile /etc/apache2/ssl/apache.crt
444
  SSLCertificateKeyFile /etc/apache2/ssl/apache.key
445
  SetEnv SERVER_PORT_SECURE 443
446
</VirtualHost>
447
Edit the /etc/httpd/conf.d/fastcgi.conf file and ensure that the line referencing the FastCgiWrapper looks like this:
448
FastCgiWrapper off
449
Restart the Apache server, followed by the radosgw daemon.
450
shell> sudo service httpd restart
451
shell> sudo /etc/init.d/ceph-radosgw restart
452 5 Jessica Mack
You can quickly test that the object gateway is running by sending an HTTP GET request to the Web server, as shown below:
453
454
!image192.png!
455 1 Jessica Mack
456
At this point, your Ceph object gateway is running and you can begin using it.
457
458
h3. Step 10: Start Working with Buckets and Objects
459
460
Before you can begin using the Ceph object gateway, you must create a user account.
461
Log in to node4 as the ceph user.
462
shell> ssh admin-node
463
Create a new user account using the radosgw-admin command. In this example, the user is named 'john'.
464
shell> radosgw-admin user create --uid=john --display-name="Example User"
465
Here's an example of what you should see. Note the access key and secret key in the output, as you will need this to access the object gateway from another client.
466
467
!image202.png!
468
469
You can also verify that the user was created with the following command:
470
shell> radosgw-admin user info --uid=john
471
While you can interact with the object gateway directly over HTTP, by sending authenticated GET, PUT and DELETE requests to the gateway endpoints, an easier way is with Amazon's AWS SDK. This SDK includes classes and constructs to help you work with buckets and objects in Amazon S3. Since the Ceph object gateway is S3-compatible, you can use the same SDK to interact with it as well.
472
The AWS SDK is available for multiple programming languages. In the examples that follow, I'll use the AWS SDK for PHP, but you will find code examples for other languages as well on the AWS developer website.
473
Log in to node4 (which will now also double as the client node) as the root user and install PHP and related tools.
474
shell> sudo yum install php curl php-curl
475
Create a working directory for your PHP files. Download Composer, the PHP dependency manager, into this directory.
476
shell> cd /tmp
477
shell> mkdir ceph
478
shell> cd ceph
479
shell> curl -sS https://getcomposer.org/installer | php
480
Create a composer.json file in the working directory and fill it with the following content:
481
{
482
    "require": {
483
        "aws/aws-sdk-php": "2.*"
484
    }
485
}
486
Download the AWS SDK for PHP and related dependencies using Composer:
487
shell> cd /tmp/ceph
488
shell> php composer.phar install
489
You can now begin interacting with your object gateway using PHP. For example, here's a simple PHP script to create a new bucket:
490
<?php
491
// create-bucket.php
492
// autoload files
493
require 'vendor/autoload.php';
494
use Aws\S3\S3Client;
495
// instantiate S3 client
496
$s3 = S3Client::factory(array(
497
        'key' => 'YOUR_ACCESS_KEY',
498
        'secret' => 'YOUR_SECRET_KEY',
499 5 Jessica Mack
        'endpoint' => 'http://node4'
500
));
501
// create bucket
502 1 Jessica Mack
try {
503
  $s3->createBucket(array('Bucket' => 'mybucket'));
504
  echo "Bucket created \n";
505
} catch (Aws\S3\Exception\S3Exception $e) {
506
  echo "Request failed: $e";
507
}
508
This script begins by initializing the Composer auto-loader and an instance of the S3Client object. The object is provided with the access key and secret for the user created earlier, and a custom endpoint points to the object gateway Web server.
509
The S3Client object provides a number of methods to create and manage buckets and objects. One of these is the createBucket() method, which accepts a bucket name and generates the necessary PUT request to create a new bucket in the object gateway.
510
You can run this script at the console as follows:
511
shell> php create-bucket.php
512
Here's an example of what the output might look like:
513
514
!image212.png!
515
516
You can also create a bucket and then add a file to it as an object, using the client object's upload() method. Here's an example:
517
<?php
518
// create-bucket-object.php
519
// autoload files
520
require 'vendor/autoload.php';
521
use Aws\S3\S3Client;
522
// instantiate S3 client
523
$s3 = S3Client::factory(array(
524
        'key' => 'YOUR_ACCESS_KEY',
525
        'secret' => 'YOUR_SECRET_KEY',
526
        'endpoint' => 'http://node4'
527
));
528
// create bucket and upload file to it
529
try {
530
  $s3->createBucket(array('Bucket' => 'myotherbucket'));
531
  $s3->upload('myotherbucket', 'test.tgz', file_get_contents('/tmp/test.tgz'), 'public-read');
532
  echo 'Bucket and object created';     
533
} catch (Aws\S3\Exception\S3Exception $e) {
534
  echo "Request failed: $e";
535
}
536
Of course, you can also list all the buckets and objects available to the authenticated user with the listBuckets() and listObjects() methods:
537
<?php
538
// list-bucket-contents.php
539
// autoload files
540
require 'vendor/autoload.php';
541
use Aws\S3\S3Client;
542
// instantiate S3 client
543
$s3 = S3Client::factory(array(
544
        'key' => 'YOUR_ACCESS_KEY',
545
        'secret' => 'YOUR_SECRET_KEY',
546
        'endpoint' => 'http://node4'
547
));
548
// create bucket and upload file to it
549
try {
550 5 Jessica Mack
  $bucketsColl = $s3->listBuckets();
551
  foreach ($bucketsColl['Buckets'] as $bucket) {
552
    echo $bucket['Name'] . "\n";
553 1 Jessica Mack
    $objColl = $s3->listObjects(array('Bucket' => $bucket['Name']));
554
     if ($objColl['Contents']) {
555
        foreach ($objColl['Contents'] as $obj) {
556
          echo '- ' . $obj['Key'] . "\n";
557
        }
558
     }
559
  }
560
} catch (Aws\S3\Exception\S3Exception $e) {
561
  echo "Request failed: $e";
562
}
563
Here's an example of what the output might look like:
564
565
!image222.png!
566
567
Of course, you can do a lot more with the AWS SDK for PHP. Refer to the reference documentation for a complete list of methods and example code.
568
569
h3. Conclusion
570
571
As this tutorial has illustrated, Ceph makes it easy to set up a standards-compliant object gateway for your applications or users, with all the benefits of a resilient, infinitely scalable underlying storage cluster.
572
The simple object gateway you created here with VirtualBox is just the tip of the iceberg: you can transition your object gateway to the cloud and run it in federated mode across regions and zones for even greater flexibility, and because the Ceph object gateway is also Swift-compliant, you can maximize compatibility for OpenStack users without any changes to your existing infrastructure. And of course, you can also use the underlying object storage cluster for fault-tolerant Ceph block devices or the POSIX-compliant CephFS filesystem.
573
The bottom line: Ceph's unique architecture gives you improved performance and flexibility without any loss in reliability and security. And it's open source, so you can experiment with it, improve it and use it without worrying about vendor lock-in. You can't get any better than that!
574
575
h3. Read More
576
577
"Introduction to Ceph":http://ceph.com/docs/master/start/intro/
578
"Ceph Architecture":http://ceph.com/docs/master/architecture/
579
"Getting Started With Ceph":http://www.inktank.com/resource/getting-started-with-ceph-miroslav-klivansky/
580
"Introduction to Ceph & OpenStack":http://www.inktank.com/resource/introduction-to-ceph-openstack-miroslav-klivansky/    
581
"Managing A Distributed Storage System At Scale":http://www.inktank.com/resource/managing-a-distributed-storage-system-at-scale-sage-weil/
582
"Scaling Storage With Ceph":http://www.inktank.com/resource/scaling-storage-with-ceph-ross-turk/
583
"Ceph API Documentation":http://ceph.com/docs/master/api/