人间熙攘,好久不见

vuePress-theme-reco Magic    2017 - 2023
人间熙攘,好久不见 人间熙攘,好久不见

Choose mode

  • dark
  • auto
  • light
Home
Category
  • tools
  • Zsh
  • iTerm2
  • Front-end
  • 版本控制-Git
  • Rust
  • skia-safe
  • 第三方对接
  • MQTT
  • Powershell
  • python
  • MD5
  • SHA1
  • wsl2
Tags
TimeLine
GitHub
  • Github (opens new window)
  • Before (opens new window)
author-avatar

Magic

23

文章

15

标签

Home
Category
  • tools
  • Zsh
  • iTerm2
  • Front-end
  • 版本控制-Git
  • Rust
  • skia-safe
  • 第三方对接
  • MQTT
  • Powershell
  • python
  • MD5
  • SHA1
  • wsl2
Tags
TimeLine
GitHub
  • Github (opens new window)
  • Before (opens new window)
  • Git

    • git 一些骚操作
    • git commit emoji 使用指南
    • gitlab 搭建
    • git 设置代理
    • git 相关总结

gitlab 搭建

vuePress-theme-reco Magic    2017 - 2023

gitlab 搭建

Magic 2023-06-21 Git

# Gitlab 搭建

# 前置条件

  • Gitlab 官网 (opens new window)
  • 以下 基于 wsl2 的 Ubuntu 20.04.6 LTS (opens new window) 安装的,推荐直接使用 Microsoft Store 的 Ubuntu 20.04.6 LTS (opens new window) 安装,这样就可以在 Windows Terminal (opens new window) 直接使用
  • wsl 教程推荐 Dev on Windows with WSL (opens new window)

# 更新软件并安装依赖项

# 更新软件
sudo apt-get update
# 安装依赖项
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl

# 安装 GitLab

# 安装 Gitlab 社区版 前置脚本相关
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-c e/script.deb.sh | sudo bash
# 安装 GitLab 社区版
sudo apt-get install gitlab-ce
  • 网络不好的情况下可以手动安装

    • 下载软件包地址:gitlab-ce (opens new window)
    • 执行 wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/bionic/gitlab-ce_16.1.0-ce.0_amd64.deb/download.deb 下载到本地
    • 安装:sudo dpkg -i gitlab-ce_16.1.0-ce.0_amd64.deb
  • 安装成功后会看到

gitlab icon

sudo gitlab-cli reconfigure # 等相关文案

# 配置对外 IP 和 默认端口

因为是在 wsl 中搭建的,所以需要获取 windows 主机映射 wsl 的 ip 地址以便我们可以在 主机端访问:

# 一种方法
ip route | grep default | awk '{print $3}'
# 或者另一种方法
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'

输出内容:

ip_route_grep

# 修改配置文件
sudo vim /etc/gitlab/gitlab.rb
# 修改 external_url
external_url 'http://172.25.168.1:5656'

# 修改时区

# 修改配置文件
sudo vim /etc/gitlab/gitlab.rb
# 修改时区 后保存
gitlab_rails['time_zone'] = 'Asia/Shanghai'

# 启动 GitLab

# 停止服务
sudo gitlab-ctl stop
# 启动服务,修改配置后要执行这个命令
sudo gitlab-ctl reconfigure
# 重启所有gitlab组件
sudo gitlab-ctl restart
# 启动所有gitlab组件
sudo gitlab-ctl start

# 配置GitLab开机自启动、关闭开机自启动

# 启用 Gitlab开机自启动 :
systemctl enable gitlab-runsvdir.service
# 禁止 Gitlab 开机自启动:
systemctl disable gitlab-runsvdir.service

# 登录 GitLab

浏览器访问上文配置的地址: external_url,这里我们要用 127.0.0.1:5656 来访问,然后使用 root 登陆,初始密码在:/etc/gitlab/initial_root_password 文件下,使用该密码登陆后修改密码。

# GitLab 常用命令

# 重新加载配置,每次修改/etc/gitlab/gitlab.rb文件之后执行
sudo gitlab-ctl reconfigure
# 查看 GitLab 状态
sudo gitlab-ctl status
# 启动 GitLab
sudo gitlab-ctl start
# 停止 GitLab
sudo gitlab-ctl stop
# 重启 GitLab
sudo gitlab-ctl restart
# 查看所有日志
sudo gitlab-ctl tail
# 查看 nginx 访问日志
sudo gitlab-ctl tail nginx/gitlab_acces.log
# 查看 postgresql 日志
sudo gitlab-ctl tail postgresql

# 注意

  • 如果启动时遇到 ruby_block[wait for redis service socket] action run is blocking,可以另起一个窗口运行 sudo /opt/gitlab/embedded/bin/runsvdir-start:https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/4257 (opens new window)

# CI/CD

TODO:

欢迎来到 人间熙攘,好久不见
看板娘