一.gitlab的备份
1.1 创建备份目录,并授权
1
2
3
4
|
[root@linux-node1 ~] # mkdir /data/backups/gitlab -p [root@linux-node1 ~] # chown -R git.git /data/ [root@linux-node1 ~] # ll /data/ -d drwxr-xr-x 3 git git 20 Dec 20 16:21 /data/ |
1.2 修改gitlab配置
1
2
3
4
5
6
7
8
9
|
设置备份路径 [root@7mini-node1 ~] # vim /etc/gitlab/gitlab.rb 201 gitlab_rails[ 'backup_path' ] = "/data/backups/gitlab" #备份路径 204 gitlab_rails[ 'backup_keep_time' ] = 604800 #备份7天 [root@7mini-node1 ~] # mkdir -p /data/backups/gitlab [root@7mini-node1 ~] # gitlab-ctl reconfigure [root@7mini-node1 ~] # gitlab-ctl restart |
1.3.定时任务备份
1
2
|
[root@7mini-node1 ~] # crontab -l 0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create |
1.4.手动执行脚本进行备份
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/usr/bin/gitlab-rake gitlab:backup:create Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] done Dumping repositories ... * java /app1 ... [DONE] * java /app1 .wiki ... [SKIPPED] [root@7mini-node1 ~] # cd /data/backups/gitlab/ [root@7mini-node1 gitlab] # ls 1525934310_gitlab_backup. tar [root@7mini-node1 gitlab] # ll total 80 -rw------- 1 git git 81920 May 10 14:38 1525934310_gitlab_backup. tar [root@7mini-node1 gitlab] # date -d @1525934310 Thu May 10 14:38:30 CST 2018 |
1.5 恢复备份
删除gitlab中的app1的项目,再恢复
停止数据写入服务:
1
2
3
4
|
[root@7mini-node1 ~] # gitlab-ctl stop unicorn ok: down: unicorn: 1s, normally up [root@7mini-node1 ~] # gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up |
恢复数据
1
2
|
[root@7mini-node1 ~] # gitlab-rake gitlab:backup:restore BACKUP=1525934310 [root@7mini-node1 ~] # gitlab-ctl restart |
丢失的文件又还原了
二.gitlab迁移
迁移如同备份与恢复的步骤一样, 只需要将老服务器/var/opt/gitlab/backups
目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups
即可(如果你没修改过默认备份目录的话).
但是需要注意的是新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同.(注意必须相同,否则会出现问题的)
比如新服务器安装的是最新的9.52版本的Gitlab, 那么迁移之前, 可以将老服务器的Gitlab 升级为9.52在进行备份
1
2
|
/etc/gitlab/gitlab .rb gitlab 配置文件须迁移,迁移后需要调整数据存放目录 /var/opt/gitlab/nginx/conf nginx配置文件目录须迁移 |
还原
1
2
3
4
5
6
|
[root@linux-node1 ~] # gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up [root@linux-node1 ~] # gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up [root@linux-node1 ~] # chmod 777 /var/opt/gitlab/backups/1481598919_gitlab_backup.tar [root@linux-node1 ~] # gitlab-rake gitlab:backup:restore BACKUP=1481598919 |
三.gitlab升级与出现问题解决办法
下载gitlab的RPM包并进行升级
1
2
|
官网下载最新版本 gitlab对应软件包 [gitlab官网](https: //packages .gitlab.com /gitlab/gitlab-ce/packages/el/7/gitlab-ce-8 .12.13-ce.0.el7.x86_64.rpm) 使用 rpm -Uvh gitlab-ce-8.12.13-ce.0.el7.x86_64 |
如果直接升级出现如下报错
1
2
3
4
|
报错. Error executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]' 解决方法: sudo chmod 2770 /var/opt/gitlab/git-data/repositories |
查看版本信息
1
2
|
[root@localhost backups] # head -1 /opt/gitlab/version-manifest.txt gitlab-ce 9.5.2 |
四.gitlab更改默认Nginx
更换gitlab自带Nginx,使用自行编译Nginx来管理gitlab服务。
编辑gitlab配置文件禁用自带Nignx服务器
1
2
3
4
5
|
vi /etc/gitlab/gitlab .rb ... #设置nginx为false,关闭自带Nginx nginx[ 'enable' ] = false ... |
检查默认nginx配置文件,并迁移至新Nginx服务
1
2
|
/var/opt/gitlab/nginx/conf/nginx .conf #nginx配置文件,包含gitlab-http.conf文件 /var/opt/gitlab/nginx/conf/gitlab-http .conf #gitlab核心nginx配置文件 |
重启 nginx、gitlab服务
1
2
|
gitlab-ctl reconfigure service nginx restart |
出现502报错
1
|
chmod -R o+x /var/opt/gitlab/gitlab-rails |
五. gitlab邮箱的配置
1
2
3
4
5
6
7
8
9
10
11
12
|
126邮件配置: gitlab_rails[ 'time_zone' ] = 'Asia/Shanghai' gitlab_rails[ 'gitlab_email_enabled' ] = true gitlab_rails[ 'gitlab_email_from' ] = 'xiaoming@126.com' #发件邮箱设置 gitlab_rails[ 'gitlab_email_display_name' ] = 'gitlab' gitlab_rails[ 'smtp_enable' ] = true gitlab_rails[ 'smtp_address' ] = "smtp.126.com" gitlab_rails[ 'smtp_port' ] = 25 gitlab_rails[ 'smtp_user_name' ] = "xiaoming" gitlab_rails[ 'smtp_password' ] = "your password" gitlab_rails[ 'smtp_domain' ] = "126.com" gitlab_rails[ 'smtp_authentication' ] = "login" |
本篇博客转载:https://www.cnblogs.com/jimmy-xuli/p/9019894.html