首先我们需要安装Gitlab EE,可以使用Docker、二进制、K8s的方式安装,实际上我们只需要替换Gitlab的一个文件即可
我这里使用Docker进行演示
安装Gitlab EE
docker run -itd \
-p 18080:80 \
-p 2222:22 \
-v /opt/soft/docker/gitlab/etc:/etc/gitlab \
-v /opt/soft/docker/gitlab/log:/var/log/gitlab \
-v /opt/soft/docker/gitlab/opt:/var/opt/gitlab \
--restart always \
--privileged=true \
--name gitlab \
gitlab/gitlab-ee
查看Gitlab状态
root@abcdocker:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0d382f52075e gitlab/gitlab-ee:latest "/assets/wrapper" 38 minutes ago Up 37 minutes (healthy) 0.0.0.0:2222->22/tcp, :::2222->22/tcp, 0.0.0.0:18080->80/tcp, :::18080->80/tcp, 0.0.0.0:1443->443/tcp, :::1443->443/tcp gitlab-gitlab-ee-1
运行ruby镜像
root@abcdocker:~# docker run -it --rm ruby /bin/bash
安装许可证工具
root@d359bcd4ca50:/# gem install gitlab-license
Fetching gitlab-license-2.3.0.gem
Successfully installed gitlab-license-2.3.0
1 gem installed
A new release of RubyGems is available: 3.4.10 → 3.4.22!
Run `gem update --system 3.4.22` to update your installation.
创建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" => "none",
"Company" => "none",
"Email" => "example@test.com",
}
license.starts_at = Date.new(2021, 1, 1) # 开始时间
license.expires_at = Date.new(2050, 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@d359bcd4ca50:/# ruby license.rb
#以下内容为输出日志
License:
#<Gitlab::License:0x00007fecc60dbd70>
Exported license:
eyJkYXRhIjoiYWo5TVVPYnBNd21FZUJuVEVXVzgrVlZ1MkNIWUcyMThibm1l
dk9EZGRPY0RMZVp4UXAxUWFzU1BTN0NuXG5hL2xENmdxUEk1YWJ6anpoVUI3
NWhIRC9RUVFid2FVTkh0dUtjejhBVTdyTWhQd0N2QVQwR0IrU0tVRzZcblJl
VjB4dXpBdGxzVUVYaWIyUXlHSTdYTTNwWnd0TWpOVDdXZXV0MTdmUlhxb0dP
UmJOejNNNStqdndYNFxuOUYrOFYyOWdDbVJCbmFrTzAwTTRGWEFtMEZXMEZQ
TE0yV1pRWnJpWnRuVEhqVFB0NDNMb2FjazhUYnppXG41UnZHUGpVUW9sa1Fw
RW40YitLS3lYNjJnVHROSXRPa012SmRpQnhJenk0YlIvUVFxdllkTWl1VUdo
dWJcbnpjUW55R1VPTUU4RTRCbE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
This instance of GitLab Enterprise Edition is licensed to:
Name: none
Company: none
Email: example@test.com
The license will expire on 2050-01-01
生成 GitLabBV.gitlab-license
license_key
license_key.pub
这三个文件。
-
将license_key.pub文件拷贝到Gitlab里`/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub中
-
GitLabBV.gitlab-license 内容前台输入到license注册码中
打开http://gitlab——IP:18080/admin/application_settings/general
激活完成