ReturnTmp's Blog ReturnTmp's Blog
首页
基础课程
编程语言
框架技术
运维笔记
人工智能
随笔摘录
  • 友链
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

ReturnTmp

分享有趣好玩的计算机知识
首页
基础课程
编程语言
框架技术
运维笔记
人工智能
随笔摘录
  • 友链
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Jenkins | VuePress博客自动化部署
  • 三步教你轻松安装配置 Linux Anaconda 环境
  • Windows SSH 远程连接 Linux
  • VuePress 数学公式支持
  • 一文教你如何防御数据库渗透入侵
  • WSL2 Ubuntu20.04 配置 CUDA
  • 前端开发部署运维笔记
  • 运维监控指南
  • 如何使用『Nginx』配置后端『HTTPS』协议访问
  • 华为云云耀云服务器L实例评测|搭建您的私人影院网站
  • 华为云云耀云服务器L实例评测|服务器反挖矿防护指南
  • 华为云云耀云服务器L实例评测|Git 私服搭建指南
    • 前言
    • 云服务器
    • GitLab 私服
      • 简介
      • Ubuntu
      • 依赖配置
      • 开始安装
      • 登录应用
      • 502 解决方案
      • 成功访问
      • CentOS
      • 依赖配置
    • Codeup 平台
      • 创建代码库
      • 配置 SSH
      • 查看密钥
      • 生成密钥
      • 复制密钥(winodws)
      • 设置平台公钥
      • SSH 公钥配置
      • 多密钥配置
      • 部署密钥(可选)
    • 参考文章
  • VSCode『SSH』连接服务器『GUI界面』传输
  • 『硅云』海外云服务器购买指南
  • GitHub Unfork 指南
  • 摆脱推荐算法,实现万物皆可『RSS』
  • Drone 指南
  • 教你如何『SSH』远程连接『内网』服务器
  • 『GitHub Actions』静态博客部署指南
  • Nginx 配置路径解析
  • 『pnpm』多项目环境迁移指南
  • Nginx 403 forbidden 问题
  • 你知道『SSH』为什么安全吗
  • 手把手教你如何给『Linux』打补丁
  • KVM Anolis OS 环境搭建
  • Docker 快速搭建 MySQL 高可用集群
  • RabbitMQ 入门指南(安装,配置,应用)
  • linux JDK8 环境配置
  • 发布策略
  • Spring Cloud Gateway + Nacos 灰度发布
  • Nginx 负载均衡集群 节点健康检查
  • 前端监控搭建
  • 运维监控系统
  • MySQL 可视化监控
  • MySQL 死锁问题排查与解决
  • Zookeeper Windows 安装配置(单机 - 集群)
  • 阿里云服务器镜像迁移
  • git clone 失败问题
  • Couldn't find ffmpeg or avconv 问题
  • 运维笔记
ReturnTmp
2023-09-15
目录

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

# 前言

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

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

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

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

# 云服务器

本章节主要讲解 云耀云服务器L实例 购置过程中的细节步骤,并且会给出合适的配置建议

首先点击以下链接进入华为官方服务器实例购买首页

官方链接:云耀云服务器L实例 _【最新】_轻量云服务器_轻量服务器_轻量应用服务器-华为云 (huaweicloud.com) (opens new window)

然后的话按照如下配置即可,这里博主推荐的是 CentOS 7.9 ,比较稳定

image-20231026192832133

其中实例规格的话,对于个人学习使用,或者是搭建访问量不高的网站 2 核 2 G 的话基本够用

image-20231026192958798

您也可以根据需要增加数据盘、开启主机安全、开启云备份等定制化的服务,最后点击购买即可,然后就可以进入下一章节搭建私服了

# GitLab 私服

# 简介

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

# Ubuntu

Ubuntu 20.04

# 依赖配置

配置依赖

sudo apt-get update -y
sudo apt-get install -y curl openssh-server ca-certificates postfix
1
2

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

sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
1
2
3
4

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

sudo systemctl enable postfix
sudo systemctl start postfix
1
2

# 开始安装

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

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

首先信任 GitLab 的 GPG 公钥:

curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
1
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
1
2

最后安装 gitlab-ce

sudo apt-get update
sudo apt-get install gitlab-ce
1
2

安装成功

image-20230915171802348

配置端口及网址

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

# 编辑文件
vim /etc/gitlab/gitlab.rb

external_url 'http://gitlab.example.com'
# 更改为如下
external_url 'http://<本机ip>:8899'
1
2
3
4
5
6

重新配置

sudo gitlab-ctl reconfigure
# 开启应用
sudo gitlab-ctl start
1
2
3

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

nohup /opt/gitlab/embedded/bin/runsvdir-start &
gitlab-ctl reconfigure
1
2

配置成功

image-20230915183125595

# 登录应用

我们注意到上面我们使用 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.
1
2
3
4
5

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

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

sudo ufw allow <端口>
sudo ufw deny <端口>
# 关闭 ufw
systemctl stop ufw.service
1
2
3
4

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

# 502 解决方案

vim /etc/gitlab/gitlab.rb
# 添加下面一行(14.x以下)
unicorn['port'] = 8088
# 14.x 及其以上
puma['port'] = 8088
1
2
3
4
5

重启应用

gitlab-ctl reconfigure
gitlab-ctl restart
1
2

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

# 成功访问

最后终于成功访问 GitLab 页面

image-20230915210129983

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

cat /etc/gitlab/initial_root_password
1

image-20230915210304181

创建项目

image-20230915210720634

添加 SSH

image-20230915210834219

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

image-20230915211248955

# CentOS

CentOS 7.6

# 依赖配置

sudo yum install -y curl policycoreutils-python openssh-server perl
1

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

sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
1
2
3
4

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

sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
1
2
3

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

# Codeup 平台

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

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

# 创建代码库

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

image-20230915181428618

# 配置 SSH

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

# 查看密钥

cat ~/.ssh/id_rsa.pub
1

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

# 生成密钥

ssh-keygen -t rsa -C "<注释内容>"
1

# 复制密钥(winodws)

cat ~/.ssh/id_rsa.pub | clip
1

# 设置平台公钥

# SSH 公钥配置

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

image-20230915190648682

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

image-20230915193452570

# 多密钥配置

编辑 ~/.ssh/config

# 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

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

  • 访问 Codeup ,由于 HostName 一致,使用别名进行区分使用不同的密钥。
  • 访问 GitLab,根据 HostName 进行区分使用不同的密钥。
# 访问 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
1
2
3
4
5
6
7
8

# 部署密钥(可选)

开启企业白名单

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

image-20230915190059109

新建密钥,然后粘贴公钥

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

image-20230915190146044

# 参考文章

搭建GitLab私服详细步骤_git私服_晴空๓的博客-CSDN博客 (opens new window)

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

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

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

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

编辑 (opens new window)
上次更新: 2023/11/13, 06:42:54
华为云云耀云服务器L实例评测|服务器反挖矿防护指南
VSCode『SSH』连接服务器『GUI界面』传输

← 华为云云耀云服务器L实例评测|服务器反挖矿防护指南 VSCode『SSH』连接服务器『GUI界面』传输→

最近更新
01
百度网盘加速
03-24
02
新版 PyCharm 设置 Conda 虚拟环境
03-24
03
腾讯云域名转到阿里云
03-24
更多文章>
Theme by Vdoing | Copyright © 2023-2024 ReturnTmp | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式