Ubuntu18.04服务器上搭建GitLab仓库、管理员密码重置以及Gitlab卸载及本地安装指定版本Gitlab

一、Ubuntu18.04服务器上搭建GitLab仓库及管理员密码重置

首先安装一些基础服务,openssh-server让远程主机可以通过网络访问sshd服务,开始一个安全shell,ca-certificates维护SSL证书的。postfix是GPL协议之下的MTA(邮件传输代理)软件。postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试。在安装postfix,选择 Internet Site确定即可。

bash 复制代码
#安装一些基础服务
apt-get update
apt-get install -y curl openssh-server ca-certificates postfix

#接着下载gpg信任GitLab的公钥
curl https://packages.gitlab.com/gpg.key 2> /dev/null | apt-key add - &>/dev/null  

#配置镜像路径为国内仓库,以名国外的下载速度慢。根据系统版本添加对应URL如下
vim /etc/apt/sources.list.d/gitlab-ce.list
#添加以下内容
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main

上面这些工作做好之后就可以开始安装gitlab-ce

bash 复制代码
apt-get update
apt-get install gitlab-ce
#执行配置后启动gitlab
gitlab-ctl reconfigure
gitlab-ctl start

这里安装的是GitLab Community Edition 13.12.8版本,然后使用http://IP地址 即可浏览访问。第一次进入界面,需要两次输入以初始化管理员密码,登录账号是root。这样gitlab已安装成功。gitlab的配置文件路径/etc/gitlab/gitlab.rb ,可在其中配置gitlab的端口和地址。每次配置有更改,需要执行 gitlab-ctl reconfigure 加载新的配置。gitlab常用命令列表如下:

gitlab-ctl stop #停止

gitlab-ctl start #启动

gitlab-ctl restart #重启

gitlab-ctl status #查看状态

gitlab-ctl reconfigure #更新配置

gitlab-ctl tail #查看日志

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION #查看GitLab 版本号

在维护过程 中如果忘了帐户的密码,可以使用gitlab-rails来重置管理员密码。

bash 复制代码
#执行命令
# gitlab-rails console
Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
#查找用户
irb(main):001:0> user = User.where(username: 'root').first
=> #<User id:1 @root>
#修改密码
irb(main):002:0> user.password = '123456'
=> "123456"
#保存密码修改
irb(main):003:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID:) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change"..
=> true

二、Gitlab卸载及本地安装指定版本Gitlab

因Gitlab整体数据迁移需要两边版本一致,如果版本不同,会在数据导入的时候报错版本不匹配:Unpacking backup ... done

GitLab version mismatch:

Your current GitLab version (13.12.8) differs from the GitLab version in the backup!

Please switch to the following version and try again:

version: 13.3.5-ee

所以准备卸载之前安装的gitlab,并更换成另一个版本。停止服务并卸载过程:

bash 复制代码
gitlab-ctl stop
gitlab-ctl uninstall
dpkg -r gitlab-ce
ps -ef |grep gitlab

安装当然可以使用脚本直接执行安装,我这里是直接下载安装包。安装包下载地址:gitlab/gitlab-ce - Packages · packages.gitlab.com 对于每一个版本在Distro/Version列都有ubuntu/xenial,ubuntu/bionic,ubuntu/focal三个细分版本。它们是ubuntu的代号。在ubuntu服务器上执行 lsb_release -a可以查看到当前服务器版本的代号Codename。

lsb_release -a

Codename: bionic

因此我这里下载时就下载ubuntu/bionic对应的版本。
gitlab/gitlab-ce - Results for '13.3.5' and ubuntu in gitlab/gitlab-ce

下载完成后进行本地安装

dpkg -i gitlab-ce_13.3.5-ce.0_amd64.deb

不过在这里也碰到了一个问题,我在上面的网址里下载的deb文件安装时提示deb文件不是一个有效的包,dpkg-deb: error: 'gitlab-ce_13.3.5-ce.0_amd64.deb' is not a Debian format archive。看文件大小只有15K,之后我在另一个网址Index of /gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror 里下载的,地址如下:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/gitlab-ce_13.3.5-ce.0_amd64.deb 文件大小有700M+。

bash 复制代码
#修改配置文件,加载配置并启动gitlab
vim /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
gitlab-ctl status
相关推荐
Avan_菜菜10 小时前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
SelectDB1 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
zzzzzz3103 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode3 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220703 天前
如何搭建本地yum源(上)
运维
大树886 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠6 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质6 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
小宇宙Zz6 天前
Maven依赖冲突
java·服务器·maven
Inhand陈工7 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信