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://域名 的方式。
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
通过浏览器访问:
gitlab 默认用户名:root
密码:`/data/gitlab/config/initial_root_password` (该文件24小时删除)
问题总汇
1. 忘记root密码怎么办?
首先,查看 root 用户ID
查询接口:http://gitlab的url/api/v4/users?username=用户名
获取到 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
, 使用修改后的密码登录即可。
本文作者:hukey
本文链接:https://www.cnblogs.com/hukey/p/16799615.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
2019-10-17 硬盘分区及Linux文件系统