码迷,mamicode.com
首页 > 其他好文 > 详细

Gitlab安装、备份与恢复

时间:2019-11-22 13:35:20      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:client   为我   unicorn   x86_64   ibus   https   安装   str   cli   

背景:由于需要把gitlab从A服务器转移到B服务器,故在B服务器进行gitlab的安装和恢复备份

步骤:

一、在B服务器安装Gitlab

1. 获取安装包

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-7.10.4~omnibus-1.x86_64.rpm

2. 安装

rpm -i gitlab-ce-7.10.4~omnibus-1.x86_64.rpm

3. 修改配置文件(修改端口号、域名、数据路径、备份路径、禁用gitlab自带的nginx)

vim  /etc/gitlab/gitlab.rb

#修改端口
unicorn[port] = 8088
#修改域名
external_url http://gitlab.abc.com
#数据存放路径
git_data_dir "/data/gitlab/git-data"
#备份路径
gitlab_rails[backup_path] = "/data/gitlab/backups"
#禁用自带的nginx(如果使用自带的则设置为true, 因为我的B服务器已经有nginx在运行,故不使用自带的)
nginx[enable] = false

4. 使配置生效

gitlab-ctl reconfigure

5. 启动gitlab

gitlab-ctl restart

==============nginx[‘enable‘] = false 时配置 6,7步===============

6. 配置nginx使域名能访问到gitlab

upstream gitlab {
    server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
        listen       80;
        server_name  gitlab.abc.com;
    access_log /data/logs/nginx/access_gitlab.abc.com.log main buffer=1k;

        location / {
        proxy_pass http://127.0.0.1:8088;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_connect_timeout    600s;
            client_max_body_size       1024m;
    }
    }

7. 重启nginx

/opt/tengine/sbin/nginx -s reload

==============nginx[‘enable‘] = false 时配置 6,7步===============

8. 访问域名,确认安装成功

 

二、备份A服务器的gitlab数据

1. 备份命令

gitlab-rake gitlab:backup:create

2. 把备份生成的文件拷贝到B服务器的gitlab备份目录下(拷贝到其他目录无法完成恢复)

scp 1574279663_gitlab_backup.tar root@B服务器IP:/data/gitlab/backups/

 

三、B服务器恢复Gitlab备份数据

1. 停止相关数据连接服务

gitlab-ctl stop unicorn

gitlab-ctl stop sidekiq

2. 执行恢复备份命令(注意BACKUP后面接着备份文件的前缀即可, gitlab会自动加上 _gitlab_backup.tar 部分)

gitlab-rake gitlab:backup:restore BACKUP=1574279663 

3. 恢复完毕后,重启gitlab

gitlab-ctl restart

4. 访问B服务器的Gitlab地址 http://gitlab.abc.com,确认数据已经恢复成功

 

四、配置B服务器的每日定时备份

1. 创建脚本文件

touch /data/gitlab/backups/gitlab_backup.sh

2. 编辑脚本文件

vim /data/gitlab/backups/gitlab_backup.sh

加入如下内容: (注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出)

#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=1

3. 增加执行权限

chmod u+x /data/gitlab/backups/gitlab_backup.sh

4. 修改定时任务

crontab -e

加入如下内容(每天凌晨两点备份)

0 2 * * * sh /data/gitlab/backups/gitlab_backup.sh > /dev/null 2>&1

 

 

完毕~~~~~~~~~~

 

 

 

 

Gitlab安装、备份与恢复

标签:client   为我   unicorn   x86_64   ibus   https   安装   str   cli   

原文地址:https://www.cnblogs.com/mhl1003/p/11910716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!