Project

General

Profile

Create Versionable and Fault-Tolerant Storage Devices with Ceph and VirtualBox » History » Version 1

Jessica Mack, 06/23/2015 02:52 AM

1 1 Jessica Mack
h1. Create Versionable and Fault-Tolerant Storage Devices with Ceph and VirtualBox
2
3
h3. Introducing Ceph
4
5
The cloud is becoming ubiquitous and more and more enterprises, applications and end-users are transitioning their data to cloud platforms. This has created a new challenge for cloud providers, both private and public: building fault-tolerant, high-performance infrastructure that supports big data storage and processing needs, yet is easy to scale and flexible enough to support multiple use cases.
6
That's where Ceph comes in. Ceph is a distributed storage system designed to provide excellent performance, reliability and scalability. It's open source, so it's freely downloadable and usable, and it offers a unified storage interface that's versatile enough to support object storage, block device storage and file system storage all in the same Ceph cluster.
7
Ceph is highly reliable, but setting it up can be a little complex, especially if you're new to scalable storage. Ceph is highly reliable, with self-healing and self-managing characteristics. While the quickstart doc is great, we also wanted to provide something a bit more procedural to get you started. That's where this tutorial comes in. Over the next few pages, I'll walk you through the process of building a simple Ceph storage cluster and adding data to it. We'll set up the cluster using VirtualBox, so you'll get a chance to see Ceph 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.
8
Intrigued? Keep reading.
9
10
h3. Assumptions and Requirements
11
12
For this tutorial, I'll be using VirtualBox, which provides an easy way to set up independent virtual servers, with CentOS as the operating system for the virtual servers. VirtualBox is available for Windows, Linux, Macintosh, and Solaris hosts. I'll make the following assumptions:
13
* You have a working knowledge of CentOS, VirtualBox and VirtualBox networking.
14
* You have downloaded and installed the latest version of VirtualBox.
15
* 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
16
* You're familiar with installing software using the yum, the CentOS package manager.
17
* You’re familiar with SSH-based authentication.
18
19
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.
20
To set up a Ceph storage cluster with VirtualBox, here are the steps you'll follow:
21
# Create cluster nodes
22
# Install the Ceph deployment toolkit
23
# Configure authentication between cluster nodes
24
# Configure and activate a cluster monitor
25
# Prepare and activate OSDs
26
# Verify cluster health
27
# Test the cluster
28
# Connect a Ceph block device to the cluster
29
30
The next sections will walk you through these steps in detail.
31
32
h3. Step 1: Create Cluster Nodes
33
34
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:
35
Launch VirtualBox and use the Machine -> New menu to create a new virtual server.
36
37
!image1.jpg!
38
39
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.
40
41
!image2.jpg!
42
43
Add a virtual hard drive of at least 10 GB.
44
45
!image3.jpg!
46
47
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).
48
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.
49
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:
50
@HWADDR=08:00:27:AE:14:41
51
TYPE=Ethernet
52
BOOTPROTO=static
53
DEFROUTE=yes
54
PEERDNS=yes
55
PEERROUTES=yes
56
IPV4_FAILURE_FATAL=no
57
IPV6INIT=yes
58
IPV6_AUTOCONF=yes
59
IPV6_DEFROUTE=yes
60
IPV6_PEERDNS=yes
61
IPV6_PEERROUTES=yes
62
IPV6_FAILURE_FATAL=no
63
NAME=enp0s8
64
UUID=5fc74119-1ab2-4c0c-9aa1-284fd484e6c6
65
ONBOOT=no
66
IPADDR=192.168.1.25
67
NETMASK=255.255.255.0
68
GATEWAY=192.168.1.1
69
DNS1=192.168.1.1
70
DNS2=8.8.8.8@
71
Should any of the above steps be unfamiliar to you, refer to the VirtualBox manual, especially the VirtualBox networking guide, and to the networking section of the CentOS deployment guide.
72
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).
73
 
74
|Server host name|	IP address|	Purpose|
75
|admin-node|	192.168.1.25|	Administration node for cluster|
76
|node1|	192.168.1.26|	Monitor|
77
|node2|	192.168.1.27|	OSD daemon|
78
|node3|	192.168.1.28|	OSD daemon|
79
|node4|	192.168.1.29|	Client (block device)|
80
81
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.
82
83
h3. Step 2: Install the Ceph Deployment Toolkit
84
85
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.
86
Log in to the administration node as the root user.
87
Add the package to the yum repository by creating a new file at /etc/yum.repos.d/ceph.repo with the following content:
88
@[ceph-noarch]
89
name=Ceph noarch packages
90
baseurl=http://ceph.com/rpm-firefly/el7/noarch
91
enabled=1
92
gpgcheck=1
93
type=rpm-md
94
gpgkey=https://ceph.com/git/?p=ceph.git;a=b...ys/release.asc@
95
Update the repository.
96
@shell> yum update@
97
Install the Ceph deployment toolkit.
98
@shell> yum install ceph-deploy@
99
 
