1.保存文件并关闭docker守护进程

2.安装 LVM2 包,该包中包含逻辑分区所需的依赖文件

$ sudo apt-get install lvm2

3.选择一块空闲磁盘,并创建逻辑分区

$ sudo pvcreate /dev/xvdf

4.创建docker 分区组

$ sudo vgcreate docker /dev/xvdf

5.创建一个 thin pool 并命名为 thinpool.

In this example, the data logical is 95% of the ‘docker’ volume group size. Leaving this free space allows for auto expanding of either the data or metadata if space runs low as a temporary stopgap.

$ lvcreate --wipesignatures y -n thinpool docker -l 95%VG
$ lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG

6.将该池转化为thinpool

$ lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta

7.配置自动扩容文件

$ vim /etc/lvm/profile/docker-thinpool.profile

Specify ‘thin_pool_autoextend_threshold’ value.

The value should be the percentage of space used before lvm attempts to autoextend the available space (100 = disabled).

thin_pool_autoextend_threshold = 80

Modify the thin_pool_autoextend_percent for when thin pool autoextension occurs.

The value’s setting is the perentage of space to increase the thin pool (100 = disabled)

thin_pool_autoextend_percent = 20

8.Check your work, your docker-thinpool.profile file should appear similar to the following:

An example /etc/lvm/profile/docker-thinpool.profile file:

activation {
thin_pool_autoextend_threshold=80
thin_pool_autoextend_percent=20
}
9.提交lvm配置文件

$ sudo lvchange --metadataprofile docker-thinpool docker/thinpool

10.确认逻辑分区已经被显示

$ sudo lvs -o+seg_monitor

11.清理docker文件夹

$ rm -rf /var/lib/docker/*

12.将以下命令加入/etc/default/docker
–storage-driver=devicemapper –storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool –storage-opt dm.use_deferred_removal=true

13.If using systemd and modifying the daemon configuration via unit or drop-in file, reload systemd to scan for changes.

$ sudo systemctl daemon-reload

14.开启docker守护进程

$ sudo systemctl start docker

15.use lvs without options or lvs -a to see tha data and metadata sizes. To monitor volume group free space, use the vgs command.

16.查看自动扩容的日志

$ journalctl -fu dm-event.service

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