指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

使用docker搭建gitlab-ce:

三大步骤:

1>配置镜像

$ docker pull docker.1ms.run/gitlab/gitlab-ce:latest
$ docker image tag docker.1ms.run/gitlab/gitlab-ce:latest gitlab/gitlab-ce:latest
$ docker rmi docker.1ms.run/gitlab/gitlab-ce:latest

2>安装

然后:
docker run --detach \
--hostname gitlab.example.com \
--publish 9080:80 --publish 9443:443 --publish 9022:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest


先进入到容器:
docker exec -it gitlab bash
修改配置:
root@gitlab:/# vi /etc/gitlab/gitlab.rb
找到 external_url 'http://gitlab.example.com'
改为 external_url 'http://gitlab.example.com:9080'  //注意如果使用https, external_url 'https://gitlab.example.com:9443'

然后执行:
root@gitlab:/# gitlab-ctl reconfigure

看到如下信息,代表配置完成
...
...
Running handlers:
[2025-02-06T16:14:56+00:00] INFO: Running report handlers
Running handlers complete
[2025-02-06T16:14:56+00:00] INFO: Report handlers complete
Infra Phase complete, 34/868 resources updated in 42 seconds

Deprecations:
* git_data_dirs has been deprecated since 17.8 and will be removed in 18.0. See https://docs.gitlab.com/omnibus/settings/configuration.html#migrating-from-git_data_dirs for migration instructions.

Update the configuration in your gitlab.rb file or GITLAB_OMNIBUS_CONFIG environment.

gitlab Reconfigured!
root@gitlab:/#
root@gitlab:/# exit

3>宿主机配置

宿主机上,添加hosts文件:
127.0.0.1 gitlab.example.com

访问:
http://gitlab.example.com:9080

首次登录,使用 root 账户,密码存储在:
docker exec -it gitlab cat /etc/gitlab/initial_root_password

$ docker exec -it gitlab 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: kICRKydbHX69mkbeqgeA7fPbWDPdaLHl/5GnPRLSKks=

然后就登进去了...

http://gitlab.example.com:9080/admin //可以查看管理面板

维护 GitLab

操作	命令
查看容器状态	docker ps -a
启动 GitLab	docker start gitlab
停止 GitLab	docker stop gitlab
重新启动 GitLab	docker restart gitlab
删除 GitLab 容器	docker rm -f gitlab

4>使用这个gitlab-ce

$ git clone git@gitlab.example.com:root/laravel-14.git
Cloning into 'laravel-14'...
ssh: connect to host gitlab.example.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


$ docker ps | grep gitlab
8a4f7a01b396   gitlab/gitlab-ce:latest     "/assets/wrapper"        23 hours ago   Up 40 minutes (healthy)   0.0.0.0:9022->22/tcp, :::9022->22/tcp, 0.0.0.0:9080->80/tcp, :::9080->80/tcp, 0.0.0.0:9443->443/tcp, :::9443->443/tcp   gitlab


# gitlab_rails['gitlab_shell_ssh_port'] = 22
打开默认注释,配置为:
gitlab_rails['gitlab_shell_ssh_port'] = 9022

root@gitlab:/# gitlab-ctl reconfigure
...
...
Running handlers:
[2025-02-07T15:30:13+00:00] INFO: Running report handlers
Running handlers complete
[2025-02-07T15:30:13+00:00] INFO: Report handlers complete
Infra Phase complete, 6/818 resources updated in 38 seconds

Deprecations:
* git_data_dirs has been deprecated since 17.8 and will be removed in 18.0. See https://docs.gitlab.com/omnibus/settings/configuration.html#migrating-from-git_data_dirs for migration instructions.

Update the configuration in your gitlab.rb file or GITLAB_OMNIBUS_CONFIG environment.

gitlab Reconfigured!

root@gitlab:/# gitlab-ctl restart
ok: run: alertmanager: (pid 3572) 1s
ok: run: gitaly: (pid 3590) 0s
ok: run: gitlab-exporter: (pid 3618) 0s
ok: run: gitlab-kas: (pid 3630) 0s
ok: run: gitlab-workhorse: (pid 3640) 0s
ok: run: logrotate: (pid 3665) 0s
ok: run: nginx: (pid 3672) 0s
ok: run: postgres-exporter: (pid 3696) 1s
ok: run: postgresql: (pid 3705) 0s
ok: run: prometheus: (pid 3716) 0s
ok: run: puma: (pid 3725) 0s
ok: run: redis: (pid 3738) 0s
ok: run: redis-exporter: (pid 3747) 0s
ok: run: registry: (pid 3754) 0s
ok: run: sidekiq: (pid 3781) 0s
ok: run: sshd: (pid 3791) 0s

退出gitlab容器

在宿主机 ~/.ssh/config 新增配置:
Host gitlab.example.com
HostName gitlab.example.com
User git
Port 9022
IdentityFile ~/.ssh/id_rsa

虽然之前已经添加了github的,仍然可以在后面继续添加

测试一下:
$ ssh -T git@gitlab.example.com
The authenticity of host '[gitlab.example.com]:9022 ([127.0.0.1]:9022)' can't be established.
ED25519 key fingerprint is SHA256:79UEk9sTgEkSKjTbJ5qdzc2iYRyYHMYr1z13GSngLIo.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[gitlab.example.com]:9022' (ED25519) to the list of known hosts.
Welcome to GitLab, @root!


然后就就可以clone代码了:
$ git clone git@gitlab.example.com:root/laravel-14.git
Cloning into 'laravel-14'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.


其实也可以直接这样,不用在~/.ssh/config下添加配置,适合临时执行的:
GIT_SSH_COMMAND="ssh -p 9022" git clone git@gitlab.example.com:root/laravel-14.git


对于已经存在的项目,想使用新的remote 连接,可以改为:
git remote set-url origin ssh://git@gitlab.example.com:9022/root/laravel-14.git

用户邮箱注册流程:

1>到登陆页面注册
guoshipengdss@gmail.com
rx7UJjznL@W57iU

2>注册完成后还不能登陆,需要管理员统一
http://gitlab.example.com:9080/admin 下的users目录下的Pending approval可以看到等待通过的用户

3>点击edit之后,选择Approval即可通过新注册的用户

为gitlab设置新的Group

1>管理员登陆
http://gitlab.example.com:9080/admin 下的Groups目录下可以选择创建新的group,比如 dev, 那么就会有
http://gitlab.example.com:9080/dev