支持5.x 6.x。这里以6.3.2为例,因为阿里的是这个版本。虽然有参考文章,还是有非常多的坑,在此缅怀我的脑细胞 !!!
参考:
https://zhuanlan.zhihu.com/p/38576593
https://blog.51cto.com/forall/2410593

备份:已经做好的jar:x-pack-core-6.3.2.jar

破解过程

初始化基础环境

设置esdir变量,方便后续操作。(es路径要绝对路径)
新建空文件夹,方便编译文件

  1. esdir=/home/es/elasticsearch-6.3.2
  2. cd ${esdir}
  3. mkdir tempdir && cd tempdir
  4. cp ${esdir}/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar ./
  5. jar -xvf x-pack-core-6.3.2.jar && rm -f x-pack-core-6.3.2.jar

反编译LicenseVerifier

  1. echo "
  2. package org.elasticsearch.license;
  3. public class LicenseVerifier
  4. {
  5. public static boolean verifyLicense(final License license, final byte[] encryptedPublicKeyData) {
  6. return true;
  7. }
  8. public static boolean verifyLicense(final License license) {
  9. return true;
  10. }
  11. }
  12. " > LicenseVerifier.java
  13. javac -cp "${esdir}/lib/*:${esdir}/modules/x-pack/x-pack-core/*" LicenseVerifier.java
  14. mv LicenseVerifier.class org/elasticsearch/license/

反编译XPackBuild

  1. cat > XPackBuild.java << \EOF
  2. package org.elasticsearch.xpack.core;
  3. import java.io.IOException;
  4. import java.net.URISyntaxException;
  5. import java.net.URL;
  6. import java.nio.file.Files;
  7. import java.nio.file.OpenOption;
  8. import java.nio.file.Path;
  9. import java.util.jar.JarInputStream;
  10. import java.util.jar.Manifest;
  11. import org.elasticsearch.common.SuppressForbidden;
  12. import org.elasticsearch.common.io.PathUtils;
  13. public class XPackBuild {
  14. public static final XPackBuild CURRENT;
  15. private String shortHash;
  16. private String date;
  17. @SuppressForbidden(
  18. reason = "looks up path of xpack.jar directly"
  19. )
  20. static Path getElasticsearchCodebase() {
  21. final URL url = XPackBuild.class.getProtectionDomain().getCodeSource().getLocation();
  22. try {
  23. return PathUtils.get(url.toURI());
  24. } catch (URISyntaxException var2) {
  25. throw new RuntimeException(var2);
  26. }
  27. }
  28. XPackBuild(final String shortHash, final String date) {
  29. this.shortHash = shortHash;
  30. this.date = date;
  31. }
  32. public String shortHash() {
  33. return this.shortHash;
  34. }
  35. public String date() {
  36. return this.date;
  37. }
  38. static {
  39. final Path path = getElasticsearchCodebase();
  40. String shortHash = null;
  41. String date = null;
  42. Label_0157: {
  43. shortHash = "Unknown";
  44. date = "Unknown";
  45. }
  46. CURRENT = new XPackBuild(shortHash, date);
  47. }
  48. }
  49. EOF
  50. javac -cp "${esdir}/lib/*:${esdir}/modules/x-pack/x-pack-core/*" XPackBuild.java
  51. mv XPackBuild.class org/elasticsearch/xpack/core/

