记录一次docker扩容

本文详细记录了如何解决Harbor镜像存储空间不足的问题,通过在CentOS 7系统上添加新硬盘,并进行分区、格式化、挂载操作,最终成功将Docker的数据目录迁移到新硬盘,从而扩展了存储空间。此外,还介绍了如何设置新硬盘开机自动挂载,并验证了Docker服务和Harbor的正常运行。
摘要由CSDN通过智能技术生成

搭建的harbor只有20G的磁盘空间,现在镜像多了,不够用了。

环境

[root@harbor harbor]#cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@harbor harbor]#docker version 
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.40
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:05:12 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          19.03.15
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       99e3ed8919
  Built:            Sat Jan 30 03:16:33 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

文件系统为xfs,未做LVM逻辑卷

虚拟机添加硬盘

在这里插入图片描述
启动虚拟机

停止harbor

[root@harbor harbor]#docker-compose stop 
Stopping harbor-jobservice ... done
Stopping nginx             ... done
Stopping harbor-core       ... done
Stopping harbor-db         ... done
Stopping harbor-portal     ... done
Stopping redis             ... done
Stopping registryctl       ... done
Stopping registry          ... done
Stopping harbor-log        ... done

验证

[root@harbor harbor]#docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

停止docker

[root@harbor harbor]#systemctl stop docker 
[root@harbor harbor]#systemctl status docker 
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2022-07-22 03:42:52 GMT; 8s ago
     Docs: https://docs.docker.com
  Process: 1104 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 10.0.0.81 (code=exited, status=0/SUCCESS)
 Main PID: 1104 (code=exited, status=0/SUCCESS)

Jul 22 03:41:04 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:41:04.257780421Z" level=info msg="ignoring event" module=l...elete"
Jul 22 03:41:04 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:41:04.264381575Z" level=info msg="ignoring event" module=l...elete"
Jul 22 03:41:14 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:41:14.195026130Z" level=info msg="Container f534d045eb889c...force"
Jul 22 03:41:14 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:41:14.281973610Z" level=info msg="ignoring event" module=l...elete"
Jul 22 03:41:24 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:41:24.387055913Z" level=info msg="Container 78c276d0231065...force"
Jul 22 03:41:24 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:41:24.466741978Z" level=info msg="ignoring event" module=l...elete"
Jul 22 03:42:52 harbor.kktb.org systemd[1]: Stopping Docker Application Container Engine...
Jul 22 03:42:52 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:42:52.167317207Z" level=info msg="Processing signal 'terminated'"
Jul 22 03:42:52 harbor.kktb.org dockerd[1104]: time="2022-07-22T03:42:52.167770509Z" level=info msg="Daemon shutdown complete"
Jul 22 03:42:52 harbor.kktb.org systemd[1]: Stopped Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

创建新的挂载点

[root@harbor harbor]#mkdir -pv /data/sdb/docker/lib/
mkdir: created directory ‘/data/sdb’
mkdir: created directory ‘/data/sdb/docker’
mkdir: created directory ‘/data/sdb/docker/lib/’

硬盘分区,格式化

[root@harbor harbor]#fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xbac63495.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[root@harbor harbor]#mkfs.xfs /dev/sdb1 
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载硬盘

[root@harbor harbor]#mount /dev/sdb1 /data/sdb/docker/lib/

移动数据

[root@harbor harbor]#mv /var/lib/docker/* /data/sdb/docker/lib/

[root@harbor ~]#ll /data/sdb/docker/lib/
total 16
drwx------   2 root root   24 Jul 15 12:32 builder
drwx--x--x   4 root root  139 Jul 15 12:32 buildkit
drwx-----x   5 root root  222 Jul 22 03:57 containers
drwx------   3 root root   22 Jul 15 12:10 image
drwxr-x---   3 root root   19 Jul 15 12:10 network
drwx-----x 102 root root 8192 Jul 22 03:57 overlay2
drwx------   4 root root   32 Jul 15 12:10 plugins
drwx------   2 root root    6 Jul 22 03:57 runtimes
drwx------   2 root root    6 Jul 15 12:10 swarm
drwx------   2 root root    6 Jul 22 03:57 tmp
drwx------   2 root root    6 Jul 15 12:10 trust
drwx-----x  20 root root 4096 Jul 18 02:01 volumes

更改docker服务启动参数

[root@harbor harbor]#grep root /usr/lib/systemd/system/docker.service 
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 10.0.0.81 --data-root=/data/sdb/docker/lib 

重新加载服务

