华为云云耀云服务器L实例评测|Git 私服搭建指南

前言

本文为华为云云耀云服务器L实例 测评文章,测评内容是 云耀云服务器L实例 Git 私有服务器搭建指南

系统配置:2核2G 3M Ubuntu 20.04

我们平时在使用代码托管服务的时候,可能某些代码托管平台对成员有限制,或是由于内容原因会对仓库进行封禁,这些问题让我们非常苦恼。这个时候搭建 Git 私服不失为一种不错的替代方案

下面将会讲解两种搭建 Git 私服方式:GitLab 私服和 Codeup 平台

GitLab 私服

简介

GitHub 和 GitLab 都是基于 Git 的开发流程代码托管平台。两者的区别是 GitHub 有私有仓库和共有仓库,私有仓库一般收费GitLab 打破这种限制,可以免费搭建私有仓库,并且可以部署在自己的服务器上。GitLab 不仅有 GitHub 的功能,还有更多的优秀特性,比如权限设置。一般企业内部软件产品用 GitLab 是更好的选择,如果是开源产品,一般放在 GitHub 上。

Ubuntu

Ubuntu 20.04

依赖配置

配置依赖

bash 复制代码
sudo apt-get update -y
sudo apt-get install -y curl openssh-server ca-certificates postfix

系统防火墙中打开 HTTPHTTPS SSH 访问 (可选,不设置则只能从本地网络访问 )

bash 复制代码
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

开启 Postfix 以发送电子邮件通知 (可选)

bash 复制代码
sudo systemctl enable postfix
sudo systemctl start postfix
开始安装

清华镜像官网:gitlab-ce | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

然后获取您的系统对应版本的安装命令

首先信任 GitLab 的 GPG 公钥:

bash 复制代码
curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
bash 复制代码
touch /etc/apt/sources.list.d/gitlab-ce.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu focal main" | sudo tee -a /etc/apt/sources.list.d/gitlab-ce.list

最后安装 gitlab-ce

bash 复制代码
sudo apt-get update
sudo apt-get install gitlab-ce

安装成功

配置端口及网址

进入文件 /etc/gitlab/gitlab.rb,进行如下配置

bash 复制代码
# 编辑文件
vim /etc/gitlab/gitlab.rb

external_url 'http://gitlab.example.com'
# 更改为如下
external_url 'http://<本机ip>:8899'

重新配置

bash 复制代码
sudo gitlab-ctl reconfigure
# 开启应用
sudo gitlab-ctl start

但是这里重新配置很容易卡住,可以使用如下命令解决

bash 复制代码
nohup /opt/gitlab/embedded/bin/runsvdir-start &
gitlab-ctl reconfigure

配置成功

登录应用

我们注意到上面我们使用 sudo gitlab-ctl reconfigure 之后控制台出现的的下面的信息

复制代码
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.

上述输出表示在 GitLab 中,默认的管理员账户的用户名是"root",密码被存储在/etc/gitlab/initial_root_password文件中。同时该文件将在首次重新配置运行后的24小时内被清除。

访问之前 external_url 设置的网址,如果是在云服务器上的话,需要开启安全组和对应防火墙

bash 复制代码
sudo ufw allow <端口>
sudo ufw deny <端口>
# 关闭 ufw
systemctl stop ufw.service

但是访问之后出现 502 We're sorry. GitLab is taking too much time to respond. 问题

502 解决方案
bash 复制代码
vim /etc/gitlab/gitlab.rb
# 添加下面一行(14.x以下)
unicorn['port'] = 8088
# 14.x 及其以上
puma['port'] = 8088

重启应用

bash 复制代码
gitlab-ctl reconfigure
gitlab-ctl restart

还有问题就查看端口是否被占用,或是内存是否不足

成功访问

最后终于成功访问 GitLab 页面

查看 root 用户密码,登录之后尽量更改密码

bash 复制代码
cat /etc/gitlab/initial_root_password

创建项目

添加 SSH

最后使用两种方式克隆项目,进行开发即可

CentOS

CentOS 7.6

依赖配置
bash 复制代码
sudo yum install -y curl policycoreutils-python openssh-server perl

系统防火墙中打开 HTTPHTTPS SSH 访问 (可选,不设置则只能从本地网络访问 )

