Gitlab安装卸载&备份还原

一、安装&卸载
准备
关闭防火墙—systemctl disable firewalld;
修改/etc/selinux/config参数—selinux=disabled,修改后reboot;
安装
1、安装gitlab 安装命令:rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
2、修改gitlab配置文件指定服务器ip和自定义端口:vim /etc/gitlab/gitlab.rb
改为自己所需的external_url ‘http://xx.xx.xx.xx:xx’
3.重置并启动GitLab
执行:
gitlab-ctl reconfigure
gitlab-ctl restart
提示 "ok: run:"表示启动成功
4、对gitlab所在目录赋权
Chmod -R 777 /opt/gitlab/
5.访问 GitLab页面
卸载
1.停止gitlab

gitlab-ctl stop

2.卸载gitlab(看是gitlab-ce版本还是gitlab-ee版本)

rpm -e gitlab-ce

3.查看gitlab进程

ps aux | grep gitlab

4.杀掉第一个进程

kill -9 17313

5.删除所有包含gitlab文件

find / -name gitlab|xargs rm -rf

find / -name gitlab | xargs rm -rf

6.删除gitlab-ctl uninstall时自动在root下备份的配置文件

ls /root/gitlab*

二、备份之前
两台服务器gitlab版本必须一致,本例均为12.10.11
三、Gitlab创建备份
创建备份文件
[root@localhost backups]# gitlab-rake gitlab:backup:create
2021-05-21 12:02:04 -0400 – Dumping database …
Dumping PostgreSQL database gitlabhq_production … [DONE]
2021-05-21 12:02:06 -0400 – done
2021-05-21 12:02:06 -0400 – Dumping repositories …

  • root/demo (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) … [DONE]
    [SKIPPED] Wiki
    2021-05-21 12:02:06 -0400 – done
    2021-05-21 12:02:06 -0400 – Dumping uploads …
    2021-05-21 12:02:06 -0400 – done
    2021-05-21 12:02:06 -0400 – Dumping builds …
    2021-05-21 12:02:06 -0400 – done
    2021-05-21 12:02:06 -0400 – Dumping artifacts …
    2021-05-21 12:02:06 -0400 – done
    2021-05-21 12:02:06 -0400 – Dumping pages …
    2021-05-21 12:02:06 -0400 – done
    2021-05-21 12:02:06 -0400 – Dumping lfs objects …
    2021-05-21 12:02:06 -0400 – done
    2021-05-21 12:02:06 -0400 – Dumping container registry images …
    2021-05-21 12:02:06 -0400 – [DISABLED]
    Creating backup archive: 1621612926_2021_05_21_12.10.11_gitlab_backup.tar … done
    Uploading backup archive to remote storage … skipped
    Deleting tmp directories … 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.
    红字部分表示 gitlab.rb 和 gitlab-secrets.json 两个文件包含敏感信息。未被备份到备份文件中。需要手动备份。

使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1621612926_2021_05_21_12.10.11_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分。
[root@localhost backups]# ls -l
-rw------- 1 git git 2969600 May 21 10:40 1621608054_2021_05_21_12.10.11_gitlab_backup.tar
-rw------- 1 git git 2969600 May 21 12:02 1621612926_2021_05_21_12.10.11_gitlab_backup.tar
需手动备份的文件
 /etc/gitlab/gitlab.rb 配置文件须备份
 /var/opt/gitlab/nginx/conf nginx配置文件
 /etc/postfix/main.cfpostfix 邮件配置备份
 /etc/gitlab/gitlab-secrets.json 存储了gitlab的db secret信息
修改备份路径
如果想修改备份路径,可在/etc/gitlab/gitlab.rb文件下编辑:
gitlab_rails[‘backup_path’] = “/var/opt/gitlab/backups”

四、定时备份
计划每天凌晨五点进行备份
[root@localhost ~]# crontab -l
0 5 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
五、备份迁移
本例是通过scp命令将源备份数据复制至新服务器之下,由于有端口限制,故对端口进行了处理:
源端服务器
[root@localhost backups]# scp -P 12018 /var/opt/gitlab/backups/1621846817_2021_05_24_12.10.11_gitlab_backup.tar root@10.78.56.115:/var/opt/gitlab/backups/
root@10.78.56.115’s password:
1621612926_2021_05_21_12.10.11_gitlab_backup.tar 100% 2900KB 3.5MB/s 00:00

