1惧浴、添加maven依賴
<repositories>
? ? ? ??elastic.co
? ? ? ? <url>https://artifacts.elastic.co/maven</url>
? ? </repository>
</repositories>
<dependency>
????<groupId>org.elasticsearch.plugin</groupId>
????<artifactId>x-pack-sql-jdbc</artifactId>
????<version>7.6.2</version>
</dependency>
2逞频、使用測試代碼連接
public static void main(String[] args) {
????try {
????????Connection connection = DriverManager.getConnection("jdbc:es://http://172.16.62.121:19200");// 將ES-IP換位ES服務(wù)器的IP
????????Statement statement = connection.createStatement();
????????ResultSet results = statement.executeQuery("select * from vmware_vm_day_perf LIMIT 5");
????????System.out.println(results);
????????while (results.next()) {
????????????System.out.println(results.getString("vmName"));
????????}
????} catch (Exception e) {
????????e.printStackTrace();
????}
}
如果未關(guān)閉授權(quán)驗(yàn)證瘤睹,需要添加用戶名和密碼參數(shù)
關(guān)閉用戶名密碼驗(yàn)證的方式:
在ES的配置文件在elasticsearch.yml新增中
xpack.security.enabled: false
3啤咽、破解x-pack-core
白金版支持JDBC連接宪祥,基礎(chǔ)版是不支持的墓卦,你可以申請(qǐng)一個(gè)白金版十酣,也可以像我一樣破解x-pack-core
接下來操作是以7.6.2版本為例灾杰,其他版本基本一樣
x-pack-core.7.6.2.jar位置:$ES_HOME/modules/x-pack-core/x-pack-core.7.6.2.jar
$ES_HOME為Elasticsearch的安裝目錄
隨便找一個(gè)目錄創(chuàng)建兩個(gè)java文件 分別是:
LicenseVerifier.java
package org.elasticsearch.license;
/**
*??* 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, byte[] publicKeyData) {
????????return true;
????}
????public static boolean verifyLicense(final License license) {
????????return true;
????}
}
XPackBuild.java
package org.elasticsearch.xpack.core;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
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;
public class XPackBuild {
????public static final XPackBuild CURRENT;
????static {
????????CURRENT = new XPackBuild("Unknown", "Unknown");
????}
????/**
*??????* 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;
????}
}
重新編譯
javac -cp "/data/work/elasticsearch-7.6.2_master/lib/elasticsearch-7.6.2.jar:/data/work/elasticsearch-7.6.2_master/lib/lucene-core-8.4.0.jar:/data/work/elasticsearch-7.6.2_master/modules/x-pack-core/x-pack-core-7.6.2.jar" LicenseVerifier.java
javac -cp "/data/work/elasticsearch-7.6.2_master/lib/elasticsearch-7.6.2.jar:/data/work/elasticsearch-7.6.2_master/lib/lucene-core-8.4.0.jar:/data/work/elasticsearch-7.6.2_master/modules/x-pack-core/x-pack-core-7.6.2.jar:/data/work/elasticsearch-7.6.2_master/lib/elasticsearch-core-7.6.2.jar" XPackBuild.java
生成對(duì)應(yīng)的.class文件
-rw-r--r-- 1 root????root?????410 6月???2 09:42 LicenseVerifier.class
-rw-r--r-- 1 root????root?????588 6月???2 09:41 LicenseVerifier.java
-rw-r--r-- 1 root????root????1464 6月???2 09:42 XPackBuild.class
-rw-r--r-- 1 root????root????1232 6月???2 09:41 XPackBuild.java
通過壓縮軟件將生成的.class文件分別替換到對(duì)應(yīng)的目錄下
org\elasticsearch\license\LicenseVerifier.class
org\elasticsearch\xpack\core\XPackBuild.class
然后用新的jar替換$ES_HOME/modules/x-pack-core/x-pack-core.7.6.2.jar
更新許可證
官方申請(qǐng)地址:https://register.elastic.co/marvel_register
郵箱和國家要正確填寫馅闽,其他隨便
根據(jù)你郵件收到的地址下載飘蚯,下載后更名為license.json
將 "type":"basic" 替換為 "type":"platinum" # 基礎(chǔ)班變更為白金版
將 "expiry_date_in_millis":的時(shí)間戳修改,具體想修改多長時(shí)間隨意福也,但是一定要時(shí)間戳局骤。
上傳license文件
curl -H "Content-Type: application/json" -XPUT???'http://ES-IP:9200/_xpack/license?acknowledge=true' -d @license.json
重啟Elasticsearch服務(wù)
上傳后查看證書時(shí)間http://ES-IP:9200/_license