PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

CentOS7 Gitlab 安装指南

PHPz
PHPz 原创
2023-03-31 13:44:58 566浏览

CentOS7 Gitlab 安装指南

概述

GitLab 是一款基于Git的Web界面的Git代码托管和代码审查的开源软件。它具有版本控制、代码审查、协作等功能,被认为是 GitHub 的完美替代品。本文将介绍在 CentOS7 上安装 GitLab 的过程。

系统要求

  • CentOS7 x64 系统,内存 2GB 以上;
  • 安装并启动 Nginx;
  • 安装并启动 PostgreSQL;
  • 安装并启动 Redis;
  • 开通 TCP 端口 22,80,443。

安装必要软件包

为了安装 GitLab,您需要在系统上安装一些必要软件包。

sudo yum -y update
sudo yum -y install curl openssh-server openssh-clients postfix cronie wget

安装 GitLab

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

GitLab 启动

sudo gitlab-ctl reconfigure

在完成 GitLab 的安装过程之后,可以使用以下命令启动 GitLab:

sudo gitlab-ctl start

访问 GitLab

默认情况下,GitLab 使用 HTTP 协议的 80 端口,因为在安装 GitLab 的过程中已经安装了 Nginx,所以可以通过访问服务器的 IP 地址或域名来访问您的 GitLab 实例。

http://<your-server-ip>

第一次访问 Gitlab

当您第一次访问您的 GitLab 实例的时候,需要设置一个管理员密码,以便在下一次访问时进行身份验证。

在浏览器中访问 GitLab 实例时,会自动定向到密码设置页面。输入密码并点击 "设置密码" 按钮。密码必须至少包含一个小写字母、一个大写字母、一个数字和一个非字母的字符,长度至少为 8 个字符。如下图所示:

Gitlab-管理员密码设置

设置密码后,会自动定向到登录页面,使用您刚刚设置的密码登录即可。

Nginx 反代

Nginx 反代可以加速 GitLab 运行速度。

修改 GitLab 配置文件

sudo vim /etc/gitlab/gitlab.rb

找到下面这一行:

external_url 'http://gitlab.example.com'

将其中的 http://gitlab.example.com 更改为您的域名或 IP 地址。然后将配置写入 GitLab。

sudo gitlab-ctl reconfigure

配置 Nginx

创建一个新的 Nginx 配置文件:

sudo touch /etc/nginx/conf.d/gitlab.conf
sudo vim /etc/nginx/conf.d/gitlab.conf

添加以下内容:

upstream gitlab-workhorse {
  server 127.0.0.1:8181 fail_timeout=0;
}

server {
  listen 80;

  # Replace with your domain name
  server_name gitlab.example.com;
  server_tokens off; ## Don't show the nginx version number, a security best practice

  location / {
    # Change this to the protocol you prefer/require.
    proxy_pass http://gitlab-workhorse;

    # Enable websocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 180;
    proxy_send_timeout 180;
  }
}

将里面的 gitlab.example.com 更改为您的 Nginx 域名或 IP。

重启 Nginx。

sudo systemctl restart nginx.service

访问 GitLab 界面。

http://gitlab.example.com

总结

在 CentOS7 上搭建 GitLab 不难,遵循上述步骤可以在短时间内完成基本安装。如果您需要更高级别的配置,可以按照 GitLab 官方文档中提供的方式进行操作。

参考文献

  • [1] GitLab.com
  • [2] GitLab Documentation
  • [3] How to Install Gitlab, Nginx and SSL on CentOS 7
  • [4] How To Install and Configure GitLab on CentOS 7

以上就是CentOS7 Gitlab 安装指南的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。