安装gitlab

说明:

1、linux安装gitlab

2、gitlab路径迁移

3、gitlab数据备份和恢复

4、gitlab备份配置文件

一、安装gitlab

1、下载gitlab包

rpm地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/

2、安装gitlab

powershell 复制代码
1、安装gitlab
yum -y install policycoreutils-python
rpm -ivh gitlab-ce-13.9.7-ce.0.el7.x86_64.rpm

版本: gitlab-ce-13.9.7

2、修改gitlab配置文件
[ ! -f /etc/gitlab/gitlab.rb.bak ] && /bin/cp -av /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak
vim /etc/gitlab/gitlab.rb

external_url 'http://ip:7005'

# 修改gitlab备份路径、保存15天
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab-back"

## Limit backup lifetime to 12 days - 1036800 seconds
gitlab_rails['backup_keep_time'] = 1036800

gitlab_rails['backup_archive_permissions'] = 0644


3、创建文件夹
mkdir -p /data/gitlab
mkdir -p /data/gitlab-back
chown -R git:git /data/gitlab-back
ln -sv /data/gitlab /var/opt/
chmod 755 /data/gitlab*

4、导入配置文件
gitlab-ctl reconfigure

说明:
a、更改了默认数据存储路径,导入配置文件报错,所以通过软连接方式解决
b、如果gitlab已经运行,需要更改默认存储路径,导入配置文件访问找不到数据。

5、启动gitlab
gitlab-ctl start
gitlab-ctl status

5、访问gitlab
http://172.16.2.9:7005/

账号:root
密码:Gitlab+2024

二、备份gitlab数据

说明:

1、如果gitlab配置文件使用默认配置文件路径,备份文件存储在默认路径

powershell 复制代码
1、创建文件夹
mkdir -p /data/solution/

2、编写shell脚本
vi /data/solution/gitlab-backup.sh

#! /bin/bash

set -e

# 定义变量
conf_path="/data/gitlab-conf"
db_date=`date '+%Y%m%d%H%M'`

# 创建文件夹
mk_data(){
  if [ ! -d ${conf_path} ];then
    echo "创建文件夹中..."
    mkdir -p ${conf_path}
  else
    echo "该文件夹已存在"
  fi
}

# 备份gitlab
zip_data(){
  /usr/bin/gitlab-rake gitlab:backup:create CRON=1
  sleep 1
  
  # 备份gitlab配置文件
  tar -zcvf ${conf_path}/gitlab-conf-${db_date}.tgz /etc/gitlab
  
  # 删除30天前文件
  find ${conf_path} -name "*.tgz" -mtime +30 -type f  -exec rm -f {} \;
}

mk_data
zip_data


2、添加定时任务
# 每天凌晨备份数据
01 0,12 * * * /usr/bin/bash /data/solution/gitlab-backup.sh &

三、gitlab数据恢复

说明:

1、gitlab版本必须要保持一致,否则会报错

powershell 复制代码
1、恢复之前先停止服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl status

2、开始恢复数据
cd /data/gitlab-back
gitlab-backup restore BACKUP=1724137663_2024_08_20_13.9.7 force=yes

[root@jenkins gitlab]# cd /data/gitlab-back/
[root@jenkins gitlab-back]# ls
1724137663_2024_08_20_13.9.7_gitlab_backup.tar
[root@jenkins gitlab-back]# gitlab-backup restore BACKUP=1724137663_2024_08_20_13.9.7 force=yes

Unpacking backup ... done
2024-08-23 15:02:04 +0800 -- done
2024-08-23 15:02:04 +0800 -- Restoring uploads ... 
2024-08-23 15:02:04 +0800 -- done
2024-08-23 15:02:04 +0800 -- Restoring builds ... 
2024-08-23 15:02:04 +0800 -- done
2024-08-23 15:02:04 +0800 -- Restoring artifacts ... 
2024-08-23 15:02:04 +0800 -- done
2024-08-23 15:02:04 +0800 -- Restoring pages ... 
2024-08-23 15:02:05 +0800 -- done
2024-08-23 15:02:05 +0800 -- Restoring lfs objects ... 
2024-08-23 15:02:05 +0800 -- done
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
and are not included in this backup. You will need to restore these files manually.
Restore task is done.

说明:出现这些done提示,导入gitlab数据完成

3、重启服务
gitlab-ctl restart

4、验证gitlab
http://172.16.2.9:7005

账号:root
密码:xxxx
相关推荐
dark_20012 小时前
ESXI8.0 vsphere vcenter 多网卡多网段配置
运维·服务器·网络
架构文摘JGWZ2 小时前
这款神器,运维绝杀 !!! 【送源码】
运维·安全·web安全
亿林网络数据2 小时前
等保2.0测评之Nginx 中间件
运维·nginx·中间件
清风 0012 小时前
在 Linux 上以 All-in-One 模式安装 KubeSphere
linux·运维·服务器
小白学习记录555552 小时前
香橙派转换模型以及在开发板上部署
linux·运维·服务器
tRNA做科研3 小时前
Bio-Linux-shell详解-1-从0开始
linux·运维·服务器
小黑爱编程3 小时前
【Linux网络】Socket套接字
linux·运维·网络
xyt0_03 小时前
【Linux】常见指令
linux
gs801404 小时前
安装node 报错需要:glibc >= 2.28
linux·服务器·前端·node.js
雾岛LYC听风5 小时前
3. 轴指令(omron 机器自动化控制器)——>MC_HomeWithParameter&MC_Move
运维·c#·自动化