首页 > 技术文章 > 更改docker默认的data,metadata存储大小(实操)

aozhejin 2022-02-04 02:37 原文

为什么要更改 data,metadata呢?我们运行环境中涉及大量数据操作,数据增长有时候很快,由于之前规划不足,所以磁盘很快达到瓶颈需要进行重新部署。
这就需要调整原来的一些docker配置。

操作系统环境采样

[root@fp-web-130 storage]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

[root@fp-web-130 storage]# uname -r
3.10.0-327.el7.x86_64

[root@fp-web-130 storage]# docker version
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:09:15 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm

Server:
Engine:
Version: 18.03.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:13:03 2018
OS/Arch: linux/amd64
Experimental: false


在更改之前,docker info 查看下,当前docker的存储情况。

此时,data的目录大小是:107G,Metadata的目录大小是:2.147G

 docker info一下 修改之前

 [root@fp-web-130 storage]# docker info

Containers: 22
Running: 0
Paused: 0
Stopped: 22
Images: 47
Server Version: 18.03.0-ce
Storage Driver: devicemapper
Pool Name: docker-8:21-2457601-pool
Pool Blocksize: 65.54kB
Base Device Size: 10.74GB
Backing Filesystem: xfs
Udev Sync Supported: true
Data file: /dev/loop0
Metadata file: /dev/loop1
Data loop file: /mnt/docker/storage/devicemapper/devicemapper/data
Metadata loop file: /mnt/docker/storage/devicemapper/devicemapper/metadata
Data Space Used: 3.333GB
Data Space Total: 107.4GB    //默认大小
Data Space Available: 102GB    
Metadata Space Used: 4.874MB
Metadata Space Total: 2.147GB  //默认2G
Metadata Space Available: 2.143GB
Thin Pool Minimum Free Space: 10.74GB
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.107-RHEL7 (2015-10-14)
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: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
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: 8
Total Memory: 15.66GiB
Name: fp-web-130
ID: ETLX:HANE:UUNX:KHX4:2ZXU:DVQN:UIOU:ZDAP:SLZG:3RYD:VPPM:O6GF
Docker Root Dir: /mnt/docker/storage
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

 

关键要执行的命令如下:

dd if=/dev/zero of=data bs=1G count=0 seek=500
dd if=/dev/zero of=metadata bs=1G count=0 seek=10

参数说明:

If:in xxx from xxx
Of:out xxx
bs:block size 块大小
Count:
seek:创建的数量
数据大小计算 data = bs * seek

 

这里是写的一个shell脚本

#!/bin/bash

DATA_SIZE=$1
METADATA_SIZE=$2

if [ "$DATA_SIZE" = "" ]; then
DATA_SIZE=1000
fi

if [ "$METADATA_SIZE" = "" ]; then
METADATA_SIZE=10
fi

# Stop docker service
systemctl stop docker

# Resize docker data space
dd if=/dev/zero of=/mnt/docker/storage/devicemapper/devicemapper/data bs=1G count=0 seek=$DATA_SIZE

# Resize docker metadata space
dd if=/dev/zero of=/mnt/docker/storage/devicemapper/devicemapper/metadata bs=1G count=0 seek=$METADATA_SIZE

# Start docker service
systemctl start docker

 
执行命令

[root@fp-web-130 storage]# sh resize_docker.sh 1000 10
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000127523 s, 0.0 kB/s
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000110421 s, 0.0 kB/s

 

docker info一下查看修改过之后池大小

[root@fp-web-130 storage]# docker info

Containers: 22
Running: 0
Paused: 0
Stopped: 22
Images: 47
Server Version: 18.03.0-ce
Storage Driver: devicemapper
Pool Name: docker-8:21-2457601-pool
Pool Blocksize: 65.54kB
Base Device Size: 10.74GB
Backing Filesystem: xfs
Udev Sync Supported: true
Data file: /dev/loop0
Metadata file: /dev/loop1
Data loop file: /mnt/docker/storage/devicemapper/devicemapper/data
Metadata loop file: /mnt/docker/storage/devicemapper/devicemapper/metadata
Data Space Used: 3.333GB
Data Space Total: 1.074TB   //已经改变
Data Space Available: 102GB
Metadata Space Used: 9.142MB
Metadata Space Total: 10.74GB   //已经改变大小
Metadata Space Available: 10.73GB
Thin Pool Minimum Free Space: 107.4GB
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.107-RHEL7 (2015-10-14)
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: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
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: 8
Total Memory: 15.66GiB
Name: fp-web-130
ID: ETLX:HANE:UUNX:KHX4:2ZXU:DVQN:UIOU:ZDAP:SLZG:3RYD:VPPM:O6GF
Docker Root Dir: /mnt/docker/storage
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

 

  lsblk一下

 

 

 

 注意:
 sdb磁盘我分了1个主分区 sdb1, 一个扩展分区sdb2, 在扩展分区上创建的sd5逻辑分区,由于整个磁盘是200G, 所以给sdb5 100G的空间
 我们看回环设备大小目前已经变化成了docker的回环设备loop0变成了 1T空间,loop1变成了10G空间
 之前我们是把docker镜像和容器存储位置从/var/lib/docker 改变到了 新加的磁盘的/mnt/docker/storage 位置上了。
 虽然我们更改了配置的大小,但是需要新硬盘大小支撑,所以只要保证硬盘大小和我们设置的大小对应即可。

 具体如何更改docker的镜像和容器存储位置,请看我的一篇文章
 https://www.cnblogs.com/aozhejin/p/15861052.html

 

推荐阅读