Gitlab 安装升级操作指令集

https://blog.csdn.net/qq_43626147/article/details/109160229

https://cloud.tencent.com/developer/article/1622317

安装Gitlab

安装必要依赖

yum -y install curl policycoreutils policycoreutils-python openssh-server openssh-clients postfix

postfix是发送邮件用的,需要配置一下,编辑文件/etc/postfix/main.cf

inet_interfaces=all
inet_protocols=all

修改完执行

systemctl start postfix
systemctl enable postfix

配置yum源

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

然后去清华官网下载对应版本的rpm文件

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

随便找个文件夹wget一下并本地安装

yum -y localinstall gitlab-ce-13.1.4-ce.0.el7.x86_64.rpm

编辑配置文件

文件路径/etc/gitlab/gitlab.rb

# 对外服务路径
external_url 'https://git.lacus.site'

# 发送邮件显示信息
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '1144131090@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'Yingbo'

# 邮件服务器配置
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1144131090@qq.com"
gitlab_rails['smtp_password'] = "pyoqbwooqfrwhfjb"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false

# 容器镜像库配置
registry_external_url 'https://git.lacus.site:5050'
gitlab_rails['registry_enabled'] = true

# 修改端口避免冲突
unicorn['port'] = 7000

# nginx配置
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/git.lacus.site.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/git.lacus.site.key"

registry_nginx['enable'] = true

# 关闭prometheus占用过多内存
prometheus['enable'] = false
prometheus['monitor_kubernetes'] = false

# nginx写死了证书路径就不用自动申请了
letsencrypt['enable'] = false

生成证书文件夹

mkdir -p /etc/gitlab/ssl
chmod -R 777 /etc/gitlab/ssl/

git.lacus.site.keygit.lacus.site.crt放到该文件夹下

生效配置

gitlab-ctl reconfigure

备份Gitlab

在gitlab正常运行时执行gitlab-rake gitlab:backup:create

会在/var/opt/gitlab/backups目录下生成对应的tar压缩包

/etc/gitlab/gitlab.rb 配置文件须备份

/var/opt/gitlab/nginx/conf nginx配置文件

/etc/postfix/main.cfpostfix 邮件配置备份

正常恢复只需要rb文件以及tar压缩包

修改备份文件目录

修改/etc/gitlab/gitlab.rb

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

修改备份过期时间

修改/etc/gitlab/gitlab.rb

gitlab_rails['backup_keep_time'] = 604800

自动备份

创建定时任务crontab -e

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

恢复Gitlab

先停止相关服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

恢复指定id版本

gitlab-rake gitlab:backup:restore BACKUP=1653627206_2022_05_27_13.1.4

升级路径

8.11.Z -> 8.12.0 -> 8.17.7 -> 9.5.10 -> 10.8.7 -> 11.11.8 -> 12.0.12 -> 12.1.17 -> 12.10.14 -> 13.0.14 -> 13.1.11 -> 13.8.8 -> 13.12.15 -> 14.0.12 -> 14.9.0 -> latest 14.Y.Z

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.1.11-ce.0.el7.x86_64.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.8.8-ce.0.el7.x86_64.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.12.15-ce.0.el7.x86_64.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.0.12-ce.0.el7.x86_64.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.9.0-ce.0.el7.x86_64.rpm
yum -y localinstall gitlab-ce-13.1.11-ce.0.el7.x86_64.rpm
yum -y localinstall gitlab-ce-13.8.8-ce.0.el7.x86_64.rpm
yum -y localinstall gitlab-ce-13.12.15-ce.0.el7.x86_64.rpm
yum -y localinstall gitlab-ce-14.0.12-ce.0.el7.x86_64.rpm
yum -y localinstall gitlab-ce-14.9.0-ce.0.el7.x86_64.rpm

常用命令

查看版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

实时查看日志

gitlab-ctl tail

数据库关系升级

gitlab-rake db:migrate

清理redis缓存

gitlab-rake cache:clear

升级PostgreSQL最新版本

gitlab-ctl pg-upgrade

启动/停止/重启所有 gitlab 组件:

gitlab-ctl start/stop/restart

启动指定模块组件

gitlab-ctl start redis/postgresql/gitlab-workhorse/logrotate/nginx/sidekiq/unicorn

停止指定模块组件

gitlab-ctl stop 模块名

查看服务状态

gitlab-ctl status

生成配置并启动服务

gitlab-ctl reconfigure

相关问题

Chef Infra Client failed

大概率是因为数据库关系错误引起的

查询数据库关系gitlab-rake db:migrate:status

如果有down的说明数据库关系错误,需要执行修复

gitlab-rake db:migrate

修复完成后,重启 GitLab 或重新 reconfigure 即可。

为了保险起见,以及便于后续升级,建议手动升级一下数据库(当然,前提是要做好备份。):

gitlab-ctl pg-upgrade

runner控制页面500

秘钥在读取的时候发生错误导致的,可以尝试进行重置runner_registration_token进行恢复,前提是之前的秘钥会丢失

gitlab-rails console
# in console
ApplicationSetting.current.reset_runners_registration_token!
exit


系统   gitlab      gitlab 工具

本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!