Elasticsearch安装破解教程

本教程基于elasticsearch8.3.3版本,基于centos7,请确保系统环境干净

安装Elasticsearch 8.x

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
wget --no-dns-cache https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.3-x86_64.rpm
rpm --install elasticsearch-8.3.3-x86_64.rpm

安装结束后会提示让你重置密码,按照提示的来即可,如果不想要重置密码请看下文

安装openJDK17

es高版本的安装包内内置了jdk17,比如8.8.2,所以高版本的可以跳过这一步

  1. 从ORACLE官网下载jdk17
    https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html

    wget --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

    如果wget指令下不动,可以在自己电脑上下载完后传上去

    image-20220810201419871

  2. 安装jdk

    yum localinstall jdk-17_linux-x64_bin.rpm

    可能文件名有所不同,自己注意就好了

  3. 查看是否安装成功

    java -version

破解elasticsearch8

准备文件

由于Github中不区分小版本,因此需要选择前两个版本号相同的分支获取源代码

# 下载源码文件
branch=8.3 # 适用于8.3.x
curl -o LicenseVerifier.java -s https://raw.githubusercontent.com/elastic/elasticsearch/$branch/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseVerifier.java
curl -o XPackBuild.java -s https://raw.githubusercontent.com/elastic/elasticsearch/$branch/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackBuild.java

修改LicenseVerifier.java

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */
package org.elasticsearch.license;

import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefIterator;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.core.internal.io.Streams;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentType;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;

/**
 * Responsible for verifying signed licenses
 */
public class LicenseVerifier {

    /**
     * verifies the license content with the signature using the packaged
     * public key
     * @param license to verify
     * @return true if valid, false otherwise
     */
    public static boolean verifyLicense(final License license, PublicKey publicKey) {
        /*
        byte[] signedContent = null;
        byte[] publicKeyFingerprint = null;
        try {
            byte[] signatureBytes = Base64.getDecoder().decode(license.signature());
            ByteBuffer byteBuffer = ByteBuffer.wrap(signatureBytes);
            @SuppressWarnings("unused")
            int version = byteBuffer.getInt();
            int magicLen = byteBuffer.getInt();
            byte[] magic = new byte[magicLen];
            byteBuffer.get(magic);
            int hashLen = byteBuffer.getInt();
            publicKeyFingerprint = new byte[hashLen];
            byteBuffer.get(publicKeyFingerprint);
            int signedContentLen = byteBuffer.getInt();
            signedContent = new byte[signedContentLen];
            byteBuffer.get(signedContent);
            XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
            license.toXContent(contentBuilder, new ToXContent.MapParams(Collections.singletonMap(License.LICENSE_SPEC_VIEW_MODE, "true")));
            Signature rsa = Signature.getInstance("SHA512withRSA");
            rsa.initVerify(publicKey);
            BytesRefIterator iterator = BytesReference.bytes(contentBuilder).iterator();
            BytesRef ref;
            while ((ref = iterator.next()) != null) {
                rsa.update(ref.bytes, ref.offset, ref.length);
            }
            return rsa.verify(signedContent);
        } catch (IOException | NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
            throw new IllegalStateException(e);
        } finally {
            if (signedContent != null) {
                Arrays.fill(signedContent, (byte) 0);
            }
        }
        */
        return true;
    }

    private static final PublicKey PUBLIC_KEY;

    static {
        try (InputStream is = LicenseVerifier.class.getResourceAsStream("/public.key")) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            Streams.copy(is, out);
            PUBLIC_KEY = CryptUtils.readPublicKey(out.toByteArray());
        } catch (IOException e) {
            throw new AssertionError("key file is part of the source and must deserialize correctly", e);
        }
    }

    public static boolean verifyLicense(final License license) {
        //return verifyLicense(license, PUBLIC_KEY);
        return true;
    }
}

修改XPackBuild.java

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */
package org.elasticsearch.xpack.core;

import org.elasticsearch.core.PathUtils;
import org.elasticsearch.core.SuppressForbidden;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;

/**
 * Information about the built version of x-pack that is running.
 */
public class XPackBuild {

    public static final XPackBuild CURRENT;

    static {
        final String shortHash;
        final String date;

        Path path = getElasticsearchCodebase();
        /*
        if (path.toString().endsWith(".jar")) {
            try (JarInputStream jar = new JarInputStream(Files.newInputStream(path))) {
                Manifest manifest = jar.getManifest();
                shortHash = manifest.getMainAttributes().getValue("Change");
                date = manifest.getMainAttributes().getValue("Build-Date");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
            // not running from a jar (unit tests, IDE)
            shortHash = "Unknown";
            date = "Unknown";
        }
        */
        shortHash = "Unknown";
        date = "Unknown";
        CURRENT = new XPackBuild(shortHash, date);
    }

