一、gitlab的数据备份
关于数据备份,咱们就不需要多说什么了,主要就是方式数据意外丢失,导致代码上线流程及数据的损坏崩溃;
为了避免严重生产事故,进而gitlab有了数据备份与恢复的功能。
1,修改gitlab的配置文件
[root@gitlab git_student]# vim /etc/gitlab/gitlab.rb
prometheus['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
gitlab_exporter['enable'] = false
prometheus_monitoring['enable'] = false
##################################
#备份参数设置
##################################
#备份是否打开
gitlab_rails['manage_backup_path'] = true
#备份目录地址路径
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
#备份的权限设置
gitlab_rails['backup_archive_permissions'] = 0644
#备份保存时间,超过事件覆盖掉;
gitlab_rails['backup_keep_time'] = 604800
2,重新生成各种服务的配置文件
[root@gitlab git_student]# gitlab-ctl reconfigure
3,手动创建一次备份
主要是为了测试备份功能是否管用;
[root@gitlab backups]# gitlab-backup create
此时查看备份数据的目录,发线,多出来一个压缩包;
[root@gitlab backups]# ll
total 432
-rw-r--r-- 1 git git 440320 Mar 9 08:36 1709944584_2024_03_09_15.9.3_gitlab_backup.tar
至此,数据备份就成功了;
二、gitlab的数据恢复
模拟,在企业当中,我们有个可爱的运维同事,将gitlab的仓库全部删除了;
1,模拟删除项目
进入项目详情-【设置】-【编辑】-【高级】-【删除项目】
2,恢复备份前,停止其他人写入
因为恢复备份,是上一次备份的压缩包,在恢复期间,若有人写入代码,将无法保存,所以,安全起见,恢复备份期间,需要停止写入;
[root@gitlab backups]# gitlab-ctl stop unicorn
[root@gitlab backups]# gitlab-ctl stop sidekiq
3,恢复备份
[root@gitlab backups]# gitlab-backup restore BACKUP=1709944584_2024_03_09_15.9.3
此时就已经回复成功了;
4,开启gitlab
[root@gitlab backups]# gitlab-ctl start
数据恢复成功,至此,gitlab的数据备份、恢复就学习完毕了;
三、拓展:gitlab配置https和email通知
#1.gitlab配置https(请先做个快照.)
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.xinjizhiwa.cn'
nginx[' enable' ] = true
nginx['client_max_body_size' ]= '250m '
nginx['redirect_http_to_https' ]= true
nginx[' redirect_http_to_https _port' ] = 443
nginx['ssl_certificate' ] = "path/ key.crt"
nginx['ssl_certificate_key'] = "path/ key.key"
nginx['ssl_ciphers' ] ="ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256"
nginx['ssl_prefer_server_ciphers']= "on"
nginx['ssl_protocols']= "TLSv1.2"
# nginx['ssl_certificate' ] =用于指定证书 .crt .pem
# nginx['ssl_certificate_key'] = 用于指定私钥 .key
#2,gitlab配置邮箱
注册的时候 Gitlab 服务器,给用户发送邮件,激活 或者找回密码
用户提交合并请求的时候,负责人可以收到邮件通知
配置发件人
51 ### Email Settings
52 gitlab_rails['gitlab_email_enabled'] = true
53 gitlab_rails['gitlab_email_from'] = '626080079@qq.com'
54 gitlab_rails['gitlab_email_display_name'] = 'gitlab_manages'
配置详细发件人信息
513 ### GitLab email server settings
514 ###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
515 ###! **Use smtp instead of sendmail/postfix.**
516
517 gitlab_rails['smtp_enable'] = true
518 gitlab_rails['smtp_address'] = "smtp.qq.com"
519 gitlab_rails['smtp_port'] = 465
520 gitlab_rails['smtp_user_name'] = "626080079@qq.com"
521 gitlab_rails['smtp_password'] = "????授权码"
522 gitlab_rails['smtp_domain'] = "163.com"
523 gitlab_rails['smtp_authentication'] = "login"
524 gitlab_rails['smtp_enable_starttls_auto'] = true
525 gitlab_rails['smtp_tls'] = true
#重启配置gitlab
[root@gitlab ~]# gitlab-ctl reconfigure
[root@gitlab ~]# gitlab-ctl restart
#3,测试发送邮件
[root@gitlab ~]# gitlab-rails console 回车
Notify.test_email('收件人','主题','内容').diliver_now
Notify.test_email('youjiu_linux@qq.com','Gitlab-test','测试').diliver_now
[root@gitlab ~]# gitlab-rails c
至此,gitlab阶段学习完毕;