100
!image4.jpg!
101
102
h3. Step 3: Configure Authentication between Cluster Nodes
103
104
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:
105
Log in as the root user.
106
Create a ceph user account.
107
shell> useradd ceph
108
shell> passwd ceph
109
Give the ceph user account root privileges with sudo.
110
shell> echo "ceph ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/ceph
111
shell> chmod 0440 /etc/sudoers.d/ceph
112
Disable 'requiretty' for the ceph user.
113
shell> sudo visudo
114
In the resulting file, locate the line containing
115
Defaults requiretty
116
and change it to read
117
Defaults:ceph !requiretty
118
Now, set up passphraseless SSH between the nodes:
119
Log in to the administration node as the ceph user.
120
Generate an SSH key for the administration node.
121
shell> ssh-keygen
122
123
!image5.jpg!
124
125
Copy the generated public key to the ceph user account of all the nodes in the cluster.
126
shell> ssh-copy-id ceph@node1
127
shell> ssh-copy-id ceph@node2
128
shell> ssh-copy-id ceph@node3
129
shell> ssh-copy-id ceph@node4
130
shell> ssh-copy-id ceph@admin-node
131
132
!image6.jpg!
133
134
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.
135
shell> ssh ceph@node1
136
137
!image7.jpg!
138
139
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:
140
Host node1
141
  Hostname node1
142
  User ceph
143
Host node2
144
  Hostname node2
145
  User ceph
146
Host node3
147
  Hostname node3
148
  User ceph
149
Host node4
150
  Hostname node4
151
  User ceph
152
Host admin-node
153
  Hostname admin-node
154
  User ceph
155
Change the permissions of the /home/ceph/.ssh/config file.
156
shell> chmod 0400 ~/.ssh/config
157
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.
158
shell> ssh node1
159
160
!image8.jpg!
161
 
162
Finally, create a directory on the administration node to store cluster information, such as configuration files and keyrings.
163
shell> mkdir my-cluster
164
shell> cd my-cluster
165
You're now ready to begin preparing and activating the cluster!
166
167
h3. Step 4: Configure and Activate a Cluster Monitor
168
169
A Ceph storage cluster consists of two types of daemons:
170
Monitors maintain copies of the cluster map
171
Object Storage Daemons (OSD) store data as objects on storage nodes
172
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.
173
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.
174
A minimal system will have at least one monitor and two OSD daemons for data replication.
175
Begin by setting up a Ceph monitor on node1 with the Ceph deployment toolkit.
176
shell> ceph-deploy new node1
177
This will define the name of the initial monitor node and create a default Ceph configuration file and monitor keyring in the current directory.
178
179
!image9.jpg!
180
 
