x-pack elasticsearch

第一步:

elasticsearch-6.3.0modulesx-packx-pack-core目录下找到x-pack-core-6.3.0.jar,复制一份出来留个备份

第二步:新建两个java文件分别命名为LicenseVerifier.java和XPackBuild.java

LicenseVerifier.java

package org.elasticsearch.license;
 
import java.nio.*;
import org.elasticsearch.common.bytes.*;
import java.util.*;
import java.security.*;
import org.elasticsearch.common.xcontent.*;
import org.apache.lucene.util.*;
import org.elasticsearch.core.internal.io.*;
import java.io.*;
 
 
public class LicenseVerifier
{
    public static boolean verifyLicense(final License license, final byte[] encryptedPublicKeyData) {
       return true;
    }
    
    public static boolean verifyLicense(final License license) {
         return true;
    }
}

XPackBuild.java

package org.elasticsearch.xpack.core;
 
import org.elasticsearch.common.io.*;
import java.net.*;
import org.elasticsearch.common.*;
import java.nio.file.*;
import java.io.*;
import java.util.jar.*;
 
 
public class XPackBuild
{
    public static final XPackBuild CURRENT;
    private String shortHash;
    private String date;
    
    @SuppressForbidden(reason = "looks up path of xpack.jar directly")
    static Path getElasticsearchCodebase() {
        final URL url = XPackBuild.class.getProtectionDomain().getCodeSource().getLocation();
        try {
            return PathUtils.get(url.toURI());
        }
        catch (URISyntaxException bogus) {
            throw new RuntimeException(bogus);
        }
    }
    
    XPackBuild(final String shortHash, final String date) {
        this.shortHash = shortHash;
        this.date = date;
    }
    
    public String shortHash() {
        return this.shortHash;
    }
    
    public String date() {
        return this.date;
    }
    
    static {
        final Path path = getElasticsearchCodebase();
        String shortHash = null;
        String date = null;
        Label_0157: {
           
            shortHash = "Unknown";
            date = "Unknown";
        }
        CURRENT = new XPackBuild(shortHash, date);
    }
}

第三步:编译两个文件

mkdir -p org/elasticsearch/license/

mv LicenseVerifier.class org/elasticsearch/license/LicenseVerifier.class

javac -cp "/usr/local/ElasticSearch/elasticsearch-6.3.1/modules/x-pack/x-pack-core/x-pack-core-6.3.1.jar:/usr/local/ElasticSearch/elasticsearch-6.3.1/lib/lucene-core-7.3.1.jar:/usr/local/ElasticSearch/elasticsearch-6.3.1/lib/elasticsearch-6.3.1.jar:/usr/local/ElasticSearch/elasticsearch-6.3.1/lib/elasticsearch-core-6.3.1.jar"  /root/andychen/tmp/LicenseVerifier.java



mkdir -p org/elasticsearch/xpack/core/

mv LicenseVerifier.class org/elasticsearch/xpack/core/XPackBuild.class

javac -cp "/usr/local/ElasticSearch/elasticsearch-6.3.1/modules/x-pack/x-pack-core/x-pack-core-6.3.1.jar:/usr/local/ElasticSearch/elasticsearch-6.3.1/lib/lucene-core-7.3.1.jar:/usr/local/ElasticSearch/elasticsearch-6.3.1/lib/elasticsearch-6.3.1.jar:/usr/local/ElasticSearch/elasticsearch-6.3.1/lib/elasticsearch-core-6.3.1.jar" /root/andychen/tmp/XPackBuild.java

  

第四步:替换x-pack-core-6.3.0.jar里的class文件(压入)

mkdir -p org/elasticsearch/license/

mv LicenseVerifier.class org/elasticsearch/license/LicenseVerifier.class

jar uvf /usr/local/ElasticSearch/elasticsearch-6.3.1/modules/x-pack/x-pack-core/x-pack-core-6.3.1.jar org/elasticsearch/license/LicenseVerifier.class

mkdir -p org/elasticsearch/xpack/core/

mv LicenseVerifier.class org/elasticsearch/xpack/core/XPackBuild.class

jar uvf /usr/local/ElasticSearch/elasticsearch-6.3.1/modules/x-pack/x-pack-core/x-pack-core-6.3.1.jar org/elasticsearch/xpack/core/XPackBuild.class

第五步:

获取 license 证书

https://license.elastic.co/registration 填些用户名,邮箱(重要,获取下载链接),Country选择China,其他信息随意填写

②打开邮箱获取的地址,将下载后的文件改名为license.json

③修改文件中的内容,将两个属性改为

将 "type":"basic" 替换为 "type":"platinum"    # 基础版变更为铂金版

将 "expiry_date_in_millis":1561420799999替换为 "expiry_date_in_millis":3107746200000    # 1年变为50年

④使用curl替换 license(license.json指的是刚刚下载修改属性后的证书,要开启elasticsearch服务)

curl -H "Content-Type: application/json" -XPUT 'http://192.168.7.245:9200/_xpack/license?acknowledge=true' -d @license.json

⑤若失败,修改配置文件

xpack.security.enabled: false

破解成功后改回来

xpack.security.enabled: true

xpack.security.transport.ssl.enabled: true

⑥上传后查看证书时间

curl -XGET http://192.168.7.245:9200/_license

参考: https://blog.csdn.net/xiaoyu_BD/article/details/81698882

API 使用账号: https://www.elastic.co/guide/en/x-pack/current/http-clients.html 

原文地址:https://www.cnblogs.com/bootoo/p/9715522.html