在当今数字化时代,软件开发与团队协作已经成为现代企业不可或缺的一部分。而在这个过程中,版本控制、协作和持续集成等工具的运用变得至关重要。GitLab作为一个领先的、完整的DevOps平台,为团队提供了一个集成的解决方案,使得软件开发和交付变得更加高效、可靠。本文将介绍如何通过安装Docker和GitLab EE来搭建一个功能完善的代码托管平台,然后通过Ruby 获得企业授权License。
Ruby生成的 GitLabBV.gitlab-license license_key.pub 文件可以直接使用本站所提供的,可以直接省略掉通过Ruby创建证书License的步骤,直接替换即可,下载地址请到我的博客
直达地址:https://www.itwk.cc/post/1144.html
安装 Docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum -y install docker-ce
systemctl enable --now docker
配置 Docker 镜像加速
{
"registry-mirrors": ["https://vwlrpbcp.mirror.aliyuncs.com"]
}
安装 GitLab EE
docker run -itd \
-p 80:80 \
-p 443:443 \
-p 2222:22 \
-v /data/gitlab/log:/var/log/gitlab \
-v /data/gitlab/opt:/var/opt/gitlab \
-v /data/gitlab/etc:/etc/gitlab \
--restart always \
--privileged=true \
--name gitlab \
gitlab/gitlab-ee
确认 GitLab EE 已经正常运行
docker ps -a
运行 Ruby
docker run -it --rm ruby /bin/bash
安装许可证工具
创建license.rb文件
cat >license.rb<<'EOF'
require "openssl"
require "gitlab/license"
key_pair = OpenSSL::PKey::RSA.generate(2048)
File.open("license_key", "w") { |f| f.write(key_pair.to_pem) }
public_key = key_pair.public_key
File.open("license_key.pub", "w") { |f| f.write(public_key.to_pem) }
private_key = OpenSSL::PKey::RSA.new File.read("license_key")
Gitlab::License.encryption_key = private_key
license = Gitlab::License.new
license.licensee = {
"Name" => "gitlab",
"Company" => "gitlab",
"Email" => "admin@gitlab.com",
}
license.starts_at = Date.new(2024, 1, 1)
license.expires_at = Date.new(2099, 1, 1)
license.notify_admins_at = Date.new(2049, 12, 1)
license.notify_users_at = Date.new(2049, 12, 1)
license.block_changes_at = Date.new(2050, 1, 1)
license.restrictions = {
active_user_count: 10000,
}
puts "License:"
puts license
data = license.export
puts "Exported license:"
puts data
File.open("GitLabBV.gitlab-license", "w") { |f| f.write(data) }
public_key = OpenSSL::PKey::RSA.new File.read("license_key.pub")
Gitlab::License.encryption_key = public_key
data = File.read("GitLabBV.gitlab-license")
$license = Gitlab::License.import(data)
puts "Imported license:"
puts $license
unless $license
raise "The license is invalid."
end
if $license.restricted?(:active_user_count)
active_user_count = 10000
if active_user_count > $license.restrictions[:active_user_count]
raise "The active user count exceeds the allowed amount!"
end
end
if $license.notify_admins?
puts "The license is due to expire on #{$license.expires_at}."
end
if $license.notify_users?
puts "The license is due to expire on #{$license.expires_at}."
end
module Gitlab
class GitAccess
def check(cmd, changes = nil)
if $license.block_changes?
return build_status_object(false, "License expired")
end
end
end
end
puts "This instance of GitLab Enterprise Edition is licensed to:"
$license.licensee.each do |key, value|
puts "#{key}: #{value}"
end
if $license.expired?
puts "The license expired on #{$license.expires_at}"
elsif $license.will_expire?
puts "The license will expire on #{$license.expires_at}"
else
puts "The license will never expire."
end
EOF
生成证书
root@8f56c7c5621c:/# ruby license.rb
License:
#<Gitlab::License:0x00007fad2d4501c8>
Exported license:
eyJkYXRhIjoidnZoUTYwZCtHWFVpWmVTWE5ibytpR2dwV04yUG8vYTlIeXd4
MWJzNUxLZzhiWUs2SjlPcjROWmZ3QXRTXG5mWm1ENHA5NXo1QkJsazZGT2Zq
TTVNWDd1TnVFeHFIWVpVeXRNbkhmQzlZWmdScEJTQU9vK0NJbHdQVXhcbnQ4
cVdmQ3dBbUVDaitYOWFhbHh2bkp6SkNSK0hJTWdIL2N5SDVCbXUvRTVFUUF2
bXVJa3hlNzNlTy9MMVxuYVRNVnFIKzc4WjRidjljWGJrbmt4ZWE5S1Y0amI1
amtrRE9GbDhhZ09aWTNJVXczWXVMeDUyMW9kMS8wXG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BseGp4
azR5VHNpZTNPWGl3a2JwcStZN1xuTnU2YkZsZWJua1htYUNFc0VuZ0Q4S3c4
dkdhcHFzTjZYNmZ0S2dCa0FnPT1cbiIsIml2IjoiYUxiazVWa21tRjFad0J1
eWd6eEQwQT09XG4ifQ==
Imported license:
#<Gitlab::License:0x00007fad2d3dd6f0>
This instance of GitLab Enterprise Edition is licensed to:
Name: gitlab
Company: gitlab
Email: admin@gitlab.com
The license will expire on 2099-01-01
然后会在当前目录下生成 GitLabBV.gitlab-license license_key license_key.pub三个文件。
将生成的 license_key.pub 文件复制到到 gitlab 容器中的/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f56c7c5621c ruby "/bin/bash" 10 minutes ago Up 10 minutes busy_bell
2042068f1d19 gitlab/gitlab-ee "/assets/wrapper" 11 minutes ago Up 11 minutes (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:2222->22/tcp, :::2222->22/tcp gitlab
[root@gitlab ~]#
[root@gitlab ~]# docker cp 8f56c7c5621c:/license_key.pub .
Successfully copied 2.05kB to /root/.
[root@gitlab ~]# ll
total 8
-rw-------. 1 root root 1218 Feb 28 17:32 anaconda-ks.cfg
-rw-r--r-- 1 root root 451 Mar 4 00:14 license_key.pub
[root@gitlab ~]#
[root@gitlab ~]# docker cp license_key.pub 2042068f1d19:/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
Successfully copied 2.05kB to 2042068f1d19:/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
获取 GitLab 初始密码并订阅许可证
默认用户名 为 root
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
Password: M4PTVPTAGib9V2e3W/7HZXN/m7ia6T1M1Mfbh8DOp7s=
然后打开打开http://gitlab/admin/application_settings/general
如果上传 license 时提示该 license 不可用,可以重启一遍 gitlab 容器,或者替换完成license_encryption_key.pub 先重启 gitlab 容器再去 web 添加 license 也可以。