gitlab-ce安装迁移部署

一、gitlab-ce安装

在迁移的目标服务器上安装gitlab-ce

1.1 添加 gitlab-ce 仓库

1tee /etc/yum.repos.d/gitlab-ce.repo <<EOF
2[gitlab-ce]
3name=gitlab-ce
4baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
5repo_gpgcheck=0
6gpgcheck=0
7enabled=1
8gpgkey=https://packages.gitlab.com/gpg.key
9EOF

1.2 安装 gitlab-ce

1yum -y install gitlab-ce

1.3 配置 gitlab-ce

修改访问域名,修改external_url字段

1vim /etc/gitlab/gitlab.rb
2external_url 'https://git.hzde.com'

由于我们的生产环境中统一用的nginx进行管理,使用外部nginx,不使用gitlab-ce自带的nginx

 1vim /etc/gitlab/gitlab.rb
 2gitlab_rails['gitlab_default_projects_features_builds'] = false
 3gitlab_rails['trusted_proxies'] = ['127.0.0.1']
 4web_server['external_users'] = ['nginx']
 5nginx['enable'] = false
 6nginx['listen_addresses'] = ['*', '[::]']
 7nginx['listen_port'] = 80
 8nginx['listen_https'] = false
 9nginx['real_ip_trusted_addresses'] = ['127.0.0.1/8','0.0.0.0/0']
10nginx['real_ip_header'] = 'X-Real-IP'
11nginx['real_ip_recursive'] = on

修改完重新加载配置

1gitlab-ctl reconfigure

1.4 配置 nginx

  1. 安装 nginx
1yum -y install epel-release
2yum -y install nginx
  1. 配置 nginx
 1vim /etc/nginx/conf.d/git.bcdat.net.conf
 2upstream gitlab-workhorse {
 3    server unix:/var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;
 4}
 5
 6server {
 7    listen       443 ssl http2;
 8    listen       [::]:443 ssl http2;
 9    server_name  git.hxde.com;
10    root         /usr/share/nginx/html;
11
12    ssl on;
13    ssl_certificate /etc/nginx/ssl/bcdat.net.crt;
14    ssl_certificate_key /etc/nginx/ssl/bcdat.net.key;
15    ssl_ciphers "HIGH:!aNULL:!MD5:!ADH:!RC4:!DH";
16    ssl_prefer_server_ciphers on;
17    ssl_session_timeout  10m;
18    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
19
20    location / {
21        client_max_body_size 0;
22        gzip off;
23
24        proxy_read_timeout      300;
25        proxy_connect_timeout   300;
26        proxy_redirect          off;
27
28        proxy_http_version 1.1;
29
30        proxy_set_header    Host                $http_host;
31        proxy_set_header    X-Real-IP           $remote_addr;
32        proxy_set_header    X-Forwarded-Ssl     on;
33        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
34        proxy_set_header    X-Forwarded-Proto   $scheme;
35        proxy_pass http://gitlab-workhorse;
36    }
37}

运行 nginx

1systemctl enable --now nginx

1.5 配置域名解析服务

添加一条A记录指向当前服务器IP

记录类型 主机记录 解析线路 记录值 MX优先级 TTL
A git 默认 XX.XX.XX.XX 10 分钟

1.6 访问 web 页面

打开浏览器 https://git.hzde.com 做一些基础设置

二、 gitlab-ce 迁移

由于某种原因,需要将原有服务器上的gitlab进行迁移,迁移到另一台服务器上,记录一下迁移的步骤。 ***为保持顺利的迁移,版本保持和原服务器版本一致

登录原 gitlab-ce 的web后台进行查看,这里的版本为 11.6.5

2.1 添加 gitlab-ce 仓库

1tee /etc/yum.repos.d/gitlab-ce.repo <<EOF
2[gitlab-ce]
3name=gitlab-ce
4baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
5repo_gpgcheck=0
6gpgcheck=0
7enabled=1
8gpgkey=https://packages.gitlab.com/gpg.key
9EOF

2.2 安装指定版本 gitlab-ce

这里很重要,最好是保持跟原有服务器版本保持一致,不然可能会引发各种问题。

