Elasticsearch安装了x-pack后x-pack有效期仅有30天的有效期,参照网上的各种方案进行整理如下。
0、需要准备的软件和环境说明
环境
系统 centos 7
elastic 5.5(我在这个版本做的实操)
需要软件
Luyten 反编译软件。
javac 编译(java->class)
jar 解包并重新打包
1、修改License文件
使用Luyte打开并找到:org.elasticsearch.license/LicenseVerifier.java 。可以使用Luyte 另存为,或者把文件里面的内容复制出来。新建一个同名同类型文件保存改代码。在Luyte上不支持直接修改。对LicenseVerifier.Java文件的两个方法修改返回true
// 把verifyLicense方法结果修改返回true即可
public static boolean verifyLicense(final License license, final byte[] encryptedPublicKeyData) {
return true;
}
public static boolean verifyLicense(final License license) {
return true;
}
3、编译LicenseVerifier.java成LicenseVerifier。
# 切换LicenseVerified.java目录
cd /tmp/
# 进行编译。编译需要指定依赖的jar包文件。得到LicenseVerifier.class
javac "/opt/elasticsearch/lib/elasticsearch5.5.0.jar:/opt/elasticsearch/lib/lucene-core-6.6.0.jar:/opt/elasticsearch/plugins/x-pack/x-pack-5.5.0.jar" LicenseVerifier.java
# 对x-pack-5.5.0.jar解压
cp /opt/elasticsearch/plugins/x-pack/x-pack-5.5.0.jar /tmp/xpack
cd /tmp/xpack
jar -xf x-pack-5.5.0.jar && rm -rf x-pack-5.5.0.jar
# 把LicenseVerifier.class 文件替换
cp /tmp/LicenseVerifier.class /tmp/xpack/org/elasticsearch/license/LicenseVerifier.class
# 重新打包
java -cf x-pack-5.5.0.jar ./
# 替换jar包
cp x-pack-5.5.0.jar /opt/elasticsearch/plugins/x-pack/x-pack-5.5.0.jar /tmp/xpack
4、申请免费证书。填写接收证书的邮件,得到一个json文件
// 文件主要修改两个字段 type:证书类型 && expriy:到期时间
"type":"platinum";
"expiry_date_in_millis":2524579200999
5、es证书进行更替.
# 更新证书
curl -XPUT -u elastic:changeme 'http://127.0.0.1:9200/_xpack/license' -d @license.json
# 检查证书
curl -XGET -u elastic:changeme 'http://192.168.100.50:9200/_license'