打包并替换新的jar包

  1. jar -cvf x-pack-core-6.3.2.jar ./*
  2. # 备份并替换x-pack包
  3. mv ${esdir}/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar ${esdir}/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar.back
  4. mv x-pack-core-6.3.2.jar ${esdir}/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar

更新license

  1. # es关闭验证,并启动
  2. vim ${esdir}/config/elasticsearch.yml
  3. xpack.security.enabled: false
  4. # 创建license.json,里面参数可以修改
  5. cat > license.json << \EOF
  6. {"license":{"uid":"6e7e391d-3a63-4624-b627-127da3824fd3","type":"platinum","issue_date_in_millis":1579392000000,"expiry_date_in_millis":2855980923000,"max_nodes":100,"issued_to":"tian yun (yzs)","issuer":"Web Form","signature":"AAAAAwAAAA3eClFPz7RjJ4/7n0O7AAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSmkxaktJRVl5MUYvUWh3bHZVUTllbXNPbzBUemtnbWpBbmlWRmRZb25KNFlBR2x0TXc2K2p1Y1VtMG1UQU9TRGZVSGRwaEJGUjE3bXd3LzRqZ05iLzRteWFNekdxRGpIYlFwYkJiNUs0U1hTVlJKNVlXekMrSlVUdFIvV0FNeWdOYnlESDc3MWhlY3hSQmdKSjJ2ZTcvYlBFOHhPQlV3ZHdDQ0tHcG5uOElCaDJ4K1hob29xSG85N0kvTWV3THhlQk9NL01VMFRjNDZpZEVXeUtUMXIyMlIveFpJUkk2WUdveEZaME9XWitGUi9WNTZVQW1FMG1DenhZU0ZmeXlZakVEMjZFT2NvOWxpZGlqVmlHNC8rWVVUYzMwRGVySHpIdURzKzFiRDl4TmM1TUp2VTBOUlJZUlAyV0ZVL2kvVk10L0NsbXNFYVZwT3NSU082dFNNa2prQ0ZsclZ4NTltbU1CVE5lR09Bck93V2J1Y3c9PQAAAQA1swTP4mHuuHRpvVXR/QQ4RZdLz/vJyKfqOLpRCoSX+sOUzWhzF21j/uyjyVMFca55gj1Af26rIHxdaYuXB6iysWaGq8YolT5cJX3r67LtAzf+w83ZQQlg8Ack4owmsgzWyMMKRvOIjH5eSgVoPJtrPSZ/gfwmHE3gQbbzawKkDX81V5QvgdSz8uxCakBGFGxrHKqCBPQHXrRvz4em/Cl6ZadwDOIxF2fo9JNyDDfXFrxojjPynI6tIK7VyT6JREoQOd/6Ie07pqsYXsNsQ4Gv8qMzwhF6oy2lomM9DiTxxzv65RgCzPEILasMD5pPucc9TLKrwiVp0Krrq3+iuk0A","start_date_in_millis":1579392000000}}
  7. EOF
  8. 设置密码和更新license,记得修改自己的密码
  9. curl -H "Content-Type:application/json" \
  10. -XPUT -u elastic:changeme \
  11. "http://127.0.0.1:9200/_xpack/license?acknowledge=true" \
  12. -d @license.json
  13. 如果返回 :{"acknowledged":true,"license_status":"valid"} 则表示成功,否则表示之前的jar编译失败。

重新启动es

  1. # 修改配置并重新启动
  2. xpack.security.enabled: true
  3. xpack.security.transport.ssl.enabled: true
  4. # 设置密码
  5. sh bin/elasticsearch-setup-passwords interactive
  6. # 查看是否成功
  7. curl -XGET -u elastic:changeme "http://127.0.0.1:9200/_license"

修改密码方式

方式1:

  1. sh bin/elasticsearch-setup-passwords interactive

方式2:

  1. curl -H "Content-Type:application/json" \
  2. -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' \
  3. -d '{ "password" : "123456" }'

CA证书

集群节点通信需要,单节点可以忽略。

1、生成证书

  1. # 获取CA证书,默认即可
  2. ./bin/elasticsearch-certutil ca
  3. # 获取ssl加密证书,使用第一步默认文件
  4. ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

2、修改es配置

  1. xpack.security.transport.ssl.verification_mode: certificate
  2. xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
  3. xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12

kibana设置

vim config/kibana.yml

  1. elasticsearch.username: elastic
  2. elasticsearch.password: "123456" # 如果是数字,则必须加引号,是一个坑
  3. server.host: "0.0.0.0" # 必须设置,否则远程不能访问,是一个坑
  4. elasticsearch.url: "http://localhost:9200"

启动即可

  1. nohup bin/kibana >/etc/null &

访问ip:5601

image.png

bug

第二次修改密码

bin/elasticsearch-setup-passwords interactive —设置密码 可能会出现如下内容: Possible causes include:

  • The password for the ‘elastic’ user has already been changed on this cluster
  • Your elasticsearch node is running against a different keystore

  • This tool used the keystore at /usr/share/elasticsearch/config/elasticsearch.keystore

解决:

1、关掉安全防护,然后重启

2、curl -XDELETE http://localhost:9200/.security-6

3、打开安全防护,然后重启

4、正常输入:bin/elasticsearch-setup-passwords interactive