Ubuntu安装Gitlab详细图文教程

1、环境准备

1.1、Ubuntu环境

Ubuntu24.04Sever版安装教程

1.2、更新系统

复制代码
sudo apt update -y
sudo apt-get update
sudo apt-get upgrade

2、安装Nginx

2.1 安装nginx

复制代码
# 安装
apt install nginx -y

2.2 修改nginx配置⽂件

修改nginx配置

vim /etc/nginx/sites-available/default

复制代码
upstream gitlab {
# 端口对应 gitlab 配置中的 nginx['listen_port']
 server 127.0.0.1:82;
}
server{
 listen 80;
 # 此域名是提供给最终用户的访问地址。域名对应 gitlab配置中的 external_url,没有域名可以不设置
 server_name gitlab.company.com;
 location / {
 # 这个大小的设置非常重要,如果 git 版本库里面有大文件,设置的太小,文件push 会失败,根据情况调整
 client_max_body_size 500m;
 proxy_redirect off;
 #以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 # 反向代理到 gitlab 内置的 nginx
 proxy_pass http://gitlab;
 index index.html index.htm;
 }
}

3、安装gitlab

选择一个社区稳定版,GitLab的稳定版本通常是每个大版本中的最后一个小版本更新‌,因为它包含了自大版本发布以来的所有错误修复和性能改进‌。例如,GitLab 16.8版本就是一个相对稳定的版本,它增加了GCP Secret Manager支持、工作区全面可用性、使用Maven依赖代理加速构建等功能。

3.1、下载gitlab

版本可以在官⽹选择,如下:

gitlab官网:gitlab/gitlab-ce - Packages · packages.gitlab.com

3.1.1、下载安装包-这里选择的版本:社区版16.8.10

复制代码
 wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/focal/gitlab-ce_16.8.10-ce.0_amd64.deb/download.deb

3.1.2、安装deb文件

复制代码
sudo dpkg -i gitlab-ce_16.8.10-ce.0_amd64.deb

3.1.3、安装Gitlab程序

复制代码
sudo apt-get install gitlab-ce=16.8.10-ce.0

3.1.4、修改配置文件

先创建仓库存储目录

mkdir /opt/gitlab/data

修改配置文件

vi /etc/gitlab/gitlab.rb

复制代码
##修改内容(开头中的nginx配置有要对应):
external_url 'http://gitlab.company.com'
# 端口对应 nginx配置中的 server:端口
nginx['listen_port'] = 82
# 仓库存储目录
git_data_dirs({
        "default" => { "path" => "/home/gitlab/data" }
})

3.2、环境配置 -加在配置信息(第一次加载很慢)

复制代码
sudo gitlab-ctl reconfigure

查看root临时密码,如下:

复制代码
 cat /etc/gitlab/initial_root_password

复制root密码,登录,如下图:

按下面的步骤将gitlab语言设置为中文: 注意点击Preferences,如下图:

保存后,刷新页面,效果如下图:

3.3、修改root密码

3.3.1、通过production命令修改

production命令执行时间比较长,需要等待ruby控制台。成功后会显示:

复制代码
cd /opt/gitlab/bin
sudo gitlab-rails console -e production
user=User.where(id:1).first
user.password='RunDict1453'
user.password_confirmation='RunDict1453'
user.save!
exit

3.3.2、通页面修改

3.3.3、gitlab常用命令

复制代码
# 启动gitlab
gitlab-ctl start
# 重启gitlab
gitlab-ctl restart
# 停止gitlab
gitlab-ctl stop
# 查看gitlab日志
gitlab-ctl tail

至此安装完成,可以使用,如下图:

相关推荐
暴躁哥2 小时前
Git 版本控制系统入门指南
git
diving deep4 小时前
IDEA中git对于指定文件进行版本控制
git
趁你还年轻_7 小时前
记录一次git提交失败解决方案
git
关于不上作者榜就原神启动那件事10 小时前
git版本控制学习
git·学习
Cchaofan17 小时前
Git/GitLab日常使用的命令指南来了!
git·gitlab
可乐加.糖1 天前
项目版本管理和Git分支管理方案
java·git·目标跟踪·gitlab·敏捷流程·源代码管理
wingaso1 天前
[经验总结]删除gitlab仓库分支报错:错误:无法推送一些引用到“http:”
linux·数据仓库·git
qianmoQ1 天前
GitHub 趋势日报 (2025年05月14日)
github
ice___Cpu1 天前
Git - 1( 14000 字详解 )
大数据·git·elasticsearch
Yvonne爱编码1 天前
CSS- 2.1 实战之图文混排、表格、表单
前端·css·html·github·状态模式·html5·hbuilder