[root@harbor ~]#systemctl daemon-reload 
[root@harbor ~]#systemctl start docker

docker info 验证

[root@harbor ~]#docker info 
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 3
  Running: 0
  Paused: 0
  Stopped: 3
 Images: 15
 Server Version: 19.03.15
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1160.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 1.777GiB
 Name: harbor.kktb.org
 ID: BKNU:DFRK:LAIX:NNNP:Q7OV:T32C:A2F3:3ACG:UR6C:GQ3I:RCOU:T7ZV
 Docker Root Dir: /data/sdb/docker/lib   # root dir数据目录已经更改
 Debug Mode: false
 Username: kktbzhao
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  10.0.0.81
  127.0.0.0/8
 Registry Mirrors:
  https://itg4y4qm.mirror.aliyuncs.com/
 Live Restore Enabled: false

验证镜像都存在

[root@harbor ~]#docker images 
REPOSITORY                      TAG       IMAGE ID       CREATED         SIZE
goharbor/harbor-exporter        v2.3.0    fa4ecf260b3a   13 months ago   80.7MB
goharbor/chartmuseum-photon     v2.3.0    199be7eb1b5b   13 months ago   178MB
goharbor/redis-photon           v2.3.0    3cc2c3e315a2   13 months ago   191MB
goharbor/trivy-adapter-photon   v2.3.0    3c3dc5fc0529   13 months ago   164MB
goharbor/notary-server-photon   v2.3.0    a8e3a26ef25a   13 months ago   105MB
goharbor/notary-signer-photon   v2.3.0    e8776cc92436   13 months ago   102MB
goharbor/harbor-registryctl     v2.3.0    4cf0d9bc3086   13 months ago   132MB
goharbor/registry-photon        v2.3.0    222f05a9ab07   13 months ago   81MB
goharbor/nginx-photon           v2.3.0    78f6ae7adc04   13 months ago   44MB
goharbor/harbor-log             v2.3.0    9446a5b39706   13 months ago   194MB
goharbor/harbor-jobservice      v2.3.0    bac328ac1a47   13 months ago   170MB
goharbor/harbor-core            v2.3.0    7bbebce7798c   13 months ago   157MB
goharbor/harbor-portal          v2.3.0    c4f22964cbf3   13 months ago   57.3MB
goharbor/harbor-db              v2.3.0    fc74663d9e30   13 months ago   262MB
goharbor/prepare                v2.3.0    a830321ca695   13 months ago   291MB

磁盘使用率

[root@harbor ~]#df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  900M     0  900M   0% /dev
tmpfs          tmpfs     910M     0  910M   0% /dev/shm
tmpfs          tmpfs     910M  9.6M  901M   2% /run
tmpfs          tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/sda2      xfs        15G  5.2G  9.9G  35% /
/dev/sda1      xfs      1014M  142M  872M  15% /boot
tmpfs          tmpfs     182M     0  182M   0% /run/user/0
/dev/sdb1      xfs       100G  1.9G   99G   2% /data/sdb/docker/lib

重新启动harbor

[root@harbor harbor]#docker-compose up -d 
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry      ... done
Creating harbor-db     ... done
Creating redis         ... done
Creating harbor-portal ... done
Creating registryctl   ... done
Creating harbor-core   ... done
Creating harbor-jobservice ... done
Creating nginx             ... done

端口

[root@harbor harbor]#ss -ntl 
State      Recv-Q Send-Q                      Local Address:Port                                     Peer Address:Port              
LISTEN     0      128                                     *:22                                                  *:*                  
LISTEN     0      100                             127.0.0.1:25                                                  *:*                  
LISTEN     0      128                             127.0.0.1:1514                                                *:*                  
LISTEN     0      128                                  [::]:22                                               [::]:*                  
LISTEN     0      100                                 [::1]:25                                               [::]:*                  
LISTEN     0      128                                  [::]:443                                              [::]:*                  
LISTEN     0      128                                  [::]:80                                               [::]:*     

设置/dev/sdb开机自动挂载

[root@harbor harbor]#tail /etc/fstab
# /etc/fstab
# Created by anaconda on Tue Jan 25 16:07:26 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=cf703e39-714d-4bda-9dc2-8f6737bfed60 /                       xfs     defaults        0 0
UUID=1fc09a8d-481b-4975-8107-542aa1db0f83 /boot                   xfs     defaults        0 0
UUID=e83936b9-4ae8-4240-ac49-38686976ce98 swap                    swap    defaults        0 0
/dev/sdb1 /data/sdb/docker/lib xfs defaults 0 0

web访问
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值