GitLab 磁盘空间不足的处理(根文件系统扩容)

公司的 git 服务器提示磁盘空间不足,无法提交代码。查看了一下磁盘空间,使用率达到了 100%。

之前安装 GitLab 的时候,仓库地址在其他分区,所以仓库位置不用更改。查看了一下大文件位置,发现是 postgresql 占据了空间。所以我尝试去修改 postgresql 数据库位置。

//先停止 gitlab
gitlab-ctl stop
//然后同步数据到其他分区
sudo rsync -av /var/opt/gitlab/postgresql /data/gitsql/
//同步完成之后,修改配置 
vim /etc/gitlab/gitlab.rb
postgresql[‘data_dir’] = “/data/gitsql/postgresql/data”
postgresql[‘dir’] = “/data/gitsql/postgresql”
postgresql[‘home’] = “/data/gitsql/postgresql”
//重新加载配置,并重启gitlab
gitlab-ctl reconfigure
gitlab-ctl restart
//注意:保留原位置目录 /var/opt/gitlab/postgresql (会创建 s.PGSQL.5432 文件)

按照网上找到的修改步骤操作了一番,然而发现加载配置的时候会报错,提示连接数据库失败。经过各种查找都没能解决问题。于是决定扩容磁盘。

因为用的是 Azure 的服务器,所以先进后台,停止虚拟机,扩容系统盘。扩容之后,重新开启虚拟机。

//登陆虚拟机,切换成 root 用户,查看当前的虚拟机的根文件系统容量。
[root@xxx root]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        30G  1.1G   27G   4% /
devtmpfs        832M     0  832M   0% /dev
tmpfs           840M     0  840M   0% /dev/shm
tmpfs           840M  8.3M  832M   1% /run
tmpfs           840M     0  840M   0% /sys/fs/cgroup/dev/sdb1        69G   53M   66G   1% /mnt/resource

//打开分区表(以下命令默认系统为centos6,centos7不同命令在旁边标注)
[root@xxx root]# fdisk /dev/sda
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.
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00093e4e
## 请记录分区信息
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    62914559    31456256   83  Linux
## 删除分区
Command (m for help): d
Selected partition 1  (centos7 应选择2)
Partition 1 is deleted
## 新建分区
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):
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): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00093e4e
## 注意,这里的start的值,必须和此前的分区表里的信息一致
Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   209715199   104856576   83  Linux
## 激活分区
Command (m for help): a   (centos7 无需这一步)
Selected partition 1
## 再次打印分区,确认已激活
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00093e4e
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   209715199   104856576   83  Linux
## 如果信息有误,或者不确定,请及时联系我们,如果信息确认无误,写入分区表
Command (m for help): wr
The partition table has been altered!
Calling ioctl() to re-read partition table.

//分区表修改完毕,重启虚拟机。
//登陆虚拟机,切换到 root 用户,检查当前根文件系统的容量。
[root@xxx root]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        30G  1.1G   27G   4% /
devtmpfs        832M     0  832M   0% /dev
tmpfs           840M     0  840M   0% /dev/shm
tmpfs           840M  8.3M  832M   1% /run
tmpfs           840M     0  840M   0% /sys/fs/cgroup
/dev/sdb1        69G   53M   66G   1% /mnt/resource

//修改根文件系统的大小。
[root@xxx root]# resize2fs /dev/sda1  (centos7 为xfs_growfs /dev/sda2)
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 13
The filesystem on /dev/sda1 is now 26214144 blocks long.

//检查根文件系统大小。
[root@xxx root]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        99G  1.1G   93G   2% /
devtmpfs        832M     0  832M   0% /dev
tmpfs           840M     0  840M   0% /dev/shm
tmpfs           840M  8.3M  832M   1% /run
tmpfs           840M     0  840M   0% /sys/fs/cgroup
/dev/sdb1        69G   53M   66G   1% /mnt/resource

//根文件系统扩容完成
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值