git,  linux

安装gitlab-ce ( 社区版 )

环境:cenots7

添加GitLab 仓库
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安装gitlab-ce ( 社区版 )
yum install -y gitlab-ce
配置gitlab完成初始化工作
vim /etc/gitlab/gitlab.rb

将external_url ‘http://xxxx.xxxx.xxxx.xxxx‘修改成你自己的域名地址或ip
例如:external_url “http://gitlab.example.com”

重新编译配置并启动 GitLab

gitlab-ctl reconfigure
gitlab-ctl start

防火墙需放行80,443端口
浏览器访问域名或ip进行登录,一开始会得到一个密码重置页面,输入密码后,使用默认用户root 登录。

启用https访问(通过ip地址访问gitlab,请跳过此步骤)

申请Let’s Encrypt的证书
安装certbot

yum install epel-release -y
yum install python2-certbot-nginx -y

获取证书,根据提示填入域名,站点等信息

certbot certonly

申请完成后,证书会放到 /etc/letsencrypt/live/gitlab.example.com 目录下

配置gitlab支持https,支持ipv6,设置时区

vim /etc/gitlab/gitlab.rb
external_url "https://gitlab.example.com"
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/letsencrypt/live/gitlab.example.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/gitlab.example.com/privkey.pem"
nginx['listen_addresses'] = ['*', '[::]']
gitlab_rails['time_zone'] = 'Asia/Shanghai'

gitlab 重新编译配置

gitlab-ctl reconfigure

到此你已完成gitlab安装

Gitlab备份

使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab备份:

gitlab-rake gitlab:backup:create

使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1510886635_2022_06_24_15.0.0_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1510886635_2022_06_24_15.0.0是备份创建的日期和版本

另外需要备份以下文件;

/etc/gitlab/gitlab.rb          gitlab 配置文件备份
/var/opt/gitlab/nginx/conf     nginx配置文件 备份
/etc/gitlab/ssl                SSL文件目录需要备份
Gitlab自动备份

实现每晚21点进行一次自动备份:通过crontab使用备份命令实现

00 21 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
Gitlab恢复

停止相关数据连接服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

修改ownership

chown git.git 1510886635_2022_06_24_15.0.0_gitlab_backup.tar

从1510886635_2022_06_24_15.0.0 编号备份中恢复

gitlab-rake gitlab:backup:restore BACKUP=1510886635_2022_06_24_15.0.0

启动Gitlab

gitlab-ctl start
GitLab迁移

需要注意的是新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同. 比如新服务器安装的是最新的15.0.0版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级为15.0.0在进行备份,否则在新服务器上恢复不了。

gitlab 更新

注意,gitlab 更新,一次只能更新一个次版本,比如 15.0.x 只能更新到 15.1.x , 而不能只能 15.2.x。另外,不同版本对于 postgresql 数据库版本也不尽相同,高版本有时候会采用更高版本的 postgresql 数据库,也要随着更新。

yum --showduplicates list all | grep gitlab |grep gitlab-ce  查看最新版本(gitlab-ce-15.1.0-ce.0.el7)
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION  现在版本(gitlab-ce-15.0.0-ce.0.el7)
yum update  gitlab-ce-15.1.0-ce.0.el7
gitlab-ctl reconfigure

留言

您的电子邮箱地址不会被公开。 必填项已用*标注