注意:
l 新服务器的gitlab版本和老服务器的gitlab版本一致
l scp -P 端口,这个P是大写
六、备份文件恢复

  1. 修改文件权限
    [root@cqgitlab backups]# chmod 777 1621846817_2021_05_24_12.10.11_gitlab_backup.tar

  2. 关闭相关服务
    关闭数据库连接服务
    [root@cqgitlab backups]# gitlab-ctl stop unicorn
    ok: down: unicorn: 0s, normally up
    [root@cqgitlab backups]# gitlab-ctl stop sidekiq
    ok: down: sidekiq: 0s, normally up
    [root@cqgitlab backups]# gitlab-ctl stop nginx
    ok: down: nginx: 1s, normally up
    这里注意不要关闭gitlab所有服务(gitlab-ctl stop),否则会报错:

  3. 执行恢复
    gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
    [root@cqgitlab backups]# gitlab-rake gitlab:backup:restore BACKUP=1621846817_2021_05_24_12.10.11
    注意:
    l 此处命令是文件编号,不是文件名称
    l 交互界面会有两次让输入“yes”

  4. 开启服务
    以下几个文件需手动恢复:
     /etc/gitlab/gitlab.rb 配置文件
     /var/opt/gitlab/nginx/conf nginx配置文件
     /etc/postfix/main.cfpostfix 邮件配置备份
     /etc/gitlab/gitlab-secrets.json 存储了gitlab的db secret信息

[root@cqgitlab gitlab]# mv /tmp/gitlab* . #将备份在tmp目录下的文件手动进行恢复
[root@cqgitlab backups]# gitlab-ctl start
ok: run: alertmanager: (pid 12840) 1696s
ok: run: gitaly: (pid 12857) 1696s
ok: run: gitlab-exporter: (pid 12888) 1695s
ok: run: gitlab-workhorse: (pid 12893) 1695s
ok: run: grafana: (pid 12904) 1694s
ok: run: logrotate: (pid 12924) 1694s
ok: run: nginx: (pid 12947) 1693s
ok: run: node-exporter: (pid 12965) 1693s
ok: run: postgres-exporter: (pid 12971) 1693s
ok: run: postgresql: (pid 12984) 1692s
ok: run: prometheus: (pid 12993) 1692s
ok: run: redis: (pid 13014) 1691s
ok: run: redis-exporter: (pid 13025) 1691s
ok: run: sidekiq: (pid 25051) 0s
ok: run: unicorn: (pid 25057) 1s
检查状态

都无问题,两边的Gitlab同步完成,数据一致

其他
GitLab 常用命令
// 启动所有 GitLab 组件—gitlab-ctl start
// 停止所有 GitLab 组件—gitlab-ctl stop
// 重启所有 GitLab 组件—gitlab-ctl restart
// 查看服务状态----gitlab-ctl status
// 启动服务----gitlab-ctl reconfigure
// 修改默认的配置文件----vi /etc/gitlab/gitlab.rb
// 检查 GitLab—gitlab-rake gitlab:check SANITIZE=true --trace
// 查看日志------sudo gitlab-ctl tail
502报错
方法一:sudo gitlab-ctl restart sidekiq
sudo gitlab-ctl hup unicorn
方法二:权限
chmod -R 755 gitlab/
方法三:端口
vim /etc/gitlab/gitlab.rb 修改gitlab.rb文件的内容
external_url ‘http://localhost:9090’
unicorn[‘listen’] = ‘127.0.0.1’
unicorn[‘port’] = 8008
重启配置—gitlab-ctl reconfigure
安装卡在ruby_block[wait for redis service socket] action run
解决方案:
在另外开启一个终端启动如下命令
sudo /opt/gitlab/embedded/bin/runsvdir-start
或者在当前的终端窗口中后台执行上述命令
nohup /opt/gitlab/embedded/bin/runsvdir-start &
然后再执行
sudo gitlab-ctl reconfigure

安装过程中问题处理
解决方案:
耐心等吧(10分钟左右)
按住 CTRL+C 强制结束
运行—sudo systemctl restart gitlab-runsvdir
再次执行----sudo gitlab-ctl reconfigure

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

&淡年华&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值