gitlab 迁移-安装-还原

文章目录

一、备份原有Gitlab

1、备份清单

  • 配置文件

备份命令备份不会备份gitlab.rb,gitlab-secrets.json文件,需要单独备份

配置文件主要有:

/etc/gitlab/gitlab.rb

/etc/gitlab/gitlab-secrets.json

或备份整个/etc/gitlab目录也是可以的

  • 数据文件:

当前gitlab中所有工程项目文件。

2、备份执行

  • 创建备份

    shell 复制代码
    [root@localhost ~]# gitlab-backup create
    #或者使用
    [root@localhost ~]# gitlab-rake gitlab:backup:create
    2023-03-15 23:01:47 -0400 -- Dumping database ... 
    Dumping PostgreSQL database gitlabhq_production ... [DONE]
    2023-03-15 23:01:51 -0400 -- done
    2023-03-15 23:01:51 -0400 -- Dumping repositories ..
    ...
    Creating backup archive: 1678935707_2023_03_15_14.9.5_gitlab_backup.tar ... done
    Uploading backup archive to remote storage  ... skipped
    Deleting tmp directories ... done
    done
    done
    done
    done
    done
    done
    done
    done
    done
    Deleting old backups ... skipping
    Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
    and are not included in this backup. You will need these files to restore a backup.
    Please back them up manually.
    Backup task   is done.
  • 查看备份:备份文件的格式为:

shell 复制代码
[root@localhost ~]# ll /var/opt/gitlab/backups/
总用量 360
-rw-------. 1 git git 368640 3月  15 23:01 1678935707_2023_03_15_14.9.5_gitlab_backup.tar

二、卸载删除原有Gitlab

1、停止Gitlab

shell 复制代码
gitlab-ctl stop

2、卸载Gitlab

shell 复制代码
rpm -e gitlab-ce

3、查看Gitlab进程

shell 复制代码
ps aux | grep gitlab

4、杀死进程

shell 复制代码
kill -9 18777 #(18777 是第一个进程的pid号,根据显示情况输入)
# 有时候kill掉后,又出新的进程,可以使用
systemctl stop gitlab-runsvdir
# 然后查看进程后,再kill 第一个进程pid号
ps -ef | grep gitlab
#杀掉后,在ps aux | grep gitlab确认一遍,还有没有gitlab的进程
#如果还有进程请用以下命令杀死所有进程:
ps -ef | grep gitlab | xargs kill -s 9

5、删除所有包含Gitlab文件

shell 复制代码
find / -name gitlab | xargs rm -rf

删除的过程中有时候遇到权限不够的情况,可以按如下处理:

shell 复制代码
$ find / -name gitlab
find: '/run/user/1000/gvfs': 权限不够
$ rm -rf /run/user/1000/gvfs
rm: 无法删除"/run/user/1000/gvfs": 是一个目录
$ umount -rf /run/user/1000/gvfs
rm -rf /run/user/1000/gvfs
$ find / -name gitlab|xargs rm -rf

三、安装Gitlab

1、添加镜像地址

添加镜像地址的目的是为了提高国内用户软件下载的速度,编辑(新建)文件gitlab-ce.repo,指令:

shell 复制代码
vi /etc/yum.repos.d/gitlab-ce.repo 

输入:

shell 复制代码
[gitlab-ce]
name=gitlab-ce
# 清华大学的镜像源
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

2、安装依赖

依次输入以下指令

shell 复制代码
# 安装和配置openssh
sudo yum install curl policycoreutils-python openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
# 安装和配置邮件服务
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

注意 如果无法启动postfix,可以尝试以下操作:

输入以下指令编辑main.cf文件:

shell 复制代码
vim /etc/postfix/main.cf

找到如下内容并进行如下修改:

shell 复制代码
inet_protocols = ipv4
inet_interfaces = all

3、安装防火墙

需要开启防火墙的,执行以下操作

shell 复制代码
# 安装和配置防火墙
sudo yum install firewalld
sudo systemctl start firewalld
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

