一、检查过程
安装有gitlab的主机, 提示磁盘满了
1 | [root@gitlab ~]$ df -h |
考虑到gitlab是以docker形式运行的, Docker Root Dir是默认文件夹,经使用 du -sh 查看文件夹及其子文件夹的大小,发现磁盘满是因为docker文件夹过大导致的。
1 | [root@gitlab ~]$ docker info | grep "Docker Root Dir" |
二、解决思路
- 停止容器及docker服务
- 暂时移动原有 /var/lib/docker 文件夹到新的路径 /var/lib/docker1
- 新增磁盘并做初始化格式化,挂载到 /var/lib/docker
- 将原有 /var/lib/docker1 的文件拷贝到 /var/lib/docker
- 重启系统,验证
三、具体步骤
停止容器及docker服务, 移动Docker Root Dir
1
2
3
4docker ps -a
docker stop CONTAINER_ID
systemctl stop docker
mv /var/lib/docker /var/lib/docker1添加磁盘后,查看磁盘列表,sda是原有的磁盘,sdb是新增的磁盘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33[root@gitlab ~]$ fdisk -l
Disk /dev/sda: 171.8 GB, 171798691840 bytes, 335544320 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000977ec
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 167772159 82836480 8e Linux LVM
Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-home: 27.0 GB, 26969374720 bytes, 52674560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes创建硬盘分区
按n,创建新分区,而后p创建主分区,而后分区数选择默认的1,第一个和最后的扇区均使用默认值即可,最后输入w写入1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26[root@gitlab ~]$ 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 0x91c761c0.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999):
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
分区完成后,再输入 fdisk -l ,已可以看到新的分区
1 | [root@gitlab ~]$ fdisk -l |
- 格式化与挂载
格式化分区, 建立挂载目录, 挂载分区, 设置开机自动挂载,拷贝目录,重启docker服务
1 | [root@gitlab ~]$ mkfs.ext4 /dev/sdb1 |
此时应能看到原来的docker容器了。
- 重启,并做最终校验
没有问题则可以删除 /var/lib/docker1/ 文件夹