Browse code

Fix thin pool devicemapper docs overwritten

Signed-off-by: Matt Bentley <matt.bentley@docker.com>

Matt Bentley authored on 2016/05/25 21:45:51
Showing 2 changed files
... ...
@@ -212,7 +212,7 @@ a `direct-lvm` configuration.
212 212
 > and have images you want to keep, `push` them Docker Hub or your private
213 213
 > Docker Trusted Registry before attempting this procedure.
214 214
 
215
-The procedure below will create a 90GB data volume and 4GB metadata volume to
215
+The procedure below will create a logical volume configured as a thin pool to
216 216
 use as backing for the storage pool. It assumes that you have a spare block
217 217
 device at `/dev/xvdf` with enough free space to complete the task. The device
218 218
 identifier and volume sizes may be be different in your environment and you
... ...
@@ -221,106 +221,146 @@ assumes that the Docker daemon is in the `stopped` state.
221 221
 
222 222
 1. Log in to the Docker host you want to configure and stop the Docker daemon.
223 223
 
224
-2. If it exists, delete your existing image store by removing the
225
-`/var/lib/docker` directory.
224
+2. Install the LVM2 package.
225
+	The LVM2 package includes the userspace toolset that provides logical volume
226
+	management facilities on linux.
227
+
228
+3. Create a physical volume replacing `/dev/xvdf` with your block device.
226 229
 
227 230
 	```bash
228
-	$ sudo rm -rf /var/lib/docker
231
+	$ pvcreate /dev/xvdf
229 232
 	```
230 233
 
231
-3. Create an LVM physical volume (PV) on your spare block device using the
232
-`pvcreate` command.
234
+4. Create a 'docker' volume group.
233 235
 
234 236
 	```bash
235
-	$ sudo pvcreate /dev/xvdf
236
-	Physical volume `/dev/xvdf` successfully created
237
+	$ vgcreate docker /dev/xvdf
237 238
 	```
238 239
 
239
-	The device identifier may be different on your system. Remember to substitute
240
-	your value in the command above. If your host is running on AWS EC2, you may
241
-	need to install `lvm2` and <a href="http://goo.gl/Q5pUwG"
242
-	target="_blank">attach an EBS device</a> to use this procedure.
240
+5. Create a thin pool named `thinpool`.
241
+
242
+	In this example, the data logical is 95% of the 'docker' volume group size.
243
+	Leaving this free space allows for auto expanding of either the data or
244
+	metadata if space runs low as a temporary stopgap.
245
+
246
+	```bash
247
+	$ lvcreate --wipesignatures y -n thinpool docker -l 95%VG
248
+	$ lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
249
+	```
243 250
 
244
-4. Create a new volume group (VG) called `vg-docker` using the PV created in
245
-the previous step.
251
+6. Convert the pool to a thin pool.
246 252
 
247 253
 	```bash
248
-	$ sudo vgcreate vg-docker /dev/xvdf
249
-	Volume group `vg-docker` successfully created
254
+	$ lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
250 255
 	```
251 256
 
252
-5. Create a new 90GB logical volume (LV) called `data` from space in the
253
-`vg-docker` volume group.
257
+7. Configure autoextension of thin pools via an `lvm` profile.
254 258
 
255 259
 	```bash
256
-	$ sudo lvcreate -L 90G -n data vg-docker
257
-	Logical volume `data` created.
260
+	$ vi /etc/lvm/profile/docker-thinpool.profile
261
+	```
262
+
263
+8. Specify 'thin_pool_autoextend_threshold' value.
264
+
265
+	The value should be the percentage of space used before `lvm` attempts
266
+	to autoextend the available space (100 = disabled).
267
+
268
+	```
269
+	thin_pool_autoextend_threshold = 80
270
+	```
271
+
272
+9. Modify the `thin_pool_autoextend_percent` for when thin pool autoextension occurs.
273
+
274
+	The value's setting is the perentage of space to increase the thin pool (100 =
275
+	disabled)
276
+
277
+	```
278
+	thin_pool_autoextend_percent = 20
258 279
 	```
259 280
 
