GitLab 安装详解

安装docker-compose

下载

curl -L https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64 > /usr/local/bin/docker-compose

授权

sudo chmod +x /usr/local/bin/docker-compose

安装 GitLab

编写docker-compose.yaml文件

services:
  gitlab-ce:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/gitlab/gitlab-ce:17.5.1-ce.0
    restart: always
    hostname: localhost
    container_name: gitlab-ce
    environment:
      TZ: 'Asia/Shanghai'
      GITLAB_OMNIBUS_CONFIG: |
	    # 对外访问gitlab地址,可以使用本机IP
        external_url 'http://10.0.2.15:8085'
		gitlab_rails['gitlab_shell_ssh_port'] = 8122
    ports:
      - "8085:8085" # 注意宿主机和容器内部的端口要一致,否则external_url无法访问
      - "8443:443"
      - "8122:22"
    volumes:
      - /root/gitlab/gitlabce/config:/etc/gitlab
      - /root/gitlab/gitlabce/logs:/var/log/gitlab
      - /root/gitlab/gitlabce/data:/var/opt/gitlab
    networks:
      - gitlab
  gitlab-runner:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/gitlab/gitlab-runner:v17.2.1
    container_name: gitlab-runner
    restart: always
    depends_on:
      - gitlab-ce
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /root/gitlab/gitlabce/gitlab-runner:/etc/gitlab-runner
    networks:
      - gitlab
networks:
  gitlab:
    name: gitlab-network

8080端口:将容器内8085端口映射至宿主机8085端口,这是访问gitlab管理页面的端口
8122端口:将容器内22端口映射至宿主机8122端口,这是访问ssh的端口,拉代码时使用的端口
-v 本机目录:容器目录:把Docker里面的目录映射到宿主机上

启动

前台启动

docker-compose up

后台启动

docker-compose up –d

关闭并删除容器

docker-compose down

访问 GitLab

http://10.0.2.15:8085/

首次登录 GitLab 需要一个临时密码,该密码在安装过程中自动生成。使用以下命令获取密码

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

首次启动门户网站需要等待几分钟时间。要登录门户,必须在用户名一栏输入root用户,并在密码一栏输入之前获得的临时密码。

配置 GitLab

关闭注册功能

点击页面头部的Deactivate按钮,进入http://10.0.2.15:8085/admin/application_settings/general#js-signup-settings 设置页面,取消Sign-up enabled选中。

修改root用户的用户名和密码

访问http://10.0.2.15:8085/admin/users,编辑root用户的用户名和密码。另外,访问这个http://10.0.2.15:8085/-/profile/account页面也可以进行修改。

GitLab Runner配置

要在 GitLab 中使用 GitLab 运行程序,需要对其进行配置。进入http://10.0.2.15:8085/admin/runners界面,点击New instance runner创建一个GitLab Runner实例。主要在Tags输入一个tag,勾选Run untagged jobs ;然后点击Create runner即可。

然后按照提示操作,因为是docker安装,需要修改一下执行的命令,执行命令如下:

docker exec -it gitlab-runner gitlab-runner register --url http://10.0.2.15:8085 --token glrt-t1_Av4ZXXvokZR7wzscBTZK
Runtime platform                                    arch=amd64 os=linux pid=55 revision=9882d9c7 version=17.2.1
Running in system-mode.                            
                                                   
Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://10.0.2.15:8085]: http://10.0.2.15:8085 #输入GitLab地址
Verifying runner... is valid                        runner=t1_Av4ZXX
Enter a name for the runner. This is stored only in the local config.toml file:
[bd515bc5cf86]: main-runner #给GitLab Runner起一个名字
Enter an executor: custom, parallels, kubernetes, instance, docker+machine, docker-autoscaler, shell, ssh, virtualbox, docker, docker-windows:
docker # 输入docker
Enter the default Docker image (for example, ruby:2.7):
alpine:latest #默认docker镜像,输入alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
 
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml" 

注册成功可以在Runner控制台查看到注册的GitLab Runner。

参考:

https://www.cnblogs.com/banger/p/18305756
https://www.zhihu.com/question/586746559/answer/6760461693
https://blog.csdn.net/tianxingzhe37/article/details/138632994
posted @ 2024-11-02 21:17  BUG弄潮儿  阅读(4)  评论(0编辑  收藏  举报