在elasticsearch中有30天的试用期,我找到网上大神的一些文章,试用了之后发现可以进行破解使用,整个过程比较简单,特此写下笔记
一,破解x-pack 6.3.2
我也不清楚为什么叫做破解,顾名思义就是打开限制的功能,达到我们所想要的目的。我个人是不赞同用破解(盗版)这个词的。因为对我而言除了登录那个好看一些的画面外,我仍然可以使用nginx或者ip地址限制来做,或者使用grafana也是个不错的选择。但是作为一个以侠客自居的手艺人,工匠精神必然不能少,于是怀着要弄就弄一套的想法,在略带忧伤的情绪下,还是给弄好了并分享。
在开始之前,破解这个限制的顺序有必要说明下,顺序如下:1,安装elk,关闭x-pack启动2,重新打x-pack包,修改license3,修改license后成为白金用户后在修改密码4,开启x-pack重要提示 : xpack.security.enabled只有在破解之后,并且配置好ssl,才能为true,当设置了密码就可以登录
1.1 修改license
准备LicenseVerifier.java 和XPackBuild.java两个文件后进行替换
-
LicenseVerifier.java如下:
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.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); } }
1.1.2 打包成class
打包成class,而后替换。如果你的安装在/usr/local下,那么大概如下
-
LicenseVerifier
javac -cp "/usr/local//elasticsearch-6.3.2/lib/elasticsearch-6.3.2.jar:/usr/local/elasticsearch-6.3.2/lib/lucene-core-7.3.1.jar:/usr/local/elasticsearch-6.3.2/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar" LicenseVerifier.java
-
XPackBuild
javac -cp "/usr/local/elasticsearch-6.3.2/lib/elasticsearch-6.3.2.jar:/usr/local/elasticsearch-6.3.2/lib/lucene-core-7.3.1.jar:/usr/local/elasticsearch-6.3.2/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar:/usr/local/elasticsearch-6.3.2/lib/elasticsearch-core-6.3.2.jar" XPackBuild.java
1.1.3 替换
而后在将x-pack-core/x-pack-core-6.3.2.jar拿到本地解压复制到本地
cp -a /usr/local/elasticsearch-6.3.2/modules/x-pack/x-pack-core/x-pack-core-6.3.2.jar .
到此,目录下有5个文件
[root@linuxea-vm-Node113 /es]# ll 总用量 1736 -rw-r--r-- 1 root root 410 8月 7 20:53 LicenseVerifier.class -rw-r--r-- 1 root root 593 8月 7 20:50 LicenseVerifier.java -rw-r--r-- 1 root root 1508 8月 7 20:53 XPackBuild.class -rw-r--r-- 1 root root 1358 8月 7 20:51 XPackBuild.java -rw-r--r-- 1 root root 1759804 8月 7 20:49 x-pack-core-6.3.2.jar
为了能够分辨的更清楚,创建一个目录jardir,复制进去后解压,而后删除原来的包或者备份
[root@linuxea-vm-Node113 /es]# mkdir jardir [root@linuxea-vm-Node113 /es]# cp x-pack-core-6.3.2.jar jardir/ [root@linuxea-vm-Node113 /es]# cd jardir/ [root@linuxea-vm-Node113 /es/jardir]# jar -xf x-pack-core-6.3.2.jar [root@linuxea-vm-Node113 /es/jardir]# rm -rf x-pack-core-6.3.2.jar
将class覆盖进去
[root@linuxea-vm-Node113 /es/jardir]# cd .. [root@linuxea-vm-Node113 /es]# cp -a LicenseVerifier.class jardir/org/elasticsearch/license/ cp:是否覆盖"jardir/org/elasticsearch/license/LicenseVerifier.class"? yes [root@linuxea-vm-Node113 /es]# cp -a XPackBuild.class jardir/org/elasticsearch/xpack/core/ cp:是否覆盖"jardir/org/elasticsearch/xpack/core/XPackBuild.class"? yes
当文件覆盖到jardir中的org/elasticsearch/xpack/core和org/elasticsearch/license中后,开始打包
[root@linuxea-vm-Node113 /es]# cd jardir/ [root@linuxea-vm-Node113 /es/jardir]# jar -cvf x-pack-core-6.3.2.jar * 已添加清单 正在添加: logstash-index-template.json(输入 = 994) (输出 = 339)(压缩了 65%) 正在忽略条目META-INF/ 正在忽略条目META-INF/MANIFEST.MF 正在添加: META-INF/LICENSE.txt(输入 = 13675) (输出 = 5247)(压缩了 61%)
生成一个新的x-pack-core-6.3.2.jar包后覆盖到/usr/local/elasticsearch-6.3.2/modules/x-pack/x-pack-core/下,license修改完成,而后重启注意,旧的在替换之前就删除了,新的是重新jar -cvf生成的
[root@linuxea-vm-Node113 ~]# ps aux|egrep ^elk|awk '{print $2}'|xargs kill && sudo -u elk /usr/local/elasticsearch-6.3.2/bin/elasticsearch -d
1.1.4 申请license
打开elastic申请页面进行申请,会发送到邮箱,下载后进行编辑将 "expiry_date_in_millis":1565135999999
修改"expiry_date_in_millis":2565135999999
将"type":"basic"
修改为"type":"platinum"
他表现的样子大概是这样的(当然,你不能用下面这种格式进行update,请使用在官网申请的license,他会发送到你填写的邮箱)
{"license":{
"uid":"2651b126-fef3-480e-ad4c-a60eb696a733",
"type":"platinum", # 白金
"issue_date_in_millis":1533513600000,
"expiry_date_in_millis":2565135999999, # 到期时间
"max_nodes":100,"
issued_to":"mark tang (www.linuxea.com)",
"issuer":"Web Form",
"signature":"AAAAAwAAAA2Of4OxzPNK/yl15sO4AAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSmkxaktJRVl5MUYvUWh3bHZVUTllbXNPbzBUemtnbWpBbmlWRmRZb25KNFlBR2x0TXc2K2p1Y1VtMG1UQU9TRGZVSGRwaEJGUjE3bXd3LzRqZ05iLzRteWFNekdxRGpIYlFwYkJiNUs0U1hTVlJKNVlXekMrSlVUdFIvV0FNeWdOYnlESDc3MWhlY3hSQmdKSjJ2ZTcvYlBFOHhPQlV3ZHdDQ0tHcG5uOElCaDJ4K1hob29xSG85N0kvTWV3THhlQk9NL01VMFRjNDZpZEVXeUtUMXIyMlIveFpJUkk2WUdveEZaME9XWitGUi9WNTZVQW1FMG1DenhZU0ZmeXlZakVEMjZFT2NvOWxpZGlqVmlHNC8rWVVUYzMwRGVySHpIdURzKzFiRDl4TmM1TUp2VTBOUlJZUlAyV0ZVL2kvVk10L0NsbXNFYVZwT3NSU082dFNNa2prQ0ZsclZ4NTltbU1CVE5lR09Bck93V2J1Y3c9PQAAAQAPymKvMYxtKy8+1tbaE0yvRbt4USyN5VYwY1+vBfxNyjUtrIgW3RQJfj/3McveTM7hiKHZXeDT+BAn9NdgFIBJ5ztA94s72RlkUJBQjSiqg50/1Nu5OTKloPKCs4R7pk42uapNISWubpRIXyGGer0KKLkpoBBlQkvwETNHk/aDGnzBzOJ/vppRYQgUtQx5ZXVo+U391w1sNj8lXuZrLwEByYU5ms25HVG1Ith0THelZMqoB0x2gvZklR5RQbEmWPGXOsBXLnfLPM571Op63TxGt+vsiNIvxBjsuq62tuhRkgAHkyqY2z+RLFDafQxUXtz41b6fgRLV5XPCDqiOWYvB",
"start_date_in_millis":1533513600000}}
当你已经修改了时间和白金类型后,上传来到 Management 选择 License Management,点击update license上传以及修改好的License ,如下(当然,我的已经修改好了,那个很骚的PLATINUM就是)修改好后来到License Management查看已经到了April 15, 2051 9:46 AM CST ok,到此es License 已经修改完成,也就是破解成功,那么接下来就是用下ssl的验证功能
二 ,elasticsearch ssl
6.3中x-pack是不能够开启密码登陆的,但这并不阻碍我们进行了解,他存在一些权限的问题,我在使用中发现无法使用,这里的信息可做参考,后面的配置中并不启用
- 请注意
权限问题说明
chmod +r $PATH/cerp/*
chown -R elk.elk /data/elasticsearch
2.1.1 颁发
创建证书颁发机构ca,会输出一个elastic-stack-ca.p12的文件在当前目录下,其中包含ca公用证书以及节点的签名和私钥。
[root@linuxea-vm-Node113 ~/crt]# /usr/local/elasticsearch-6.3.2/bin/elasticsearch-certutil ca
在提示输入密码保护时候输入密码并记住(假如你输了的话)生成证书和私钥,输入设置的保护密码(如果没有则不需要输入)
[root@linuxea-vm-Node113 ~/crt]# /usr/local/elasticsearch-6.3.2/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
如果不出所料你将看到两个文件
-rw------- 1 root root 3443 8月 6 13:00 elastic-certificates.p12
-rw------- 1 root root 2527 8月 6 12:59 elastic-stack-ca.p12
2.2.2 使用
创建证书目录
[root@linuxea-vm-Node113 ~/crt]# mkdir /usr/local/elasticsearch-6.3.2/config/certs/
[root@linuxea-vm-Node113 ~/crt]# cp elastic-* /usr/local/elasticsearch-6.3.2/config/certs/
传递给其他elasticsearch机器(当然,目录还要创建)
[root@linuxea-vm-Node113 ~/crt]# scp elastic-* 10.10.240.114:/usr/local/elasticsearch-6.3.2/config/certs/
[root@linuxea-vm-Node113 ~/crt]# scp elastic-* 10.0.1.49:/usr/local/elasticsearch-6.3.2/config/certs/
而后修改权限,主要给java访问,否则报错Caused by: java.nio.file.AccessDeniedException
[root@linuxea-vm-Node113 ~/crt]# chmod +r /usr/local/elasticsearch-6.3.2/config/certs/
[root@linuxea-vm-Node113 ~/crt]# chown -R elk.elk /data/elasticsearch
2.2.3 在配置文件使用
配置到配置文件将一下配置文件写到两台elasticsearch里面
当然,如果你不了解之前怎么配置的,参考ELK6.3.2安装与配置[跨网络转发思路](https://www.linuxea.com/1889.html)其中包含配置和安装信息
xpack.security.enabled: true
xpack.monitoring.collection.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ssl.verification_mode: none
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
- 注意
将xpack.security.enabled
改成 true
,之前没有启用时false,并且填写相对的路径xpack.ssl.verification_mode
必须为 none
,否则报错,意思大概就是忽略服务器密钥验证,只考虑使用,其中会失去一些诊断的机制
xpack.security.transport.ssl.enabled: true
开启,否则报[o.e.x.s.t.n.SecurityNetty4ServerTransport] [master] exception caught on transport layer [NettyTcpChannel
错误
三,修改密码
当执行完上面的操作后,重启并未 报错的情况下选择一台elasticsearch执行elasticsearch-setup-passwords interactive如果按照我说演示的操作会出现以下对话,输入密码即可
[root@linuxea-vm-Node113 ~]# /usr/local/elasticsearch-6.3.2/bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [elastic]
但密码输入完成后会同步到其他节点只需要修改kibana和logstash的配置即可完成
3.1 kibana配置密码验证
将xpack.security.enabled
改为true开启监控和添加验证
xpack.security.enabled: true
xpack.monitoring.enabled: true
elasticsearch.username: "elastic"
elasticsearch.password: "linuxea"
重启kibana就可以完成登录
- 注意
如果顺序错误这可能会失败,但是请关注你的日志报错,正常的顺序一定是要先破解了之后才能使用x-pack