260
-	The command creates an LVM logical volume called `data` and an associated
261
-	block device file at `/dev/vg-docker/data`. In a later step, you instruct the
262
-	`devicemapper` storage driver to use this block device to store image and
263
-	container data.
281
+10. Check your work, your `docker-thinpool.profile` file should appear similar to the following:
264 282
 
265
-	If you receive a signature detection warning, make sure you are working on
266
-	the correct devices before continuing. Signature warnings indicate that the
267
-	device you're working on is currently in use by LVM or has been used by LVM in
268
-	the past.
283
+	An example `/etc/lvm/profile/docker-thinpool.profile` file:
269 284
 
270
-6. Create a new logical volume (LV) called `metadata` from space in the
271
-`vg-docker` volume group.
285
+	```
286
+	activation {
287
+		thin_pool_autoextend_threshold=80
288
+		thin_pool_autoextend_percent=20
289
+	}
290
+	```
291
+
292
+11. Apply your new lvm profile
272 293
 
273 294
 	```bash
274
-	$ sudo lvcreate -L 4G -n metadata vg-docker
275
-	Logical volume `metadata` created.
295
+	$ lvchange --metadataprofile docker-thinpool docker/thinpool
276 296
 	```
277 297
 
278
-	This creates an LVM logical volume called `metadata` and an associated
279
-	block device file at `/dev/vg-docker/metadata`. In the next step you instruct
280
-	the `devicemapper` storage driver to use this block device to store image and
281
-	container metadata.
298
+12. Verify the `lv` is monitored.
282 299
 
283
-7. Start the Docker daemon with the `devicemapper` storage driver and the
284
-`--storage-opt` flags.
300
+	```bash
301
+	$ lvs -o+seg_monitor
302
+	```
285 303
 
286
-	The `data` and `metadata` devices that you pass to the `--storage-opt`
287
-	options were created in the previous steps.
304
+13. If the Docker daemon was previously started, clear your graph driver directory.
305
+
306
+	Clearing your graph driver removes any images, containers, and volumes in your
307
+	Docker installation.
288 308
 
289 309
 	```bash
290
-	$ sudo docker daemon --storage-driver=devicemapper --storage-opt dm.datadev=/dev/vg-docker/data --storage-opt dm.metadatadev=/dev/vg-docker/metadata &
291
-	[1] 2163
292
-	[root@ip-10-0-0-75 centos]# INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)
293
-	INFO[0027] Option DefaultDriver: bridge
294
-	INFO[0027] Option DefaultNetwork: bridge
295
-	<-- output truncated -->
296
-	INFO[0027] Daemon has completed initialization
297
-	INFO[0027] Docker daemon commit=1b09a95 graphdriver=aufs version=1.11.0-dev
310
+	$ rm -rf /var/lib/docker/*
298 311
 	```
299 312
 
300
-	It is also possible to set the `--storage-driver` and `--storage-opt` flags
301
-	in the Docker config file and start the daemon normally using the `service` or
302
-	`systemd` commands.
313
+14. Configure the Docker daemon with specific devicemapper options.
303 314
 
304
-8. Use the `docker info` command to verify that the daemon is using `data` and
305
-`metadata` devices you created.
315
+	There are two ways to do this. You can set options on the commmand line if you start the daemon there:
306 316
 
307 317
 	```bash
308
-	$ sudo docker info
309
-	INFO[0180] GET /v1.20/info
310
-	Containers: 0
311
-	Images: 0
312
-	Storage Driver: devicemapper
313
-	 Pool Name: docker-202:1-1032-pool
314
-	 Pool Blocksize: 65.54 kB
315
-	 Backing Filesystem: xfs
316
-	 Data file: /dev/vg-docker/data
317
-	 Metadata file: /dev/vg-docker/metadata
318
-	[...]
318
+	--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true
319 319
 	```
320 320
 