4、下载安装Gitlab

  • 安装最新版

    shell 复制代码
    yum install gitlab-ce
  • 安装指定版:GitLab10.0.0下载:【如果要还原,一定要安装与备份的Gitlab版本一致的Gitlab】

    shell 复制代码
    curl -LJO https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

    安装:

    shell 复制代码
    rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

5、配置Gitlab

运行以下指令,类似于初始化操作:

shell 复制代码
sudo gitlab-ctl reconfigure

可选操作 配置防火墙,放行端口(8091为例):

shell 复制代码
sudo firewall-cmd --permanent --zone=public --add-port=8091/tcp
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

可选操作 关闭防火墙

shell 复制代码
# 查看防火墙状态
firewall-cmd --state
# 关闭防火墙
systemctl stop firewalld.service
# 关闭防火墙自启动
systemctl disable firewalld.service 

vim的搜索指令提示:

打开文件后,在命令模式,就是按下ESC后的模式,输入以下内容,点击进行搜索,按下N搜索下一个,按下Shift+N搜索前一个:

shell 复制代码
#"/"后面添加需要搜索的内容
/external_url

更改GitLab端口,编辑文件gitlab.rb

shell 复制代码
vim /etc/gitlab/gitlab.rb

修改以下内容(IP以 47.110.230.147 为例):

shell 复制代码
external_url 'http://47.110.230.147:8091'
nginx['listen_port'] = 8091
nginx['listen_https'] = false

更改nigx端口,编辑文件gitlab-http.conf:

复制代码
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

查找如下内容并修改:

shell 复制代码
server {
listen *:8091;
server_name 47.110.230.147;
...
if ($http_host = "") {
   set $http_host_with_default "47.110.230.147:8091";
}
}

保存修改,执行以下指令

shell 复制代码
gitlab-ctl reconfigure

6、启动并访问

启动GitLab:

shell 复制代码
gitlab-ctl restart

四、还原备份

1、设置备份路径

根据/etc/gitlab/gitlab.rb 配置文件中backups配置的路径,将备份文件放在相应的目录下,以备下一步骤进行还原,找到相应文件。

原有备份过程中,/etc/gitlab整个文件夹进行备份,在还原之前需要将之前备份的当前文件夹进行手动还原后执行,还原命令。

2、还原备份

进行

shell 复制代码
gitlab-rake gitlab:backup:restore BACKUP=/var/opt/gitlab/backups/xxxx_yyyy_MM_dd_version

还原后可直接通过页面人工确认是否成功,数据是否有遗漏。如果还原过程有错误,可执行以下命令检验

shell 复制代码
gitlab-rake gitlab:check SANITIZE=true
相关推荐
火山上的企鹅1 小时前
Codex实战:APP远程升级服务搭建(三)后台管理页面(APK 上传、版本管理、多应用页签)
服务器·网络·数据库·oracle·qgc
阿狸猿2 小时前
论 NoSQL 数据库技术及其应用
数据库·nosql
FBI HackerHarry浩2 小时前
DataGrip2023.2.3默认保存的数据库和.sql文件在哪里?怎么修改默认路径?
数据库
袁小皮皮不皮2 小时前
3.HCIP OSPF补充知识(优化版)
服务器·网络·数据库·网络协议·智能路由器
运筹vivo@2 小时前
Python ContextVar 底层机制与内存模型拆解
前端·数据库·python
志栋智能3 小时前
超自动化巡检:知识沉淀与团队协作的新载体
大数据·运维·网络·数据库·人工智能·自动化
syt_biancheng3 小时前
Redis初识
数据库·redis·缓存
cmes_love4 小时前
股票逐笔level2历史行情下载十档订单薄五档tick分钟下载分享
数据库·区块链
仙俊红4 小时前
SQL 调优需要掌握的知识
数据库·sql
fofantasy4 小时前
NSK LH12AN 微型导轨技术手册
运维·网络·数据库·经验分享·规格说明书