CentOS 7配置Docker Storage

前端之家收集整理的这篇文章主要介绍了CentOS 7配置Docker Storage前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

背景

CentOS 7已经集成了Docker Engine,并且提供了docker-storage-setup服务来帮助配置docker服务的devicemapper存储驱动,如果该驱动自动配置失败,则docker服务的存储驱动会降级为lvm-loop驱动。由于loop设备的缓存问题,lvm-loop模式不适合生产环境。

CentOS 7的安装程序默认使用lvm模式管理磁盘,如果仅有一块磁盘,安装程序会在该物理卷(pv)上创建centos卷组(vg),并同时使用所有空间创建home和root逻辑卷(lv)。

服务docker-storage-setup默认会尝试使用root文件系统所属的vg,即centos vg,但是由于该vg上已经没有剩余空间,从而导致devicemapper驱动配置失败。

减小home lvm的大小创建docker lvm

CentOS 7默认安装程序创建的home lv空间一般比较大,先减小其大小:

lvresize -L -50G /dev/centos/home

重新创建并挂载home文件系统

umount /home
mkfs.xfs /dev/centos/home
mount /home

使用docker-storage-setup配置devicemapper驱动,执行:

servicedockerstop
rm -rf /var/lib/docker
servicedockerstart

添加新的存储设备创建docker lvm

停止docker服务,并清除已有的docker storage:

servicedockerstop
rm -rf /var/lib/docker

编辑/etc/sysconfig/docker-storage-setup:

DEVS=/dev/sdb
VG=docker

配置devicemapper驱动:

[root@localhost ~]# docker-storage-setup
INFO: Volumegroupbackingrootfilesystemcouldnot bedetermined
INFO: Device /dev/sdbis alreadypartitionedand is partofvolumegroupdocker
Roundingupsizeto fullphysicalextent 12.00 MiB
Logicalvolume "docker-poolMeta" created.
Logicalvolume "docker-pool" created.
WARNING: Convertinglogicalvolumedocker/docker-pooland docker/docker-poolMetato pool's dataand Metadatavolumes.
THIS WILLDESTROYCONTENTOFLOGICALVOLUME (filesystemetc.)
Converteddocker/docker-poolto thinpool.
Logicalvolume "docker-pool" changed.

重启docker服务:

servicedockerstart

确认配置生效: a) vg信息:

[root@localhost ~]# vgdisplay
--- Volumegroup ---
VGNamedocker
SystemID
Formatlvm2
MetadataAreas1
MetadataSequenceNo6
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV1
OpenLV0
MaxPV0
CurPV1
ActPV1
VGSize10.00 GiB
PESize4.00 MiB
TotalPE2559
AllocPE / Size1028 / 4.02 GiB
FreePE / Size1531 / 5.98 GiB
VGUUIDv1eiA1-P7CS-pUx9-D0uS-eVwZ-41pA-SKdlef

b) docker info:

[root@localhost ~]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
ServerVersion: 1.10.3
StorageDriver: devicemapper
 PoolName: docker-docker--pool
 PoolBlocksize: 524.3 kB
 BaseDeviceSize: 10.74 GB
 BackingFilesystem: xfs
 Datafile:
 Metadatafile:
 DataSpaceUsed: 20.45 MB
 DataSpaceTotal: 4.287 GB
 DataSpaceAvailable: 4.266 GB
 MetadataSpaceUsed: 40.96 kB
 MetadataSpaceTotal: 12.58 MB
 MetadataSpaceAvailable: 12.54 MB
 UdevSyncSupported: true
 DeferredRemovalEnabled: true
 DeferredDeletionEnabled: true
 DeferredDeletedDeviceCount: 0
 LibraryVersion: 1.02.107-RHEL7 (2016-06-09)
ExecutionDriver: native-0.2
LoggingDriver: json-file
Plugins:
 Volume: local
 Network: bridgenull host
KernelVersion: 3.10.0-327.22.2.el7.x86_64
OperatingSystem: CentOSLinux 7 (Core)
OSType: linux
Architecture: x86_64
NumberofDockerHooks: 2
cpus: 2
TotalMemory: 1.782 GiB
Name: localhost.localdomain
ID: AY7O:H2RJ:33J5:62FY:GHZE:AGFH:F42E:AH3J:WY7N:JXQK:LHBS:BDKY
WARNING: bridge-nf-call-iptablesis disabled
WARNING: bridge-nf-call-ip6tablesis disabled
Registries: docker.io (secure)

3) Docker Storage配置选项,查看/etc/sysconfig/docker-storage:

DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper --storage-opt dm.fs=xfs --storage-opt dm.thinpooldev=/dev/mapper/centos-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true " http://www.tuicool.com/articles/UFJFRzN   

参考

原文链接:https://www.f2er.com/centos/378726.html

猜你在找的CentOS相关文章