    /**
     * Returns path to xpack codebase path
     */
    @SuppressForbidden(reason = "looks up path of xpack.jar directly")
    static Path getElasticsearchCodebase() {
        URL url = XPackBuild.class.getProtectionDomain().getCodeSource().getLocation();
        try {
            return PathUtils.get(url.toURI());
        } catch (URISyntaxException bogus) {
            throw new RuntimeException(bogus);
        }
    }

    private String shortHash;
    private String date;

    XPackBuild(String shortHash, String date) {
        this.shortHash = shortHash;
        this.date = date;
    }

    public String shortHash() {
        return shortHash;
    }

    public String date() {
        return date;
    }
}

重新编译class文件

javac -cp "/usr/share/elasticsearch/lib/*:/usr/share/elasticsearch/modules/x-pack-core/*" LicenseVerifier.java
javac -cp "/usr/share/elasticsearch/lib/*:/usr/share/elasticsearch/modules/x-pack-core/*" XPackBuild.java

替换原始x-pack-core文件

version=8.3.3
cp /usr/share/elasticsearch/modules/x-pack-core/x-pack-core-$version.jar x-pack-core-$version.jar
unzip x-pack-core-$version.jar -d ./x-pack-core-$version
cp LicenseVerifier.class ./x-pack-core-$version/org/elasticsearch/license/
cp XPackBuild.class ./x-pack-core-$version/org/elasticsearch/xpack/core/
jar -cvf x-pack-core-$version.crack.jar -C x-pack-core-$version/ .
rm -rf x-pack-core-$version

完成破解,替换原始x-pack-core

cp x-pack-core-$version.crack.jar /usr/share/elasticsearch/modules/x-pack-core/x-pack-core-$version.jar

第一次启动需要授予权限

chown -R elasticsearch:elasticsearch /etc/elasticsearch/
service elasticsearch restart

启动elasticsearch

你会发现rpm安装的elasticsearch文件夹下(/usr/share/elasticsearch)并没有config文件夹,这是因为系统把配置文件塞到/etc下面了

cd /etc/elasticsearch/

这样就可以看见配置文件了

修改x-pack参数

vim elasticsearch.yml

image-20220810210609388

把这里的true改为false即可

如果不改这个参数的话需要配置密码后才能访问,否则会出现下面的错误

image-20220810210708816

修改访问范围

同一个配置文件,默认为0.0.0.0,即全部允许,如果需要修改访问范围可以在这里改,当然还是推荐直接在系统防火墙里配置

image-20220810211046907

放行系统防火墙

firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

修改JVM参数(非必要)

申请白金许可证

申请授权

https://register.elastic.co/marvel_register

到上面这个网址申请授权,填写邮箱之后即可收到信息

image-20220810203454806

点击邮件中的网址获取授权json文件

image-20220810203553104

然后就能得到一个json文件,需要修改其中的许可证类型过期时间

image-20220810203859938

  • 修改typeplatinum
  • 修改expiry_date_in_millis2524579200999(过期时间为2050年)

导入许可证

将修改好的license.json文件上传到当前命令行所在目录,执行:

 curl -XPUT -u elastic 'http://127.0.0.1:9200/_license' -H "Content-Type: application/json" -d @license.json
 # 如果出现下面输入密码的提示,直接按回车就行了
 Enter host password for user 'elastic':
{"acknowledged":true,"license_status":"valid"}

验证许可证

curl http://127.0.0.1:9200/_license

返回有"type" : "platinum"就为成功

下载图形化管理(可选)

这个玩意,可以直接安装在自己电脑上,要用的时候开起来就行

安装nodejs

curl --silent --location https://rpm.nodesource.com/setup_lts.x | bash -
yum install -y nodejs

修改npm源

npm config set registry https://registry.npm.taobao.org

下载head插件

cd /usr/local/
#clone不了的直接访问链接下载zip然后丢到路径下即可
git clone https://github.com/mobz/elasticsearch-head.git

安装依赖

cd elasticsearch-head/
#安装依赖卡住报错的建议挂个梯子
npm install

安装完后可能有些奇奇怪怪的提示,无视就好了

image-20220810215739204

启动

npm run start

image-20220810215953622

默认端口为9100端口

或者可以尝试下这个项目https://github.com/1340691923/ElasticView

参考资料:

https://blog.csdn.net/qq_36731677/article/details/124965226

https://www.cnblogs.com/52py/p/12745893.html

https://www.jianshu.com/p/bba5d12389ff

评论区
头像
文章目录