X-pack是elasticsearch的一個擴展包,將安全,警告,監視,圖形和報告功能捆綁在一個易於安裝的軟件包中,雖然x-pack被設計爲一個無縫的工做,可是你能夠輕鬆的啓用或者關閉一些功能。java
目前6.2及如下版本只能使用免費版,然而免費版的功能至關少。X-pack 的破解基本思路是先安裝正常版本,以後替換破解的jar包來實現,目前只能破解到白金版,但已經夠用了。node
先下載最新版本的 x-pack,裏面包含了 es,kibana,logstash 新版本的x-pack
下載地址:https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-6.2.4.zip
以後到es目錄執行git
[root@elk ~]# ./bin/elasticsearch-plugin install file:///opt/x-pack-6.2.4.zip
或者:github
[root@elk ~]# .bin/elasticsearch-plugin install x-pack
須要贊成下協議 回車 輸入y 回車 會提示安裝成功apache
修改代碼
LicenseVerifier 中有兩個靜態方法,這就是驗證受權文件是否有效的方法,咱們把它修改成所有返回true.json
package org.elasticsearch.license; import java.nio.*; import java.util.*; import java.security.*; import org.elasticsearch.common.xcontent.*; import org.apache.lucene.util.*; import org.elasticsearch.common.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 中 最後一個靜態代碼塊中 try的部分所有刪除,這部分會驗證jar包是否被修改安全
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); } }
編譯java文件,把class文件替換到原來的x-pack-core-6.2.2.jar中app
[root@elk ~]# javac -cp "/usr/share/elasticsearch/lib/elasticsearch-6.2.4.jar:/usr/share/elasticsearch/lib/lucene-core-7.2.1.jar:/usr/share/elasticsearch/plugins/x-pack/x-pack-core/x-pack-core-6.2.4.jar:/usr/share/elasticsearch/lib/elasticsearch-core-6.2.4.jar" XPackBuild.java [root@elk ~]# javac -cp "/usr/share/elasticsearch/lib/elasticsearch-6.2.4.jar:/usr/share/elasticsearch/lib/lucene-core-7.2.1.jar:/usr/share/elasticsearch/plugins/x-pack/x-pack-core/x-pack-core-6.2.4.jar" LicenseVerifier.java
[root@elk ~]# ./bin/x-pack/setup-passwords interactive
這樣破解的x-pack就安裝好了curl
elasticsearch 6.2.4 中默認開啓了安全驗證,咱們暫時修改配置文件以方便導入本身的文件
在elasticsearch.yml 中 添加一下配置elasticsearch
xpack.security.enabled:false
{"license": { "uid":"32575be3-f4d3-4bd7-a93f-be00562e976e", "type":"platinum", "issue_date_in_millis":1528070400000, "expiry_date_in_millis":252457920099, "max_nodes":1000, "issued_to":"billy li (test)", "issuer":"Web Form", "signature":"AAAAAwAAAS", "start_date_in_millis":1528070400000}}
咱們將過時時間寫到2050年,type改成platinum 白金版,這樣咱們就會擁有所有的x-pack功能
執行命令 導入
curl -XPUT -u elastic 'http://10.31.90.181:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
執行後會提示導入成功。
注:若是有多個節點ES集羣,把全部es節點關閉而後開啓一個節點,在這個節點導入license,集羣其餘節點會自動同步license。