321
-	The output of the command above shows the storage driver as `devicemapper`.
322
-	The last two lines also confirm that the correct devices are being used for
323
-	the `Data file` and the `Metadata file`.
321
+	You can also set them for startup in the `daemon.json` configuration, for example:
322
+
323
+	```json
324
+	 {
325
+		 "storage-driver": "devicemapper",
326
+		 "storage-opts": [
327
+			 "dm.thinpooldev=/dev/mapper/docker-thinpool",
328
+			 "dm.use_deferred_removal=true"
329
+		 ]
330
+	 }
331
+	```
332
+
333
+15. If using systemd and modifying the daemon configuration via unit or drop-in file, reload systemd to scan for changes.
334
+
335
+	```bash
336
+	$ systemctl daemon-reload
337
+	```
338
+
339
+16. Start the Docker daemon.
340
+
341
+	```bash
342
+	$ systemctl start docker
343
+	```
344
+
345
+After you start the Docker daemon, ensure you monitor your thin pool and volume
346
+group free space. While the volume group will auto-extend, it can still fill
347
+up. To monitor logical volumes, use `lvs` without options or `lvs -a` to see tha
348
+data and metadata sizes. To monitor volume group free space, use the `vgs` command.
349
+
350
+Logs can show the auto-extension of the thin pool when it hits the threshold, to
351
+view the logs use:
352
+
353
+```bash
354
+$ journalctl -fu dm-event.service
355
+```
356
+
357
+If you run into repeated problems with thin pool, you can use the
358
+`dm.min_free_space` option to tune the Engine behavior. This value ensures that
359
+operations fail with a warning when the free space is at or near the minimum.
360
+For information, see <a
361
+href="../../../reference/commandline/daemon/#storage-driver-options"
362
+target="_blank">the storage driver options in the Engine daemon reference</a>.
363
+
324 364
 
325 365
 ### Examine devicemapper structures on the host
326 366
 
... ...
@@ -329,20 +369,20 @@ You can use the `lsblk` command to see the device files created above and the
329 329
 
330 330
 ```bash
331 331
 $ sudo lsblk
332
-NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
333
-xvda                       202:0    0    8G  0 disk
334
-└─xvda1                    202:1    0    8G  0 part /
335
-xvdf                       202:80   0   10G  0 disk
336
-├─vg--docker-data          253:0    0   90G  0 lvm
337
-│ └─docker-202:1-1032-pool 253:2    0   10G  0 dm
338
-└─vg--docker-metadata      253:1    0    4G  0 lvm
339
-  └─docker-202:1-1032-pool 253:2    0   10G  0 dm
332
+NAME			   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
333
+xvda			   202:0	0	 8G  0 disk
334
+└─xvda1			   202:1	0	 8G  0 part /
335
+xvdf			   202:80	0	10G  0 disk
336
+├─vg--docker-data		   253:0	0	90G  0 lvm
337
+│ └─docker-202:1-1032-pool 253:2	0	10G  0 dm
338
+└─vg--docker-metadata	   253:1	0	 4G  0 lvm
339
+  └─docker-202:1-1032-pool 253:2	0	10G  0 dm
340 340
 ```
341 341
 
342 342
 The diagram below shows the image from prior examples updated with the detail
343 343
 from the `lsblk` command above.
344 344
 
