配置direct-lvm模式
1. 停止Docker
systemctl stop docker
2. 安装依赖包
device-mapper-persistent-data,lvm2, and all dependencies
3. 创建物理卷/dev/md123p1来替换块设备
[root@localhost ~]# pvcreate /dev/md123p1
WARNING: ext4 signature detected on /dev/md123p1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/md123p1.
Physical volume "/dev/md123p1" successfully created.
4. 用vgcreate命令在同一个设备上创建docker卷组
[root@localhost ~]# vgcreate docker /dev/md123p1
Volume group "docker" successfully created
5. 用lvcreate命令创建thinpool(数据)和thinpoolmeta(元数据)两个逻辑卷
最后一个参数指定空闲空间的数量,以允许在空间运行低时自动扩展数据或元数据,作为临时的权宜之计。这些是推荐的值。
[root@localhost ~]# lvcreate --wipesignatures y -n thinpool docker -l 95%VG
Logical volume "thinpool" created.
[root@localhost ~]# lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
Logical volume "thinpoolmeta" created.
6. 用lvconvert命令把thinpool数据卷和thinpoolmeta元数据卷换为一个精简池,且此精简池使用原数据卷的名字
[root@localhost ~]# lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
WARNING: Maximum supported pool metadata size is 15.81 GiB.
WARNING: Converting logical volume docker/thinpool and docker/thinpoolmeta to thin pool's data and metadata volumes with metadata wiping.
THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
Converted docker/thinpool_tdata to thin pool.
7. 通过lvm profile配置精简池的自动扩容
$ sudo vi/etc/lvm/profile/docker-thinpool.profile
8. 指定thin_pool_autoextend_threshold和thin_pool_autoextend_percent的值
thin_pool_autoextend_threshold:当达到使用空间的指定阈值(百分数)后,lvm就会试图尝试自动扩展可用的空间(100=禁用)。
thin_pool_autoextend_percent:当磁盘每次达到上面定义的阈值后,自动再扩展的百分比数(0=禁用)。
示例:
当磁盘使用达到80%时,再扩展当前容量的10%。更新/etc/lvm/profile/docker-thinpool.profile
activation {
thin_pool_autoextend_threshold=80
thin_pool_autoextend_percent=10
}
保存文件。
9. 用lvchange命令激活LVM profile
[root@localhost ~]# lvchange --metadataprofile docker-thinpool docker/thinpool
Logical volume docker/thinpool changed.
10. 对主机上的逻辑卷启用监视
如果没有这个步骤,即使在LVM配置文件出现时也不会发生自动扩展。
[root@localhost ~]# lvs -o+seg_monitor
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Monitor
thinpool docker twi-a-t--- 3.28t 0.00 0.02 monitored
11. 备份Docker原有数据
如果曾经在这个主机上运行过Docker,或者如果/var/ lib/docker存在,那么将它移出后,Docker就可以使用新的LVM池来存储镜像和容器的内容了。
$ mkdir /var/lib/docker.bk
$ mv /var/lib/docker/*/var/lib/docker.bk
12. 编辑/etc/docker/daemon.json
配置devicemapper存储驱动程序所需的选项。如果该文件以前是空的,那么现在应该包含以下内容:
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://vaflkxbk.mirror.aliyun.com"],
"storage-driver":"devicemapper",
"storage-opts": [
"dm.thinpooldev=/dev/mapper/docker-thinpool",
"dm.use_deferred_removal=true",
"dm.use_deferred_deletion=true"
]
}
注意:
延迟删除选项,dm.use_deferred_deletion=true,在使用默认内核版本3.18时还不支持RHEL、CentOS或Ubuntu 14.04。
13. 启动Docker
systemd:
$ sudo systemctl start docker
service:
$ sudo service docker start
14. 查看Docker启动信息
$ docker info
[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.12.0-ce
Storage Driver: devicemapper
Pool Name: docker-thinpool
Pool Blocksize: 524.3kB
Base Device Size: 10.74GB
Backing Filesystem: xfs
Udev Sync Supported: true
Data Space Used: 20.45MB
Data Space Total: 3.611TB
Data Space Available: 3.611TB
Metadata Space Used: 2.822MB
Metadata Space Total: 16.98GB
Metadata Space Available: 16.98GB
Thin Pool Minimum Free Space: 361.1GB
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.140-RHEL7 (2017-05-03)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 24
Total Memory: 125.7GiB
Name: localhost.localdomain
ID: J3U3:BRQF:4WTY:S725:ALZ4:DJPR:IF5I:JRRP:CYLU:LMNG:LT56:EIGM
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
15. 验证配置正确后,就可以删除/var/lib/docker.bk目录了
$ rm -rf /var/lib/docker.bk