bash 复制代码
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

安装 Postfix 以发送电子邮件通知 (可选)

bash 复制代码
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

其他配置基本类似,这里不再赘述

Codeup 平台

平台官网:云效代码管理 Codeup_代码托管_企业级代码管理平台-阿里云 (aliyun.com)

阿里云-云效 Codeup 是一款企业代码托管平台,支持在线编写和在线 web IDE,非常适合大型企业及小型团队编写进行代码托管

创建代码库

首先我们注册成功之后会进入控制台,我们点击添加库创建代码库

配置 SSH

下面我们主要是使用 SSH(RSA) 的方式讲解如何管理代码库

查看密钥
bash 复制代码
cat ~/.ssh/id_rsa.pub

可以查看到密钥即可跳过第二步

生成密钥
plaintext 复制代码
ssh-keygen -t rsa -C "<注释内容>"
复制密钥(winodws)
bash 复制代码
cat ~/.ssh/id_rsa.pub | clip

设置平台公钥

SSH 公钥配置

配置页面:个人设置 (aliyun.com)

之后我们就可以连接 SSH 操作远程仓库了

多密钥配置

编辑 ~/.ssh/config

bash 复制代码
# Codeup 示例用户1
HostName codeup.aliyun.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519
  
# Codeup 示例用户2,设置别名 codeup-user-2
Host codeup-user-2
HostName codeup.aliyun.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/codeup_user_2_ed25519

# GitLab 平台
HostName gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitlab_ed25519

按照上述配置,使用SSH协议访问时,SSH 客户端会使用文件指定的密钥进行认证,实现访问不同平台或同一平台的不同账号使用本地不同的 SSH 密钥进行认证。

  • 访问 Codeup ,由于 HostName 一致,使用别名进行区分使用不同的密钥。
  • 访问 GitLab,根据 HostName 进行区分使用不同的密钥。
bash 复制代码
# 访问 Codeup,将使用 ~/.ssh/id_ed25519.pub 密钥
git clone git@codeup.aliyun.com:example/repo.com

# 以 codeup-user-2 别名访问 Codeup 时,将使用 ~/.ssh/codeup_user_2_ed25519 密钥 
git clone git@codeup-user-2:example/repo.com

# 访问 GitLab 平台,将使用 ~/.ssh/gitlab_ed25519 密钥
git clone git@gitlab.com:example/repo.com
部署密钥(可选)

开启企业白名单

网址:安全设置 · Codeup (aliyun.com)

新建密钥,然后粘贴公钥

注意:此公钥不可与上面的 SSH 公钥相同

参考文章

搭建GitLab私服详细步骤_git私服_晴空๓的博客-CSDN博客

Git学习笔记之搭建私服-腾讯云开发者社区-腾讯云 (tencent.com)

Ubuntu 18.04搭建GitLab私服_gitlab 服务器搭建 ubuntu18_沙漠中的独行者的博客-CSDN博客

linux中安装Gitlab服务器后登录报错502解决办法(图文结合)_青山孤客的博客-CSDN博客

gitlab-ce-10.0.2版本升级到15.4.2 - 掘金 (juejin.cn)

本文由博客一文多发平台 OpenWrite 发布!

相关推荐
不念霉运2 天前
2025 Gitee vs. GitLab:全面对比与选择指南
gitee·gitlab
水瓶_bxt2 天前
创建 GitLab Runner 使用CICD自动化部署容器
eureka·自动化·gitlab
黑心的奥利奥4 天前
Docker配置Gitlab-runner实现自动化容器化部署前端项目
docker·自动化·gitlab
wuzuyu3654 天前
在腾讯云上安装gitlab
云计算·gitlab·腾讯云
xiaodaiwang4 天前
OpenEuler 22.03 系统上安装配置gitlab runner
gitlab
TimberWill5 天前
gitlab私服搭建
gitlab
中东大鹅5 天前
访问 gitlab 跳转 0.0.0.0
gitlab
guygg885 天前
配置本地git到gitlab并推送
git·gitlab
大A崛起6 天前
Gitlab-CI实现组件自动推送
ci/cd·gitlab·github
越来越无动于衷6 天前
GitLab 社区版 10.8.4 安装、汉化与使用教程
gitlab