配置Docker的devicemapper(direct-lvm)

1.安装lvm2

  1. # ubuntu
  2. apt-get install lvm2
  3. # centos
  4. yum install lvm2

2.创建PV

  1. # 先查看一下预分配的磁盘名
  2. fdisk -l
  3. # 在这个示例中是 /dev/vdb 这个设备
  4. Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors
  5. Units = sectors of 1 * 512 = 512 bytes
  6. Sector size (logical/physical): 512 bytes / 512 bytes
  7. I/O size (minimum/optimal): 512 bytes / 512 bytes
  8. Disk label type: dos
  9. Disk identifier: 0x0008e3b4
  10. Device Boot Start End Blocks Id System
  11. /dev/vda1 * 2048 209713151 104855552 83 Linux
  12. Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
  13. Units = sectors of 1 * 512 = 512 bytes
  14. Sector size (logical/physical): 512 bytes / 512 bytes
  15. I/O size (minimum/optimal): 512 bytes / 512 bytes
  16. # 创建pv
  17. pvcreate /dev/vdb
  18. Physical volume "/dev/vdb" successfully created.

3.创建VG

  1. vgcreate docker /dev/vdb
  2. Volume group "docker" successfully created

4.查看VG信息

  1. vgdisplay docker
  2. --- Volume group ---
  3. VG Name docker
  4. System ID
  5. Format lvm2
  6. Metadata Areas 1
  7. Metadata Sequence No 1
  8. VG Access read/write
  9. VG Status resizable
  10. MAX LV 0
  11. Cur LV 0
  12. Open LV 0
  13. Max PV 0
  14. Cur PV 1
  15. Act PV 1
  16. VG Size 100.00 GiB
  17. PE Size 4.00 MiB
  18. Total PE 25599
  19. Alloc PE / Size 0 / 0
  20. Free PE / Size 25599 / 100.00 GiB
  21. VG UUID 4sW1dh-4i2Z-cJM0-es3b-2hbv-0oji-t4ZfRO

5.创建thinpool,数据LV的大小为VG的95%

  1. lvcreate --wipesignatures y -n thinpool docker -l 95%VG
  2. Logical volume "thinpool" created.

6.创建pool,元数据的大小为VG的1%

  1. lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
  2. Logical volume "thinpoolmeta" created.

7.转换pool为thinpool格式

  1. lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
  2. WARNING: Converting logical volume docker/thinpool and docker/thinpoolmeta to thin pool's data and metadata volumes with metadata wiping.
  3. THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
  4. Converted docker/thinpool to thin pool.

8.调整lvm配置

  1. vi /etc/lvm/profile/docker-thinpool.profile
  2. activation {
  3. thin_pool_autoextend_threshold=80
  4. thin_pool_autoextend_percent=20
  5. }

9.lvchange应用配置

  1. lvchange --metadataprofile docker-thinpool docker/thinpool
  2. Logical volume docker/thinpool changed.

10.查看卷信息,验证monitord的状态

  1. lvs -o+seg_monitor
  2. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Monitor
  3. thinpool docker twi-a-t--- 95.00g 0.02 0.01 monitored

修改Docker配置

  1. vi /etc/goodrain/envs/docker.sh
  2. DOCKER_OPTS="-H 0.0.0.0:2376 \
  3. -H unix:///var/run/docker.sock \
  4. --bip=172.30.42.1/16 \
  5. --insecure-registry goodrain.me \
  6. --storage-driver=devicemapper \
  7. --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool \
  8. --storage-opt=dm.use_deferred_removal=true \
  9. --storage-opt=dm.use_deferred_deletion=true \
  10. --userland-proxy=false"

重启Docker

  1. systemctl restart docker

查看lvmz状态

  1. # 查看服务状态
  2. journalctl -fu dm-event.service
  3. # 查看对应的设备
  4. lsblk -I '253' |grep -v vdb