AI 摘要
在Rocky9上使用YUM源安装GitLab社区版,配置自签名HTTPS证书,并实现备份恢复与密码管理。
一、规划及环境准备
1.1 规划
使用GitLab提供的Yum源,在Rocky9安装GitLab,并绑定自签名证书。
| 主机名 |
GitLab-Server |
| 系统版本 |
Rocky9 |
| IP地址 |
192.168.10.13 |
| 开放端口 |
80、22、443 |
| 配置 |
2C、4G、100GB |
| 域名 |
gitlab.qx.lab |
| 用途 |
本地GitLab服务器 |
1.2 环境准备
二、安装
2.1 安装GitLab
- 选择社区版的
YUM 源(二选一)
1
| curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh" | sudo bash
|
- 使用清华源(二选一)
1
| vim /etc/yum.repos.d/gitlab-ce.repo
|
1 2 3 4 5
| [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
|
- 使用高校联盟聚合源
1
| vim /etc/yum.repos.d/gitlab-ce.repo
|
1 2 3 4 5
| [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.cernet.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
|
- 使用本地源
1
| vim /etc/yum.repos.d/gitlab-ce.repo
|
1 2 3 4 5
| [gitlab-ce] name=Gitlab CE Repository baseurl=https://yum.qx.lab/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
|
- 设置域名,并安装
1 2
| EXTERNAL_URL="https://gitlab.qx.lab" dnf install gitlab-ce
|
2.2 配置HTTPS
这里使用了自签名证书.
- 编辑配置文件
1
| vim /etc/gitlab/gitlab.rb
|
1 2 3 4
| external_url 'https://gitlab.qx.lab' nginx['redirect_http_to_https'] = true nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.qx.lab/gitlab.qx.lab.crt" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.qx.lab/gitlab.qx.lab.key"
|
1
| egrep -v '^$|^#' /etc/gitlab/gitlab.rb
|
- 生成证书
1 2 3 4 5
| step certificate create "gitlab.qx.lab" gitlab.qx.lab.crt gitlab.qx.lab.key \ --profile leaf \ --ca intermediate_ca.crt --ca-key intermediate_ca.key \ --san gitlab.qx.lab --san 192.168.10.13 \ --not-after 87600h --no-password --insecure --bundle
|
- 重载配置,重启
gitlab
1 2
| gitlab-ctl reconfigure gitlab-ctl restart
|
2.3 密码
- 查看默认密码
1 2
| cat /etc/gitlab/initial_root_password
|
- 重置密码
1
| gitlab-rake "gitlab:password:reset"
|
三、备份恢复
3.1 备份配置文件
/etc/gitlab
1 2
| mkdir /backup/gitlab/ -p tar -zcvf /backup/gitlab/gitlab-conf-$(date+%F).tar.gz /etc/gitlab/
|
3.2 修改配置文件
- 修改相关的配置
1
| vim /etc/gitlab/gitlab.rb
|
1
| egrep -v '^$|^#' /etc/gitlab/gitlab.rb
|
1 2 3 4
| 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
|
1 2 3 4 5 6 7 8 9 10
| [root@GitLab-Server ~]# egrep -v '^$|^#' /etc/gitlab/gitlab.rb external_url 'https://gitlab.qx.lab' 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 nginx['redirect_http_to_https'] = true nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.qx.lab/gitlab.qx.lab.crt" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.qx.lab/gitlab.qx.lab.key" [root@GitLab-Server ~]#
|
- 重载配置,重启
gitlab
1 2
| gitlab-ctl reconfigure gitlab-ctl restart
|
3.3 手动备份
1
| gitlab-rake gitlab:backup:create
|
3.4 手动恢复
- 停止进程写入
1 2
| gitlab-ctl stop unicorn gitlab-ctl stop sidekiq
|
- 查看所有的备份
1
| ls -l /var/opt/gitlab/backups
|
1 2 3 4
| [root@GitLab-Server ~]# ls -l /var/opt/gitlab/backups total 752 -rw-r--r--. 1 git git 768000 Dec 8 21:49 1765201779_2025_12_08_18.6.1_gitlab_backup.tar [root@GitLab-Server ~]#
|
- 恢复
不能携带tar 的后缀
>=12.2,需要输入两次yes
1765201779_2025_12_08_18.6.1_gitlab_backup.tar
1
| gitlab-backup restore BACKUP=1765201779_2025_12_08_18.6.1
|
1
| itlab-rake gitlab:backup:restore BACKUP=
|
- 重启
3.5 备份脚本
1 2 3 4 5 6 7 8 9 10 11 12
| #!/bin/bash
gitlab-backup create
tar zcf /backup/gitlab/gitlab-conf-$(date+%F).tar.gz /etc/gitlab/
rsync xxx
00 03 * * * sh /server/scripts/backup-gitlab.sh &>/dev/null
|
3.6 忘记密码
1
| gitlab-rake "gitlab:password:reset"
|