181
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:
182
osd pool default size = 2
183
osd pool default min size = 2
184
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:
185
osd journal size = 4000
186
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:
187
osd pool default pg num = 128
188
Install Ceph on each node in the cluster, including the administration node.
189
shell> ceph-deploy install admin-node node1 node2 node3 node4
190
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.
191
192
!image10.jpg!
193
194
Create the Ceph monitor on node1 and gather the initial keys.
195
shell> ceph-deploy mon create-initial node1
196
197
!image11.jpg!
198
199
h3. Step 5: Prepare and Activate OSDs
200
201
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:
202
Log into node2 as the ceph user.
203
shell> ssh node2
204
Create a directory for the OSD daemon.
205
shell> sudo mkdir /var/local/osd
206
Log out of node2. Then, from the administrative node, prepare and activate the OSD.
207
shell> ceph-deploy osd prepare node2:/var/local/osd
208
209
!image12.jpg!
210
211
shell> ceph-deploy osd activate node2:/var/local/osd
212
213
!image13.jpg!
214
215
Repeat the above steps for node3.
216
At this point, the OSD daemons have been created and the storage cluster is ready.
217
218
h3. Step 6: Verify Cluster Health
219
220
Copy the configuration file and admin keyring from the administration node to all the nodes in the cluster.
221
shell> ceph-deploy admin admin-node node1 node2 node3 node4
222
223
!image14.jpg!
224
225
Log in to each node as the ceph user and change the permissions of the admin keyring.
226
shell> ssh node1
227
shell> sudo chmod +r /etc/ceph/ceph.client.admin.keyring
228
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.
229
shell> ceph status
230
231
!image15.jpg!
232
233
h3. Step 7: Test the Cluster
234
235
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:
236
Log in to node1 as the ceph user.
237
shell> ssh node1
238
Create a new file with some dummy data.
239
shell> echo "Hello world" > /tmp/hello.txt
240
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.
241
shell> rados put hello-object /tmp/hello.txt --pool data
242
To verify that the Ceph storage cluster stored the object:
243
Log in to node2 as the ceph user.
244
Check that the file exists in the cluster's data storage pool with the rados ls command.
245
shell> rados ls --pool data
246
Copy the file out of the storage cluster to a local directory with the rados get command and verify its contents
247
shell> rados get hello-object /tmp/hello.txt --pool data
248
shell> cat hello.txt
249
250
!image16.jpg!
251
252
h3. Step 8: Connect a Ceph Block Device to the Cluster
253
254
Now that the cluster is operating, it’s time to do something with it. Ceph storage clusters can be accessed by three types of clients: Ceph block devices, Ceph object gateways and the Ceph filesystem (CephFS). The simplest to demonstrate is the RADOS Block Device (RBD), so in this step you'll create a virtual block device client on node4, associate it with a storage pool and then read and write data to it.
255
Log in to node4 as the ceph user.
256
shell> ssh node4
257
Create a pool named work. Within the pool, specify the number of placement groups, which are the number of shards or fragments that the pool is divided into. Placement groups are mapped to OSDs and a larger number of placement groups (such as 100 per OSD) leads to better balancing.
258
shell> ceph osd pool create work 100 100
259
Create a RADOS Block Device image with rbd and connect it with the pool.
260
shell> rbd create image01 --size 1024 --pool work
261
Map the block device image to the actual block device.
262
shell> sudo rbd map image01 --pool work --name client.admin
263
Create a filesystem on the block device and mount it.
264
shell> sudo /sbin/mkfs.ext4 -m0 /dev/rbd/work/image01
265
shell> sudo mkdir /mnt/ceph-block-device
266
shell> sudo mount /dev/rbd/work/image01 /mnt/ceph-block-device
267
268
!image17.jpg!
269
270
At this point, your Ceph block device is mounted and ready for use. You can write data to it as with any other block device, and your data will be automatically stored in the cluster (with all its resiliency and scalability benefits). Plus, you get a bunch of cool features, such as the ability to create device snapshots, so you can easily roll back to a previous image of the device.
271
To demonstrate this:
272
Navigate to where you mounted the block device and create a text file. You might need to first change the permissions of the mount point so that you can write to it.
273
shell> cd /mnt/ceph-block-device
274
shell> vi today.txt
275
Add the word 'Monday' to the file.
276
Then, take a snapshot of the image.
277
shell> rbd --pool work snap create --snap monday image01
278
Edit the file again and this time change the contents to 'Friday'.
279
Unmount the block device. Then, roll back to the previous snapshot and mount it again.
280
shell> sudo umount /mnt/ceph-block-device
281
shell> rbd --pool work snap rollback --snap monday image01
282
shell> sudo mount /dev/rbd/work/image01 /mnt/ceph-block-device
283
When you inspect the contents of the file, you will see the original contents restored.
284
You must unmount the block device before doing a rollback. If it's mounted when you rollback, the client will have a stale cache, which may cause filesystem corruption, since it's like a hard drive being written by two machines at once.
285
286
h3. Conclusion
287
288
Just as you can use Ceph block devices, so too can you use the Ceph Object Gateway to create Amazon S3-style storage buckets accessible via REST, or CephFS as a POSIX-compliant scalable, fault-tolerant network filesystem. Setting these up is beyond the scope of this beginner tutorial, but since they both use the Ceph storage cluster that you've already configured, it won't take long for you to get them running. Review instructions for the Ceph Object Gateway and instructions for CephFS.
289
As this tutorial will have illustrated, Ceph is a powerful solution for creating resilient, infinitely scalable storage. The simple storage cluster you created here with VirtualBox is just the tip of the iceberg: as you transition the cluster to your network or the cloud and add more nodes, you'll benefit from improved performance and flexibility without any loss in reliability and security. What more could you ask for?
290
291
h3. Read More
292
293
* Introduction to Ceph
294
* Ceph Architecture
295
* Ceph Storage Cluster Quick Start
296
* Getting Started With Ceph
297
* Introduction to Ceph & OpenStack   
298
* Managing A Distributed Storage System At Scale
299
* Scaling Storage With Ceph
300
* Ceph API Documentation