Project

General

Profile

Deploying Ceph with Chef » History » Version 1

Jessica Mack, 06/06/2015 06:57 AM

1 1 Jessica Mack
h1. Deploying Ceph with Chef
2
3
{{toc}}
4
5
h2. %{color:black}Installing Chef%
6
7
Chef defines three types of entities:
8
 
9
* *Chef Nodes*: Run 'chef-client', which installs and manages software.
10
* *Chef Server*: Interacts with 'chef-client' on Chef nodes.
11
* *Chef Workstation* : Manages the Chef server.
12
 
13
See "'Chef Architecture Introduction'":http://docs.chef.io/ for details.
14
 
15
h3. Create a 'chef' User
16
 
17
The 'chef-client' command requires the proper privileges to install and manage
18
installations. On each Chef node, we recommend creating a 'chef' user with 
19
full 'root' privileges. For example: 
20
 
21
<pre>
22
ssh user@chef-node
23
sudo useradd -d /home/chef -m chef
24
sudo passwd chef
25
</pre>
26
 
27
To provide full privileges, add the following to '/etc/sudoers.d/chef'. :
28
 
29
<pre>
30
echo "chef ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/chef
31
sudo chmod 0440 /etc/sudoers.d/chef
32
</pre>
33
 
34
If you are using a version of 'sudo' that doesn't support includes, you will
35
need to add the following to the '/etc/sudoers' file:
36
 
37
<pre>
38
chef ALL = (root) NOPASSWD:ALL
39
</pre>
40
 
41
> .. important: Do not change the file permissions on '/etc/sudoers'. Use a
42
43
>   suitable tool such as 'visudo'.
44
 
45
h4. Generate SSH Keys for Chef Clients
46
 
47
Chef's 'knife' tool can run 'ssh'. To streamline deployments, we 
48
recommend generating an SSH key pair without a passphrase for your 
49
Chef nodes and copying the public key(s) to your Chef nodes so that you 
50
can connect to them from your workstation using 'ssh' from 'knife'
51
without having to provide a password. To generate a key pair without 
52
a passphrase, execute the following on your Chef workstation. : 
53
 
54
<pre>
55
ssh-keygen
56
Generating public/private key pair.
57
Enter file in which to save the key (/ceph-admin/.ssh/id_rsa): 
58
Enter passphrase (empty for no passphrase): 
59
Enter same passphrase again: 
60
Your identification has been saved in /ceph-admin/.ssh/id_rsa.
61
Your public key has been saved in /ceph-admin/.ssh/id_rsa.pub.
62
</pre>
63
 
64
You may use RSA or DSA keys. Once you generate your keys, copy them to each 
65
OSD host. For example: 
66
 
67
<pre>
68
ssh-copy-id chef@your-node
69
</pre>
70
 
71
Consider modifying your '~/.ssh/config' file so that it defaults to 
72
logging in as 'chef' when no username is specified. : 
73
 
74
<pre>
75
Host myserver01
76
Hostname myserver01.fqdn-or-ip-address.com
77
User chef
78
Host myserver02
79
Hostname myserver02.fqdn-or-ip-address.com
80
User chef
81
</pre>
82
 
83
h4. Installing Ruby
84
 
85
Chef requires you to install Ruby. Use the version applicable to your current 
86
Linux distribution and install Ruby on all of your hosts. :
87
 
88
<pre>
89
sudo apt-get update
90
sudo apt-get install ruby
91
</pre>
92
93
Installing Chef and Chef Server on a Server
94
 
95
If you plan on hosting your Chef Server at Opscode you may skip this step, 
96
but you must make a note of the the fully qualified domain name or IP address
97
of your Chef Server for 'knife' and 'chef-client'.
98
 
99
First, add Opscode packages to your APT configuration. For example: 
100
 
101
<pre>
102
sudo tee /etc/apt/sources.list.d/chef.list << EOF
103
deb http://apt.opscode.com/ $(lsb_release -cs)-0.10 main  
104
deb-src http://apt.opscode.com/ $(lsb_release -cs)-0.10 main
105
EOF
106
</pre>
107
 
108
Next, you must request keys so that APT can verify the packages. Copy
109
and paste the following line into your command line: 
110
 