345
-![](http://farm1.staticflickr.com/703/22116692899_0471e5e160_b.jpg)
345
+![](images/lsblk-diagram.jpg)
346 346
 
347 347
 In the diagram, the pool is named `Docker-202:1-1032-pool` and spans the `data`
348 348
 and `metadata` devices created earlier. The `devicemapper` constructs the pool
... ...
@@ -427,12 +467,10 @@ The `Data Space` values show that the pool is 100GB total. This example extends
427 427
 3. Verify the file size changed.
428 428
 
429 429
 	```bash
430
-	$ sudo ls -al /var/lib/docker/devicemapper/devicemapper/
431
-	total 1175492
432
-	drwx------ 2 root root         4096 Mar 29 02:45 .
433
-	drwx------ 5 root root         4096 Mar 29 02:48 ..
434
-	-rw------- 1 root root 214748364800 Mar 31 11:20 data
435
-	-rw------- 1 root root   2147483648 Mar 31 11:17 metadata
430
+	$ sudo ls -lh /var/lib/docker/devicemapper/devicemapper/
431
+	total 1.2G
432
+	-rw------- 1 root root 200G Apr 14 08:47 data
433
+	-rw------- 1 root root 2.0G Apr 19 13:27 metadata
436 434
 	```
437 435
 
438 436
 4. Reload data loop device
... ...
@@ -450,13 +488,14 @@ The `Data Space` values show that the pool is 100GB total. This example extends
450 450
 	a. Get the pool name first.
451 451
 
452 452
 	```bash
453
-	$ sudo dmsetup status docker-8:1-123141-pool: 0 209715200 thin-pool 91
453
+	$ sudo dmsetup status | grep pool
454
+	docker-8:1-123141-pool: 0 209715200 thin-pool 91
454 455
 	422/524288 18338/1638400 - rw discard_passdown queue_if_no_space -
455 456
 	```
456 457
 
457 458
 	The name is the string before the colon.
458 459
 
459
- 	b. Dump the device mapper table first.
460
+	b. Dump the device mapper table first.
460 461
 
461 462
 	```bash
462 463
 	$ sudo dmsetup table docker-8:1-123141-pool
... ...
@@ -469,6 +508,7 @@ The `Data Space` values show that the pool is 100GB total. This example extends
469 469
 	reflect the new number of 512 byte sectors in the disk. For example, as the
470 470
 	new loop size is 200GB, change the second number to 419430400.
471 471
 
472
+
472 473
 	d. Reload the thin pool with the new sector number
473 474
 
474 475
 	```bash
... ...
@@ -533,7 +573,7 @@ disk partition.
533 533
 
534 534
 	c. Calculate the real total sectors of the thin pool now. we can use `blockdev` to get the real size of data lv.
535 535
 
536
-	Change the second number of the table info (i.e. the disk end sector) to
536
+	Change the second number of the table info (i.e. the number of sectors) to
537 537
 	reflect the new number of 512 byte sectors in the disk. For example, as the
538 538
 	new data `lv` size is `264132100096` bytes, change the second number to
539 539
 	`515883008`.
... ...
@@ -592,8 +632,8 @@ There are several other things that impact the performance of the
592 592
 
593 593
 - **The mode.** The default mode for Docker running the `devicemapper` storage
594 594
   driver is `loop-lvm`. This mode uses sparse files and suffers from poor
595
-  performance. It is **not recommended for production**. The recommended mode
596
-  for production environments is `direct-lvm` where the storage driver writes
595
+  performance. It is **not recommended for production**. The recommended mode for
596
+  production environments is `direct-lvm` where the storage driver writes
597 597
   directly to raw block devices.
598 598
 
599 599
 - **High speed storage.** For best performance you should place the `Data file`
... ...
@@ -601,10 +641,10 @@ There are several other things that impact the performance of the
601 601
   attached storage or from a SAN or NAS array.
602 602
 
603 603
 - **Memory usage.** `devicemapper` is not the most memory efficient Docker
604
-  storage driver. Launching *n* copies of the same container loads *n* copies
605
-  of its files into memory. This can have a memory impact on your Docker host.
606
-  As a result, the `devicemapper` storage driver may not be the best choice for
607
-  PaaS and other high density use cases.
604
+  storage driver. Launching *n* copies of the same container loads *n* copies of
605
+  its files into memory. This can have a memory impact on your Docker host. As a
606
+  result, the `devicemapper` storage driver may not be the best choice for PaaS
607
+  and other high density use cases.
608 608
 
609 609
 One final point, data volumes provide the best and most predictable
610 610
 performance. This is because they bypass the storage driver and do not incur
... ...
@@ -618,4 +658,4 @@ data volumes.
618 618
 * [Select a storage driver](selectadriver.md)
619 619
 * [AUFS storage driver in practice](aufs-driver.md)
620 620
 * [Btrfs storage driver in practice](btrfs-driver.md)
621
-* [daemon reference](../../reference/commandline/dockerd#storage-driver-options)
621
+* [daemon reference](../../reference/commandline/daemon#storage-driver-options)
622 622
new file mode 100644
623 623
Binary files /dev/null and b/docs/userguide/storagedriver/images/lsblk-diagram.jpg differ