公司的gitlab由于停电,又崩了,每次停电都会崩掉。所以就想到自己学一下搭建gitlab代码中心,后面在搞一个jenkins自动发版学习一下,慢慢搞吧。
在弄的时候,发现Centos7居然在2024年6月31日停止维护了。这就离谱了,他的yum默认数据源也归档了。只能用阿里云等第三方的镜像数据源:
大佬教程地址:CentOS 7 yum无法使用解决方法Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch= - 愚生浅末 - 博客园 (cnblogs.com)
一、配置阿里云第三方yum数据源:
1、首先找到yum的配置文件:
cd /etc/yum.repos.d
找到CentOS-Base.repo文件
直接粘贴吧,懒得改:
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
把旧的数据全部替换掉。
执行更新数据源:
sudo yum clean all sudo yum makecache
2、增加阿里云第三方数据源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
再次更新数据源:
sudo yum clean all sudo yum makecache
二、 安装gitlab
1、下载gitlab安装包(后续安装时,会自动跟新为最新版的gitlab,不知道是为啥,下了半天。。。)
Index of /gitlab-ce/yum/el7/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
这里选择el7因为我使用的是Centos7的操作系统。
2、运行安装gitlab命令,下载所需的依赖
下载下来后搞一个文件夹放着(/opt/module/gitlab-ce-13.10.2-ce.0.el7.x86_64.rpm),创建一个.sh文件,写入这些:
#!/bin/bash # 安装 GitLab CE RPM 包 sudo rpm -ivh /opt/module/gitlab-ce-13.10.2-ce.0.el7.x86_64.rpm # 安装所需的依赖项 sudo yum install -y curl policycoreutils-python openssh-server cronie # 配置防火墙(iptables)以允许 HTTP 和 SSH 连接,并安装并启动 Postfix 邮件服务 sudo lokkit -s http -s ssh sudo yum install -y postfix sudo service postfix start sudo chkconfig postfix on # 使用 GitLab 官方安装脚本添加软件包库 curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash # 通过指定外部 URL 安装 GitLab CE sudo EXTERNAL_URL="http://gitlab.example.com" yum -y install gitlab-ce
我执行后,下载了很多依赖,最后又下了一个V17.2.1 版本的gitlab。真奇怪。
3、初始化、运行gitlab
执行以下命令来初始化 GitLab 服务:
sudo gitlab-ctl reconfigure
启动 GitLab 服务
sudo gitlab-ctl start
4、地址就是gitlab服务器地址,80端口记得开放
- root默认密码在车间gitlab时会创建一个文件,存放在里面:
/etc/gitlab/initial_root_password
- 据说这个文件将在首次执行reconfigure后24小时自动删除
5、默认是英文的,设置为中文
三、备份gitlab
设置备份文件存放地址、备份文件存在时间(默认/var/opt/gitlab/backups,不修改也是可以的,达到一定时间会自动删除,不修改也是可以的)
/etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" ##备份文件存放地址,不存在自动创建 gitlab_rails['backup_keep_time'] = 604800 ##一个周删除
上面两个都是gitlab的默认值,不设置就会按照默认值执行。
如果修改了值,请加载配置文件:
gitlab-ctl reconfigure
1、执行备份
在命令执行:
/usr/bin/gitlab-rake gitlab:backup:create
生成一次备份。
2、自动执行备份
每天中午十二点备份
(crontab -l; echo "00 12 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1")| crontab
3、恢复gitlab备份
需要先停止推送,拉去代码的服务,以防在恢复gitlab时,有人操作
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
执行恢复备份命令:
gitlab-rake gitlab:backup:restore BACKUP=备份数字名
即:1722409895_2024_07_31_17.2.1_gitlab_backup.tar文件名,就是这样
然后就会进入漫长的恢复,还能看见删表、建表的sql语句gitlab-rake gitlab:backup:restore BACKUP=1722409895_2024_07_31_17.2.1
4、默认的代码拉取地址是 :
http://gitlab.example.com/xxxxx
要改为自己gitlab服务器的地址:
[root@localhost ~]# vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
重启服务:
gitlab-ctl restart