docker devicemapper loop_lvm 轉爲生產環境使用的direcrt_lvm

轉自官網:https://docs.docker.com/storage/storagedriver/device-mapper-driver/#manage-devicemapper
後續的擴容監控官網有詳細的介紹

Configure direct-lvm mode manually

The procedure below creates a logical volume configured as a thin pool to use as backing for the storage pool. It assumes that you have a spare block device at /dev/xvdf with enough free space to complete the task. The device identifier and volume sizes may be different in your environment and you should substitute your own values throughout the procedure. The procedure also assumes that the Docker daemon is in the stopped state.

Identify the block device you want to use. The device is located under /dev/ (such as /dev/xvdf) and needs enough free space to store the images and container layers for the workloads that host runs. A solid state drive is ideal.

Stop Docker.

$ sudo systemctl stop docker

Install the following packages:

    RHEL / CentOS: device-mapper-persistent-data, lvm2, and all dependencies

    Ubuntu / Debian: thin-provisioning-tools, lvm2, and all dependencies

Create a physical volume on your block device from step 1, using the pvcreate command. Substitute your device name for /dev/xvdf.

    Warning: The next few steps are destructive, so be sure that you have specified the correct device!

$ sudo pvcreate /dev/xvdf

Physical volume "/dev/xvdf" successfully created.

Create a docker volume group on the same device, using the vgcreate command.

$ sudo vgcreate docker /dev/xvdf

Volume group "docker" successfully created

Create two logical volumes named thinpool and thinpoolmeta using the lvcreate command. The last parameter specifies the amount of free space to allow for automatic expanding of the data or metadata if space runs low, as a temporary stop-gap. These are the recommended values.

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

Logical volume "thinpool" created.

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

Logical volume "thinpoolmeta" created.

Convert the volumes to a thin pool and a storage location for metadata for the thin pool, using the lvconvert command.

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

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 to thin pool.

Configure autoextension of thin pools via an lvm profile.

$ sudo vi /etc/lvm/profile/docker-thinpool.profile

Specify thin_pool_autoextend_threshold and thin_pool_autoextend_percent values.

thin_pool_autoextend_threshold is the percentage of space used before lvm attempts to autoextend the available space (100 = disabled, not recommended).

thin_pool_autoextend_percent is the amount of space to add to the device when automatically extending (0 = disabled).

The example below adds 20% more capacity when the disk usage reaches 80%.

activation {
  thin_pool_autoextend_threshold=80
  thin_pool_autoextend_percent=20
}

Save the file.

Apply the LVM profile, using the lvchange command.

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

Logical volume docker/thinpool changed.

Enable monitoring for logical volumes on your host. Without this step, automatic extension does not occur even in the presence of the LVM profile.

$ sudo lvs -o+seg_monitor

LV       VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Monitor
thinpool docker twi-a-t--- 95.00g             0.00   0.01                             monitored

If you have ever run Docker on this host before, or if /var/lib/docker/ exists, move it out of the way so that Docker can use the new LVM pool to store the contents of image and containers.

$ mkdir /var/lib/docker.bk
$ mv /var/lib/docker/* /var/lib/docker.bk

If any of the following steps fail and you need to restore, you can remove /var/lib/docker and replace it with /var/lib/docker.bk.

Edit /etc/docker/daemon.json and configure the options needed for the devicemapper storage driver. If the file was previously empty, it should now contain the following contents:

{
    "storage-driver": "devicemapper",
    "storage-opts": [
    "dm.thinpooldev=/dev/mapper/docker-thinpool",
    "dm.use_deferred_removal=true",
    "dm.use_deferred_deletion=true"
    ]
}

Start Docker.

或者:
#str=$(cat /usr/lib/systemd/system/docker.service|grep ExecStart)
#sed -i “s%$str%ExecStart=/usr/bin/dockerd --storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true%g” /usr/lib/systemd/system/docker.service

systemd:

$ sudo systemctl start docker

service:

$ sudo service docker start

Verify that Docker is using the new configuration using docker info.

$ docker info

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.03.1-ce
Storage Driver: devicemapper
 Pool Name: docker-thinpool
 Pool Blocksize: 524.3 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file:
 Metadata file:
 Data Space Used: 19.92 MB
 Data Space Total: 102 GB
 Data Space Available: 102 GB
 Metadata Space Used: 147.5 kB
 Metadata Space Total: 1.07 GB
 Metadata Space Available: 1.069 GB
 Thin Pool Minimum Free Space: 10.2 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: true
 Deferred Deletion Enabled: true
 Deferred Deleted Device Count: 0
 Library Version: 1.02.135-RHEL7 (2016-11-16)
<output truncated>

If Docker is configured correctly, the Data file and Metadata file is blank, and the pool name is docker-thinpool.

After you have verified that the configuration is correct, you can remove the /var/lib/docker.bk directory which contains the previous configuration.

$ rm -rf /var/lib/docker.bk
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章