部署GitLab代码管理平台 2024

搭建公司/个人私有化的Gitlab/Github代码版本管理平台

文章耗时:5天(终于全流程走通),相关的应用或问题将持续更新。

怎么用

  • 条件:个人域名,公网IP的小主机或服务器(或购得的VPS或网络服务器)
  • 根据‘实现方法’中的步骤用docker搭建好gitlab平台
  • IDE或者命令行,或WEB UI,访问gitlab代码版本管理/控制等功能

相关内容

实现方法

Docker命令搭建

1
docker pull gitlab/gitlab-ce:latest
1
2
#实践过程中,这个下载过程需要持续好长时间,所以还单独使用docker pull
e05b9f286a50: Downloading [=====> ] 148.6MB/1.364GB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ce:latest
container_name: gitlab
restart: always
#hostname: 'HOSTNAME'
#environment:
# GITLAB_OMNIBUS_CONFIG:
# Add any other gitlab.rb configuration here, each on its own line
# external_url 'https://gitlab.carlzeng.top:3'
ports:
- '8097:80' #根据自身端口情况调整
- '4431:443' #根据自身端口情况调整
- '2222:22' #根据自身端口情况调整
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '256m'

这个docker-compose.yml文件,然后docker-compose up -d,在我的环境就能正常启动。

通过注释掉了environment 和 hostname的section以后可以正常启动,然后再耐心等待3-4分钟以后(不行就关闭重启来),启动成功

然后登录界面需要用户名和密码

1
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

这个命令可以获取初始化root用户的密码。或者使用config映射出来的目录,直接查看这个文件。

image-20240308105655373

配置连接Gitlab端口(非标准443端口)

git remote 非标准端口

测试使用IntelliJ IDEA来提交project到https://gitlab.carlzeng.top:3/

https://gitlab.carlzeng.top:3/root/proxypool.git

配置remote提示错误:unable to access ‘https://gitlab.carlzeng.top:3/root/proxypool':LibreSSL SSL_connect: Connection reset by peer in connection to gitlab.carlzeng.top:443

解决办法(以问题中的特定例子来举例说明):

  1. cd 到相应目录,执行一下命令
  2. git remote set-url origin https://gitlab.carlzeng.top:3/root/proxypool.git
  3. 在IDE中push提示登录时,使用root用户登录即可

友情提示:

1
git remote add origin  https://gitlab.carlzeng.top:3/root/proxypool.git

这条命令也可以使用,用来添加多个git的源(这样push的时候,多个远程仓库都可以同时得到更新);需要在命令行下切换到项目的主目录下使用。

Access denied

08:32:02.142: [goProjects] git -c core.quotepath=false -c log.showSignature=false push –progress –porcelain origin refs/heads/master:master
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://gitlab.carlzeng.top/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
fatal: Authentication failed for ‘https://gitlab.carlzeng.top:3/root/proxypool.git/

解决办法:

用root用户登录即可

Email SMTP setup

vi /etc/gitlab/gitlab.rb

![image-20240308164451369](/Users/carlzeng/Library/Application Support/typora-user-images/image-20240308164451369.png)

![image-20240308165425674](/Users/carlzeng/Library/Application Support/typora-user-images/image-20240308165425674.png)

1
2
docker-compose down   
docker-compose up -d

现有项目同步至私有仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 1. 添加新的project,在UI上操作
https://gitlab.carlzeng.top:3/root/pri-freight-container

# 2. 添加remote, 注意替换具体的仓库地址
git remote add origin_gitlab https://gitlab.carlzeng.top:3/root/pri-freight-container.git

# 3. Push 更新至远程(本地部署的gitlab平台)
git push origin_gitlab
# 命令输出展示
Enumerating objects: 667, done.
Counting objects: 100% (667/667), done.
Delta compression using up to 8 threads
Compressing objects: 100% (550/550), done.
Writing objects: 100% (667/667), 334.70 KiB | 8.58 MiB/s, done.
Total 667 (delta 334), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (334/334), done.
To https://gitlab.carlzeng.top:3/root/pri-freight-container.git
* [new branch] working -> working


image-20240311181747412

灵感来源

Gitlab install | SMTP Mail configure and test on Linux | User create delete password change

Git中的ssh和https及相关问题