极狐GitLab 采用 Omnibus 方式安装时默认目录位置如下:
-
/opt/gitlab
主程序文件目录 -
/var/opt/gitlab
数据文件目录 -
/var/log/gitlab
日志文件目录
在大多情况下,服务器/var
目录存放在根目录下,根目录一般不会分配比较大的空间,而 Git 仓库和 PostgreSQL 数据目录作为增长比较快的目录,经常会导致根目录磁盘空间不足。因此需要进行数据目录的迁移。本文本次仅提供 PostgreSQL数据目录的迁移。
具体操作步骤如下:
1.修改极狐gitlab配置文件
$ sudo cat /etc/gitlab/gitlab.rb
......
postgresql['dir'] = "/${new_dir}/postgresql"
postgresql['home'] = "/${new_dir}/postgresql"
postgresql['data_dir'] = "/${new_dir}/postgresql" # 旧版本中可能存在此参数
gitlab_rails['db_host'] = "/${new_dir}/postgresql"
gitlab_rails['auto_migrate'] = false
......
2.移动数据文件
# 停止gitlab实例
$ sudo gitlab-ctl stop
# 移动数据库数据文件目录 - data_dir
$ sudo cp -r /var/opt/gitlab/postgresql/data /${new_dir}/postgresql
$ sudo chown -R gitlab-psql.gitlab-psql /${new_dir}/postgresql/data
3.重新配置
# 重新配置
$ sudo gitlab-ctl reconfigure
# 启动实例
$ sudo gitlab-ctl start
4.开启自动迁移
# 开启auto_migrate
gitlab_rails['auto_migrate'] = true
# 重新配置
$ sudo gitlab-ctl reconfigure
5.验证迁移
$ ps -ef|grep 'postgresql01'|grep -v grep
gitlab-+ 42684 1269 0 14:23 ? 00:00:00 /opt/gitlab/embedded/bin/postgres -D /${new_dir}/postgresql/data
$ netstat -an|grep 5432
unix 2 [ ACC ] STREAM LISTENING 205599 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 213842 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 209521 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 214439 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 213280 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 209439 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 207798 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 214965 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 210124 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 214960 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 209638 /${new_dir}/postgresql/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 208734 /${new_dir}/postgresql/.s.PGSQL.5432