Gitlab-内嵌数据库迁移到外部postgresql实例

实验环境:
172.16.212.11上docker安装了gitlab实例,需要将该实例的数据迁移到172.16.212.22

一、172.16.212.22上新起一个gitlab实例

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce -y
sudo systemctl start docker
sudo mkdir /data/gitlab/{etc,data} -pv
sudo mkdir /data/log/gitlab -pv
sudo mkdir /data/gitlab/data/gitlab-shell/{hooks,hooks_no_review,custom_hooks} -pv

sudo docker run --detach
–hostname git.testabc.com
–publish 8443:443 --publish 8000:80 --publish 8022:22
–name gitlab
–restart always
–volume /data/gitlab/etc:/etc/gitlab
–volume /data/log/gitlab:/var/log/gitlab
–volume /data/gitlab/data:/var/opt/gitlab
–volume /data/gitlab/data/gitlab-shell/hooks:/opt/gitlab/embedded/service/gitlab-shell/hooks
–volume /data/gitlab/data/gitlab-shell/hooks_no_review:/opt/gitlab/embedded/service/gitlab-shell/hooks_no_review
–volume /data/gitlab/data/gitlab-shell/custom_hooks:/opt/gitlab/embedded/service/gitlab-shell/custom_hooks
–volume /etc/localtime:/etc/localtime
harbor.yourdizhi.com/ops/gitlab/gitlab-ce:13.1.4-ce.0

二、172.16.212.22上安装postgresql

sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
sudo yum install postgresql11 postgresql11-contrib postgresql11-server -y
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl start postgresql-11

sudo vim /var/lib/pgsql/11/data/postgresql.conf
listen_addresses = ‘*’

sudo vim /var/lib/pgsql/11/data/pg_hba.conf
host all all 0.0.0.0/0 md5

sudo systemctl restart postgresql-11
sudo -u postgres psql

create role gitlab login encrypted password ‘’;
CREATE DATABASE ops_gitlab owner=gitlab ENCODING=‘UTF8’;
\c ops_gitlab;
create extension pg_trgm;

三、172.16.212.22上,修改gitlab配置文件,外接postgresql

sudo vim /data/gitlab/etc/gitlab.rb
gitlab_rails[‘db_adapter’] = “postgresql”
gitlab_rails[‘db_encoding’] = “utf8”
gitlab_rails[‘db_database’] = “ops_gitlab”
gitlab_rails[‘db_username’] = “gitlab”
gitlab_rails[‘db_password’] = “”
gitlab_rails[‘db_host’] = “172.16.212.22”
gitlab_rails[‘db_port’] = 5432
prometheus[‘enable’] = false
node_exporter[‘enable’] = false
redis_exporter[‘enable’] = false
postgres_exporter[‘enable’] = false
prometheus_monitoring[‘enable’] = false

sudo docker restart gitlab

四、172.16.212.11上,进入旧的gitlab容器,备份数据,并将备份文件传给172.16.212.22上新gitlab实例

sudo docker exec -it gitlab /bin/bash
gitlab-rake gitlab:backup:create /var/opt/gitlab/backups/
exit

cd /data/gitlab/data/backups/
scp 1659596203_2022_08_04_13.1.4_gitlab_backup.tar 172.16.212.22:/data/gitlab/data/backups/

五、172.16.212.22上,进入容器,执行恢复

sudo docker exec -it gitlab /bin/bash
chmod 644 1659596203_2022_08_04_13.1.4_gitlab_backup.tar
gitlab-rake gitlab:backup:restore BACKUP=1659596203_2022_08_04_13.1.4

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鬼刺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值