GitLab部署

GitLab部署

环境

参考文档: GitLab官方部署文档 系统: CentOS7.9

需要安装: docker 需要安装: docker-compose

安装部署-docker

# 获取GitLab镜像
docker pull gitlab/gitlab-ce:latest

# 创建目录
mkdir config logs data

# 创建真正要跑的容器
docker run -dit \
--hostname gitlab \
--env GITLAB_OMNIBUS_CONFIG="external_url 'https://caowd.com:9900'" \
--publish 9900:443 \
--publish 9922:22 \
--name gitlab \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
--shm-size 256m \
gitlab/gitlab-ce:latest

# 启动较慢,约有13分钟

安装部署-docker-compose

docker-compose.yml文件:

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    restart: always
    hostname: gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://${hostname}:${https_port}'        
    ports:
      - '${https_port}:443'
      - '${http_port}:80'
      - '${ssh_port}:22'
    volumes:
      - '${GITLAB_HOME}/config:/etc/gitlab'
      - '${GITLAB_HOME}/logs:/var/log/gitlab'
      - '${GITLAB_HOME}/data:/var/opt/gitlab'
    shm_size: '256m'

.env配置文件:

gitlab_version=latest
GITLAB_HOME=/opt/shortcut/gitlab
hostname=caowd.com
http_port=9980
https_port=9900
ssh_port=9922
# 创建目录
mkdir config logs data

启动

# 启动GitLab
docker-compose up -d

配置GitLab

配置邮箱服务

修改gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1774104802@qq.com"
gitlab_rails['smtp_password'] = "wqhpavzppffljhbh"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_pool'] = false

gitlab_rails['gitlab_email_from'] = '1774104802@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'GitLab@caowd.com'

重新生成配置文件

# 如果GitLab修改了配置,执行下面的命令重新生成配置
gitlab-ctl reconfigure

# 进入rails控制台
gitlab-rails console

# 测试GitLab发邮件
Notify.test_email('caowd1990@163.com', 'GitLab Title', 'test GitLab').deliver_now

配置HTTPS访问

修改gitlab.rb

# 配置外部访问地址
external_url 'https://caowd.com:9900'
nginx['listen_port'] = 9900
# 开启HTTPS访问
nginx['listen_https'] = true

# 配置证书路径
nginx['ssl_certificate'] = "/etc/gitlab/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/privkey.pem"