111
<pre>
112
sudo touch /etc/apt/trusted.gpg.d/opscode-keyring.gpg && sudo gpg --fetch-key http://apt.opscode.com/packages@opscode.com.gpg.key && sudo gpg --export 83EF826A | sudo apt-key --keyring /etc/apt/trusted.gpg.d/opscode-keyring.gpg add - && sudo gpg --yes --delete-key 83EF826A
113
</pre>
114
 
115
The key is only used by 'apt', so remove it from the 'root' keyring by
116
typing 'Y' when prompted to delete it.
117
 
118
Install the Opscode keyring, Chef and Chef server on the host designated
119
as your Chef Server. :
120
 
121
<pre>
122
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install opscode-keyring chef chef-server
123
</pre>
124
 
125
Enter the fully qualified domain name or IP address for your Chef server. For example:
126
 
127
<pre>
128
http://fqdn-or-ip-address.com:4000
129
</pre>
130
 
131
The Chef server installer will prompt you to enter a temporary password. Enter
132
a temporary password (*e.g.,* 'foo') and proceed with the installation. 
133
 
134
> .. tip: When prompted for a temporary password, you may press **OK**.
135
136
>   The installer wants you to re-enter the password to confirm it. To 
137
138
>   re-enter the password, you must press the **ESC** key.
139
 
140
Once the installer finishes and activates the Chef server, you may enter the 
141
fully qualified domain name or IP address in a browser to launch the 
142
Chef web UI. For example: 
143
 
144
<pre>
145
http://fqdn-or-ip-address.com:4000
146
</pre>
147
 
148
The Chef web UI will prompt you to enter the username and password.
149
 
150
<pre>
151
- login: 'admin'
152
- password: 'foo'
153
</pre>
154
 
155
Once you have entered the temporary password, the Chef web UI will prompt you
156
to enter a new password.
157
 
158
 
159
h4. Install Chef on all Remaining Hosts
160
 
161
Install Chef on all Chef Nodes and on the Chef Workstation (if it is not the 
162
same host as the Chef Server).
163
 
164
First, add Opscode packages to your APT configuration. For example: 
165
 
166
<pre>
167
sudo tee /etc/apt/sources.list.d/chef.list << EOF
168
deb http://apt.opscode.com/ $(lsb_release -cs)-0.10 main  
169
deb-src http://apt.opscode.com/ $(lsb_release -cs)-0.10 main
170
EOF
171
</pre>
172
 
173
Next, you must request keys so that APT can verify the packages. Copy
174
and paste the following line into your command line: 
175
 
176
<pre>
177
sudo touch /etc/apt/trusted.gpg.d/opscode-keyring.gpg && sudo gpg --fetch-key http://apt.opscode.com/packages@opscode.com.gpg.key && sudo gpg --export 83EF826A | sudo apt-key --keyring /etc/apt/trusted.gpg.d/opscode-keyring.gpg add - && sudo gpg --yes --delete-key 83EF826A
178
</pre>
179
180
The key is only used by 'apt', so remove it from the 'root' keyring by
181
typing 'Y' when prompted to delete it.
182
 
183
Install the Opscode keyring and Chef on all hosts other than the Chef Server. :
184
 
185
<pre>
186
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install opscode-keyring chef
187
</pre>
188
 
189
Enter the fully qualified domain name or IP address for your Chef server. 
190
For example:
191
 
192
<pre>
193
http://fqdn-or-ip-address.com:4000
194
</pre>
195
 
196
 
197
h4. Configuring Knife
198
 
199
Once you complete the Chef server installation, install 'knife' on the your
200
Chef Workstation. If the Chef server is a remote host, use 'ssh' to connect. : 
201
 
202
<pre>
203
ssh chef@fqdn-or-ip-address.com
204
</pre>
205
 
206
In the '/home/chef' directory, create a hidden Chef directory. : 
207
 
208
<pre>
209
mkdir -p ~/.chef
210
</pre>
211
 
212
The server generates validation and web UI certificates with read/write 
213
permissions for the user that installed the Chef server. Copy them from the
214
'/etc/chef' directory to the '~/.chef' directory. Then, change their 
215
ownership to the current user. :
216
 
