找回密码
 立即注册
搜索
热搜: Java Linux Docker
查看: 25|回复: 0

GitlabEE 许可证

[复制链接]

24

主题

1

回帖

4万

积分

管理员

积分
40166
发表于 2025-4-15 09:51:19 | 显示全部楼层 |阅读模式

操作系统: Ubuntu 22.04

环境准备

sudo apt install ruby
sudo gem install gitlab-license

Fetching gitlab-license-2.4.0.gem
Successfully installed gitlab-license-2.4.0
Parsing documentation for gitlab-license-2.4.0
Installing ri documentation for gitlab-license-2.4.0
Done installing documentation for gitlab-license after 0 seconds
1 gem installed

许可证生成步骤

  1. 创建新脚本license.rb,修改时间
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" => "[email protected]",
}
license.starts_at = Date.new(2024, 5, 24) # 开始时间
license.expires_at = Date.new(2099, 12, 31) # 结束时间
license.notify_admins_at = Date.new(2099, 12, 1)
license.notify_users_at = Date.new(2099, 12, 1)
license.block_changes_at = Date.new(2099, 12, 31)
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
  1. 生成证书
ruby license.rb
License:
#<Gitlab::License:0x000055cd4d95eb18>
Exported license:
eyJkYXRhIjoiZGI5Y3ovZkh4VTRvSmZyQncwR2RNZU5Ma0lRRDVVK2c0ZUVh
UHJFc053R0RONE04S1lWS09Id2VZdFJvXG5pZUpzb3JXaHl5Tm9lVEFsS2Nr
Z1F4TjlMTlduMFgvNWw1VWdEK1BWOWlidE9zRGRYNUQ0NGRCWHE1UDhcbmZY
NVRhWm9NdUdzdDllYjdnY3QxT1dzbysyWlRpKy9SbTFLSUFRMXQ0ck1LWTlI
OEpMdmNqbjdSMGtYMlxuMXFYVWp2TmR5T0luNDBreHNONlNpbHNUUGg4aGlU
ZGxNTVhUdytTUThxMFF6eDgxUktEN0JZanpJK0hhXG4ybGozYzl2MW52UGRu
dUJjOVQzR0tEa2Y4RENyVnBlMlpLcUZpSThGbG9ibHluWkxjN3lDSFUvdG9o
d0dcbmRuTmxoN2MrSUdQZVZmUTYzYm5PVGJuWG9Dd1dZbkFzY1Mvd1Z1aHp3
SVpXUWxSVzhIYVJCbzNPZm9ielxuTFBHOHZ6ZVh2M0Q2eG8wUy9QblhmN3Jw
MDVCeGk1VVhXRlkrSGlnVXE2WUlzVXhlek9DVVRQV2UrR0NOXG5XMXR0Zm1V
ZG1RUk0vU0hSbzBiZUl6VWl6ZHF6KzNiTGpnbE5qcTVSR1FhMG5ScHV5Vk1H
Qk0rd1gySjhcbjdSMVZJTkhSWno1Q2FDVFp2NmNzcFhLZ1hMMDhWcWt1MmU1
SnlpNHlUeXNiZ1N4YXg4aFhRWVlMOUZuUVxuYlRiaTlKanZMUHFDMGp1TC9G
bEtaTUZrVVN1WDEweDlMM3hWYUlLdFA0SXVmdXlhc01QcmdIaitRaE5nXG42
ZEF0aktDdE9GOExxSGJrN1JXd1MveXlWaThzOXB0NUtyZVJEY1JVdm11UEJF
cXd5Um5hYXNMaVcyWDRcblVWTml1YzhnNC9wS2NzVUpNUStETkFDWHhxcUcx
Y1dFV3ZsT2RZdlEvcjhyXG4iLCJrZXkiOiJsbk8yL0tEME1KOWRaZG02YU84
TXZiN0ZoQkNKbHh5QnJWdUNEUVV4aDBMUW1XVVRocGhueExTVU96RzBcbmFI
N2VTRVJ6MnJ1OTFWSGZTVFljeityNG5nUmFZUEhWcURscXNJek9tZytoelpo
RmVGUVlFaHJ4VGo2bVxuV1hDZjZreHRRY1duUUQwVEZuOXY1NW8zUkYxZU1t
RFAyVjZVTHdjWGZESnJXdmlXMXQ2ZDlabGpGVmZoXG5UOHIrV0dvNGR5cEYr
ajBZM0tSdjBBSElKT2I3WTJEOEk0bnoxTzcxeTk4WnJObGVacDdpRzRjMTY3
b1Rcbis5WVp3TDBxL1duWEU5SVVxcGZoczhxRFY5dG5mS2puYjdIWXRCOUxH
NzViZDV3d3N1S0tmVjEvWDB5L1xuMk93UWFFZVQwNUZvZUpUT1dNZTlzbWt4
YXRad1lyMVhSaXM4N1YvSHRBPT1cbiIsIml2IjoicVhqbHA3VjIwU2ppNkxU
Z092S2tQZz09XG4ifQ==
Imported license:
#<Gitlab::License:0x000055cd4d9566c0>
This instance of GitLab Enterprise Edition is licensed to:
Name: none
Company: none
Email: [email][email protected][/email]
The license will expire on 2099-12-31

同时生成三个文件

GitLabBV.gitlab-license
license_key
license_key.pub

许可证激活

  1. 使用license_key.pub替换/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
sudo cp license_key.pub /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
  1. 修改/opt/gitlab/embedded/service/gitlab-rails/ee/app/models/license.rb,修改plan函数
def plan
    restricted_attr(:plan).presence || STARTER_PLAN
end

为:

def plan
    restricted_attr(:plan).presence || ULTIMATE_PLAN
end
  1. 重启gitlab以使用新密钥

打开http://127.0.0.1/admin/application_settings/general,找到Add License

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|saotolls Inc.

GMT+8, 2025-11-8 13:38 , Processed in 0.212980 second(s), 30 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表