安装 Gitlab

虚拟机建议 cpu 分配 2核及以上,内存 4G 以上

方式一、使用 rpm 包安装

清华大学开源软件镜像站
rpm包地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el9/gitlab-ce-17.9.6-ce.0.el9.x86_64.rpm

# 下载完 rpm 包后放到 linux root 目录下,然后直接安装
dnf install gitlab-ce-17.9.6-ce.0.el9.x86_64.rpm -y

# 安装完成后,打开 /etc/gitlab/gitlab.rb,然后修改其中的 external_url 为虚拟机 ip
# external_url 'http://192.168.31.111'

# 运行下面的命令来启动 gitLab 实例
sudo gitlab-ctl reconfigure

# 启动完成会有下面输出,提示用户名是 root,密码在 /etc/gitlab/initial_root_password 中
# 密码文件24小时后会失效并自动删除,登陆 gitlab 后,先重置密码
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.

# 查看登陆密码,里面的Password: 后面的值就是 root 默认的登陆密码
cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: OIRZsVzNqBP8CtGKJGWYOmk2zkFMFbGzgQkkaqpSV+s=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

方式二、使用 docker 安装

1、安装 docker
# 添加阿里云docker-ce仓库
dnf config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 列出当前系统中所有可安装的 docker-ce 版本,并按照版本号从高到低进行排序,同时显示重复的版本。
dnf list docker-ce --showduplicates | sort -r
# 安装最新版本 docker-ce,也可以指定版本安装(dnf install -y docker-ce-20.10.15-3.el9.x86_64)
dnf install -y docker-ce
# 启用Docker Cgroup用于限制进程的资源使用量,如CPU、内存资源
# 创建目录,存放 docker 的配置文件
mkdir /etc/docker
# 创建并写入 /etc/docker/daemon.json 文件,设置 Docker 使用 systemd 作为 Cgroup 驱动
# registry-mirrors 配置:docker 镜像加速器的地址列表。
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": [
    "https://qa9ktbtj.mirror.aliyuncs.com",
    "https://docker.m.daocloud.io",
    "https://docker.mirrors.ustc.edu.cn",
    "https://www.daocloud.io/mirror"
  ]
}
EOF
# 设置 docker 开机自启
systemctl enable docker
# 启动 docker
systemctl start docker
# 查看 docker 状态
systemctl status docker
2、下载 gitlab
docker pull gitlab/gitlab-ce:latest
3、安装 gitlab

方式 1: 使用 Docker 直接运行 GitLab CE

# hostname 替换为虚拟机 ip
# hostname 替换为虚拟机 ip
docker run -d \
  --name gitlab \
  --hostname 192.168.31.111 \
  --restart unless-stopped \
  -e GITLAB_OMNIBUS_CONFIG="
    external_url 'http://192.168.31.111';
    gitlab_rails['gitlab_shell_ssh_port'] = 2222;
  " \
  -p 80:80 \
  -p 443:443 \
  -p 2222:22 \
  -v /srv/gitlab/config:/etc/gitlab \
  -v /srv/gitlab/logs:/var/log/gitlab \
  -v /srv/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

方式 2:使用 Docker Compose 安装(推荐)

root 目录下创建 gitlab.yaml 文件,内容如下:
version: '3.6'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: 'gitlab'
    restart: always
    hostname: '192.168.31.111' # hostname 替换为虚拟机 ip
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://192.168.31.111' # 替换为虚拟机 ip
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
    ports:
      - '80:80'
      - '443:443'
      - '2222:22'
    volumes:
      - '/srv/gitlab/config:/etc/gitlab'
      - '/srv/gitlab/logs:/var/log/gitlab'
      - '/srv/gitlab/data:/var/opt/gitlab'
# 启动 gitlab 服务
docker compose -f gitlab.yaml up -d

# 等待几分钟让 gitLab 完全启动(首次启动可能需要较长时间)
# 可以通过 docker ps 查看 gitlab 是否完全启动,如下所示,STATUS 为 healthy 后说明成功启动,如果是 starting 说明还在启动中

[root@gitlab ~]# docker ps
CONTAINER ID   IMAGE                     COMMAND                  CREATED       STATUS                    PORTS                                                                                                                   NAMES
24b5a0b86dd6   gitlab/gitlab-ce:latest   "/assets/init-contai…"   3 hours ago   Up 13 minutes (healthy)   0.0.0.0:80->80/tcp, [::]:80->80/tcp, 0.0.0.0:443->443/tcp, [::]:443->443/tcp, 0.0.0.0:2222->22/tcp, [::]:2222->22/tcp   gitlab

# 访问 http://192.168.31.111 或你配置的域名
# 首次访问会要求设置 root 用户密码,密码在 /srv/gitlab/config/initial_root_password 文件中
# Password: 后面对应的就是登陆密码
# 该文件24小时后会失效并自动删除,登陆 gitlab 后,先重置密码
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容