docker运行gitlab并配置https


主机信息

一台能够访问外网的主机,配置如下:

系统:CentOS Linux release 7.9.2009 (Core)
内核:3.10.0-1160.el7.x86_64
gitlab版本:15.4

安装过程


1. 安装docker-ce

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl --system

yum install -y docker-ce
mkdir -p /etc/docker/
cat << 'EOF' > /etc/docker/daemon.json
{
  "log-driver": "json-file",
  "data-root": "/data/docker",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  },
  "exec-opts": ["native.cgroupdriver=systemd"],
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ],
  "insecure-registries": [
    "192.168.1.200:80"
  ],
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com"
  ]
}
EOF

systemctl enable docker; systemctl start docker
docker info 

2. 启动 gitlab-ce

mkdir /data/gitlab; cd /data/gitlab
cat << 'EOF' > run.sh
#!/bin/bash
# Author:hukey
docker run -d  \
-p 443:443 \
-p 80:80 \
-p 222:22 \
--name gitlab \
--restart always \
-v /data/gitlab/config:/etc/gitlab \
-v /data/gitlab/logs:/var/log/gitlab \
-v /data/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce
EOF

sh run.sh

到目前为止,即可通过主机IP:80端口访问gitlab ,但是只能通过ip访问,无法通过 https://域名 的方式。

image-20221017152616226


3. 生成SSL证书

如果是云平台提供域名及证书就直接使用免费的,例如阿里云。

域名解析里添加一条A记录,然后在SSL证书中免费创建SSL证书。

这里通过自行签发证书的方式来实现https

yum install openssl openssl-devel -y
mkdir /data/gitlab/config/ssl ; cd /data/gitlab/config/ssl

### 生成证书
openssl req -new -newkey rsa:2048 -sha256 -nodes -out gitlab.super.com.csr -keyout gitlab.super.com.key -subj "/C=CN/ST=Beijing/L=Beijing/O=Super Inc./OU=Web Security/CN=gitlab.super.com"

openssl x509 -req -days 365 -in gitlab.super.com.csr -signkey gitlab.super.com.key -out gitlab.super.com.crt

4. 为Gitlab配置https

修改gitlab 配置信息:

vim /data/gitlab/config/gitlab.rb
### 添加如下内容 ###
external_url 'https://gitlab.super.com'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.super.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.super.com.key"

nginx['proxy_set_headers'] = {
  "X-Forwarded-Proto" => "https",
  "X-Forwarded-Ssl" => "on"
}

修改完成后,一定要记得重启容器

docker restart gitlab

注意:重启容器后,稍微多等待一段时间,gitlab容器初始化时间较长,如果没有初始化完成访问则会出现 500 或者 502

当出现如下提示则表示 gitlab 初始化完成:

docker logs -f gitlab
...
Successfully created self monitoring project.
...

5. 浏览器访问

如果是win10电脑作为客户端,修改hosts 文件:"C:\Windows\System32\drivers\etc\hosts"

192.168.199.101	gitlab.super.com

通过浏览器访问:

image-20221017160154431

gitlab 默认用户名:root
密码:`/data/gitlab/config/initial_root_password` (该文件24小时删除)

问题总汇


1. 忘记root密码怎么办?

首先,查看 root 用户ID

查询接口:http://gitlab的url/api/v4/users?username=用户名

image-20221017160547684

获取到 root用户ID为 1


再次,通过ID重置 root 密码

进入到容器内部

docker exec -it gitlab bash
# gitlab-rails console -e production  ### 这里会稍微等上一会,可能2分钟左右
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.4.2 (ef309cf1466) FOSS
 GitLab Shell: 14.10.0
 PostgreSQL:   13.6
------------------------------------------------------------[ booted in 65.76s ]
Loading production environment (Rails 6.1.6.1)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'gitlab@super.com'
=> "gitlab@super.com"
irb(main):003:0> user.password_confirmation = 'gitlab@super.com'
=> "gitlab@super.com"
irb(main):004:0> user.save!
=> true
irb(main):005:0> quit

密码修改为:gitlab@super.com , 使用修改后的密码登录即可。



--- EOF ---

本文作者:hukey

本文链接:https://www.cnblogs.com/hukey/p/16799615.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   hukey  阅读(2053)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
历史上的今天:
2019-10-17 硬盘分区及Linux文件系统
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 彩虹 Jay
彩虹 - Jay
00:00 / 00:00
An audio error has occurred.

彩虹 + 轨迹 (Live) - 周杰伦 (Jay Chou)

彩虹

词:周杰伦

曲:周杰伦

哪里有彩虹告诉我

哪里有彩虹告诉我

能不能把我的愿望还给我

能不能把我的愿望还给我

为什么天这么安静

为什么天这么安静

所有的云都跑到我这里

有没有口罩一个给我

有没有口罩一个给我

释怀说了太多就成真不了

释怀说了太多就成真不了

也许时间是一种解药

也许时间是一种解药

也是我现在正服下的毒药

也是我现在正服下的毒药

看不见你的笑 我怎么睡得着

看不见你的笑 我怎么睡得着

你的声音这么近我却抱不到

你的声音这么近我却抱不到

没有地球太阳还是会绕

没有地球太阳还是会绕

没有理由我也能自己走

没有理由我也能自己走

你要离开 我知道很简单

你要离开 我知道很简单

你说依赖 是我们的阻碍

你说依赖 是我们的阻碍

就算放开 但能不能别没收我的爱

就算放开 但能不能别没收我的爱

当作我最后才明白

当作我最后才明白

看不见你的笑 要我怎么睡得着

看不见你的笑 要我怎么睡得着

你的声音这么近我却抱不到

没有地球太阳还是会绕 会绕

没有理由我也能自己走掉

释怀说了太多就成真不了

也许时间是一种解药 解药

也是我现在正服下的毒药

轨迹

词:黄俊郎

曲:周杰伦

我会发着呆然后忘记你

接着紧紧闭上眼

想着哪一天 会有人代替

想着哪一天 会有人代替

让我不再想念你

我会发着呆 然后微微笑

我会发着呆 然后微微笑

接着紧紧闭上眼

又想了一遍 你温柔的脸

又想了一遍 你温柔的脸

在我忘记之前