1yum makecache
2yum -y install gitlab-ce-11.6.5

2.3 配置 gitlab-ce

跟之前部署的时候配置一样

修改访问域名

1vim /etc/gitlab/gitlab.rb
2external_url 'https://git.hzde.com'

使用外部nginx,不使用自带的nginx

 1vim /etc/gitlab/gitlab.rb
 2gitlab_rails['gitlab_default_projects_features_builds'] = false
 3gitlab_rails['trusted_proxies'] = ['127.0.0.1']
 4web_server['external_users'] = ['nginx']
 5nginx['enable'] = false
 6nginx['listen_addresses'] = ['*', '[::]']
 7nginx['listen_port'] = 80
 8nginx['listen_https'] = false
 9nginx['real_ip_trusted_addresses'] = ['127.0.0.1/8','0.0.0.0/0']
10nginx['real_ip_header'] = 'X-Real-IP'
11nginx['real_ip_recursive'] = on

修改完重新加载配置

1gitlab-ctl reconfigure

2.4 备份 gitlab-ce 数据

登录原服务器进行备份

1gitlab-rake gitlab:backup:create

备份文件保存在/var/opt/gitlab/backups/目录下,使用工具将文件下载上传至目标服务器的/var/opt/gitlab/backups/目录

2.5 使用原 gitlab-ce 备份数据进行恢复

1cd /var/opt/gitlab/backups/
2
3# 将权限修改为git用户
4chown git 1551144361_2019_02_26_11.6.5_gitlab_backup.tar
5
6# 执行还原操作
7gitlab-rake gitlab:backup:restore BACKUP= 1551144361_2019_02_26_11.6.5

2.6 安装 nginx

安装 nginx

1yum -y install epel-release
2yum -y install nginx

配置 `nginx

 1vim /etc/nginx/conf.d/git.bcdat.net.conf
 2upstream gitlab-workhorse {
 3    server unix:/var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;
 4}
 5
 6server {
 7    listen       443 ssl http2;
 8    listen       [::]:443 ssl http2;
 9    server_name  git.hzde.com;
10    root         /usr/share/nginx/html;
11
12    ssl on;
13    ssl_certificate /etc/nginx/ssl/bcdat.net.crt;
14    ssl_certificate_key /etc/nginx/ssl/bcdat.net.key;
15    ssl_ciphers "HIGH:!aNULL:!MD5:!ADH:!RC4:!DH";
16    ssl_prefer_server_ciphers on;
17    ssl_session_timeout  10m;
18    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
19
20    location / {
21        client_max_body_size 0;
22        gzip off;
23
24        proxy_read_timeout      300;
25        proxy_connect_timeout   300;
26        proxy_redirect          off;
27
28        proxy_http_version 1.1;
29
30        proxy_set_header    Host                $http_host;
31        proxy_set_header    X-Real-IP           $remote_addr;
32        proxy_set_header    X-Forwarded-Ssl     on;
33        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
34        proxy_set_header    X-Forwarded-Proto   $scheme;
35        proxy_pass http://gitlab-workhorse;
36    }
37}

运行 nginx

1systemctl enable --now nginx

2.7 修改域名解析至目标服务器

记录类型 主机记录 解析线路 记录值 MX优先级 TTL
A git 默认 XX.XX.XX.XX 10 分钟

2.8 检查 gitlab-ce 迁移情况

打开浏览器,登录 https://git.hzde.com 查看效果

三、升级 gitlab-ce

迁移顺利完成之后,再对服务器进行升级操作,升级的方法很简单

1yum -y update gitlab-ce

附:常用命令

查看服务运行状态

1gitlab-ctl status

查看日志(默认为全部组件的日志)

1gitlab-ctl tail

查看单个应用的日志,后面跟模块名(如:nginx)

1gitlab-ctl tail nginx

修改了/etc/gitlab/gitlab.rb,重新配置 gitlab

1gitlab-ctl reconfigure

重启 gitlab

1gitlab-ctl restart

备份 gitlab

1gitlab-rake gitlab:backup:create

恢复 gitlab

1gitlab-rake gitlab:backup:restore BACKUP=备份的文件名