217
<pre>
218
sudo cp /etc/chef/validation.pem /etc/chef/webui.pem ~/.chef && sudo chown $(id -u):$(id -g) ~/.chef/*.pem
219
</pre>
220
 
221
From the current user's home directory, configure 'knife' with an initial 
222
API client. : 
223
 
224
<pre>
225
knife configure -i
226
</pre>
227
 
228
The configuration will prompt you for inputs. Answer accordingly: 
229
 
230
# Where should I put the config file? [~/.chef/knife.rb]* Press **Enter** to accept the default value.
231
# Please enter the chef server URL:* If you are installing the client on the same host as the server, enter 'http://localhost:4000'. Otherwise, enter an appropriate URL for the server.
232
# Please enter a clientname for the new client:* Press **Enter** to accept the default value.
233
# Please enter the existing admin clientname:* Press **Enter** to accept the default value.
234
# Please enter the location of the existing admin client's private key:* Override the default value so that it points to the '.chef' directory.  (*e.g.,* '/home/chef/.chef/webui.pem')
235
# Please enter the validation clientname:* Press **Enter** to accept  the default value.
236
# Please enter the location of the validation key:* Override the  default value so that it points to the '.chef' directory. (*e.g.,* '/home/chef/.chef/validation.pem')
237
# Please enter the path to a chef repository (or leave blank):* Leave the entry field blank and press **Enter**.
238
239
h4. Add a Cookbook Path
240
 
241
Add 'cookbook_path' to the '~/.chef/knife.rb' configuration file
242
on your Chef workstation. For example:
243
 
244
<pre>
245
cookbook_path '/home/{user-name}/chef-cookbooks/'
246
</pre>
247
 
248
Then create the path if it doesn't already exist. :
249
 
250
<pre>
251
mkdir /home/{user-name}/chef-cookbooks
252
</pre>
253
 
254
This is where you will store local copies of cookbooks before uploading
255
them to the Chef server.
256
 
257
 
258
h4. Copy 'validation.pem' to Nodes
259
 
260
Copy the '/etc/chef/validation.pem' file from your Chef server to
261
each Chef Node. In a command line shell on the Chef Server, for each node, 
262
replace '{nodename}' in the following line with the node's host name and 
263
execute it. :
264
 
265
<pre>
266
sudo cat /etc/chef/validation.pem | ssh {nodename} "exec sudo tee /etc/chef/validation.pem >/dev/null"
267
</pre>
268
 
269
 
270
h4. Run 'chef-client' on each Chef Node
271
 
272
Run the 'chef-client' on each Chef Node so that the nodes
273
register with the Chef server. : 
274
 
275
<pre>
276
ssh chef-node
277
sudo chef-client
278
</pre>
279
 
280
h4. Verify Nodes
281
 
282
Verify that you have setup all the hosts you want to use as 
283
Chef nodes. : 
284
 
285
<pre>
286
knife node list
287
</pre>
288
 
289
A list of the nodes you've configured should appear.
290
 
291
Read on for information on using Chef to deploy your Ceph cluster.
292
 
293
> Chef Architecture Introduction: http://wiki.opscode.com/display/chef...e+Introduction
294
295
> Chef Server at Opscode: http://www.opscode.com/hosted-chef/
296
297
> Installing Chef Client on Ubuntu or Debian: http://wiki.opscode.com/display/chef...untu+or+Debian
298
299
> Installing Chef Server on Debian or Ubuntu using Packages: http://wiki.opscode.com/display/chef...using+Packages
300
301
> Knife Bootstrap: http://wiki.opscode.com/display/chef/Knife+Bootstrap
302
 
303
 
304
h2. %{color:black}Deploying Ceph%
305
306
Now it's time to deploy Ceph.   For Chef installation instructions, see above.
307
 
308
h3. Clone the Required Cookbooks
309
 
310
To get the cookbooks for Ceph, clone them from git.:
311
 
312
<pre>
313
cd ~/chef-cookbooks
314
git clone https://github.com/opscode-cookbooks/apache2.git
315
git clone https://github.com/ceph/ceph-cookbooks.git ceph
316
</pre>
317
 
318
 
319
h4. Add the Required Cookbook Paths
320
 
321
If you added a default cookbook path when you installed Chef, 'knife'
322
may be able to upload the cookbook you've cloned to your cookbook path
323
directory without further configuration. If you used a different path, 
324
or if the cookbook repository you cloned has a different tree structure, 
325
add the required cookbook path to your 'knife.rb' file. The 
326
'cookbook_path' setting takes a string or an array of strings. 
327
For example, you can replace a string path with an array of string paths:
328
 
329
<pre>
330
cookbook_path '/home/{user-name}/chef-cookbooks/'
331
</pre> 
332
Becomes:
333
 
334
<pre>
335
cookbook_path [
336
'/home/{user-name}/chef-cookbooks/', 
337
'/home/{user-name}/chef-cookbooks/{another-directory}/',
338
'/some/other/path/to/cookbooks/'
339
]
340
</pre>
341
 
342
 
343
h4. Install the Cookbooks
344
 
345
To install Ceph, you must upload the Ceph cookbooks and the Apache cookbooks
346
(for use with RADOSGW) to your Chef server. : 
347
 
348
<pre>
349
knife cookbook upload apache2 ceph
350
</pre>
351
 
352
 
353
h4. Configure your Ceph Environment
354
 
355
The Chef server can support installation of software for multiple environments.
356
The environment you create for Ceph requires an 'fsid', the secret for
357
your monitor(s) if you are running Ceph with 'cephx' authentication, and
358
the host name (i.e., short name) for your monitor hosts.
359
 
360
> .. tip: Open an empty text file to hold the following values until you create
361
>    your Ceph environment.
362
 
363
For the filesystem ID, use 'uuidgen' from the 'uuid-runtime' package to 
364
generate a unique identifier.
365
 
366
<pre>
367
uuidgen -r
368
</pre>
369
 
370
For the monitor(s) secret(s), use 'ceph-authtool' to generate the secret(s):
371
 
372
<pre>
373
sudo apt-get update
374
sudo apt-get install ceph-common
375
ceph-authtool /dev/stdout --name=mon. --gen-key  
376
</pre>
377
 
378
The secret is the value to the right of "key =", and should look something 
379
like this:
380
 
381
<pre>
382
AQBAMuJPINJgFhAAziXIrLvTvAz4PRo5IK/Log==
383
</pre>
384
 
385
To create an environment for Ceph, set a command line editor. For example:
386
 
387
<pre>
388
export EDITOR=vim
389
</pre>
390
 
391
Then, use 'knife' to create an environment.
392
 
393
<pre>
394
knife environment create {env-name}
395
</pre>
396
 
397
For example:
398
 
399
<pre>
400
knife environment create Ceph
401
</pre>
402
 
403
A JSON file will appear. Perform the following steps: 
404
 
405
# Enter a description for the environment. 
406
# In '"default_attributes": {}', add '"ceph" : {}'.
407
# Within '"ceph" : {}', add '"monitor-secret":'.
408
# Immediately following '"monitor-secret":' add the key you generated within quotes, followed by a comma.
409
# Within '"ceph":{}' and following the 'monitor-secret' key-value pair, add '"config": {}'
410
# Within '"config": {}' add '"fsid":'.
411
# Immediately following '"fsid":', add the unique identifier you generated within quotes, followed by a comma.
412
# Within '"config": {}' and following the 'fsid' key-value pair, add '"mon_initial_members":'
413
# Immediately following '"mon_initial_members":', enter the initial monitor host names.
414
 
415
You may also set Ceph settings within '"config": {}'.
416
 
417
For example:
418
<pre>
419
 
420
    "default_attributes" : {
421
        "ceph": {
422
            "monitor-secret": "{replace-with-generated-secret}",
423
            "config": {
424
                "fsid": "{replace-with-generated-uuid}",
425
                "mon_initial_members": "{replace-with-monitor-hostname(s)}",
426
                "global": {
427
                    "public network": "xxx.xxx.xxx.xxx/yy",
428
                    "cluster network": "xxx.xxx.xxx.xxx/yy"
429
                },
430
                "osd": {
431
                    "osd journal size": "1000"
432
                }
433
            }
434
        }
435
    }
436
</pre>
437
 
438
Will generate the following ceph.conf:
439
 
440
<pre>
441
    [global]
442
        fsid = <fsid>
443
        mon initial members = X,Y,Z
444
        mon host = ipX:port, ipY:port, ipZ:port ;mon host is auto generated
445
        public network = xxx.xxx.xxx.xxx/yy
446
        cluster network = xxx.xxx.xxx.xxx/yy
447
    [osd]
448
        osd journal size = 1000
449
</pre>
450
 
451
Advanced users (i.e., developers and QA) may also add '"branch": "{branch}"'
452
to '"ceph": {}'. Valid values are 'stable', 'testing', 'dev'.
453
You can specify which stable release (e.g. argonaut, bobtail) or which dev
454
branch to use with '"version": "{version}"' within '"ceph": {}'.
455
If 'version' is not specified for 'stable', the latest stable release
456
will be used. 'testing' does not require 'version'.
457
 
458
The Ceph cookbook will, by default, use the official Ceph repositories. If you wish to use your own repositories you can specify them, in the Ceph environment, within '"ceph": {}' like so:
459
460
<pre>
461
"platform_family": {
462
    "branch": {
463
        "repository": "mylocalcephrepo"
464
        "repository_key": "mylocalcephrepokey"
465
    }
466
}
467
</pre>
468
469
platform_family can be:
470
* rhel: For RHEL and CentOS
471
* debian: For Debian and Ubuntu
472
* suse: For OpenSUSE and SLES
473
* fedora: For Fedora
474
branch can be:
475
* stable
476
* testing
477
* dev
478
479
h4. Configure the Roles
480
 
481
Navigate to the Ceph cookbooks directory. : 
482
 
483
<pre>
484
cd ~/chef-cookbooks/ceph
485
</pre>
486
 
487
Create roles for OSDs, monitors, metadata servers, and RADOS Gateways from
488
their respective role files. :
489
 
490
<pre>
491
knife role from file roles/ceph-osd.rb
492
knife role from file roles/ceph-mon.rb
493
knife role from file roles/ceph-mds.rb
494
knife role from file roles/ceph-radosgw.rb
495
</pre>
496
 
497
h4. Configure Nodes
498
 
499
You must configure each node you intend to include in your Ceph cluster. 
500
Identify nodes for your Ceph cluster. :
501
 
502
<pre>
503
knife node list
504
</pre>
505
 
506
> .. note: for each host where you installed Chef and executed 'chef-client', 
507
508
>   the Chef server should have a minimal node configuration. You can create
509
510
>   additional nodes with 'knife node create {node-name}'.
511
 
512
For each node you intend to use in your Ceph cluster, configure the node 
513
as follows: 
514
 
515
<pre>
516
knife node edit {node-name}
517
</pre>
518
 
519
The node configuration should appear in your text editor. Change the 
520
'chef_environment' value to 'Ceph' (or whatever name you set for your
521
Ceph environment). 
522
 
523
In the 'run_list', add '"recipe[ceph:repo]",' to all nodes as
524
the first setting, so that Chef can install or update the necessary packages. 
525
Then, add at least one of: 
526
 
527
<pre>
528
"role[ceph-mon]"
529
"role[ceph-osd]"
530
"role[ceph-mds]"
531
"role[ceph-radosgw]"
532
</pre>
533
 
534
If you add more than one role, separate them with a comma. Run 'hostname'
535
on your command line, and replace the '{hostname}' setting of the 'name' 
536
key to the host name for the node. :
537
 
538
<pre>
539
{
540
  "chef_environment": "Ceph",
541
  "name": "{hostname}",
542
  "normal": {
543
    "tags": [
544
    ]
545
  },
546
  "run_list": [
547
    "role[ceph-mon]",
548
    "role[ceph-mds]"
549
  ]
550
}
551
</pre>
552
 
553
 
554
h4. Deploy OSDs
555
 
556
Configuring a node with an OSD role tells Chef that the node will run at
557
least one OSD. However, you may run many OSDs on one host. For example, 
558
you may run one 'ceph-osd' daemon for each data disk on the system. 
559
To tell Chef to deploy OSDs, edit the node and add the following
560
within '"normal": {}':
561
 
562
<pre>
563
    "ceph": {
564
        "osd_devices": [
565
            {
566
                "device": "/dev/...",
567
                "journal": "/dev/..."
568
            },
569
            {
570
                "device": "/dev/...",
571
                "dmcrypt": true
572
            }
573
        ]
574
    }
575
</pre>
576
 
577
Supported values are 'device', 'journal', 'dmcrypt' (deactivated by default).
578
 
579
> .. note: dmcrypt is only supported starting with Cuttlefish
580
 
581
 
582
h4. Run 'chef-client' on each Node
583
 
584
Once you have completed the preceding steps, you must run 'chef-client' 
585
on each node. For example:
586
 
587
<pre>
588
sudo chef-client
589
</pre>
590
 
591
 
592
h4. Proceed to Operating the Cluster
593
 
594
Once you complete the deployment, you may begin operating your cluster.
595
See "'Operating a Cluster'":http://ceph.com/docs/master/rados/operations/operating/ for details.
596
 
597
 
598
> Managing Cookbooks with Knife: http://wiki.opscode.com/display/chef...oks+With+Knife