环境:
OS:CentOS 7
elasticsearch:6.5.0
1.vim 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;
}
}
vim 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);
}
}
2.将刚创建的两个java包打包成class文件,我们需要做的就是替换这两个class文件(因里面需要引用到其他的jar,故需要用到javac -cp命令)
javac -cp "/opt/elasticsearch-6.5.0/lib/elasticsearch-6.5.0.jar:/opt/elasticsearch-6.5.0/lib/lucene-core-7.5.0.jar:/opt/elasticsearch-6.5.0/modules/x-pack-core/x-pack-core-6.5.0.jar" LicenseVerifier.java
javac -cp "/opt/elasticsearch-6.5.0/lib/elasticsearch-6.5.0.jar:/opt/elasticsearch-6.5.0/lib/lucene-core-7.5.0.jar:/opt/elasticsearch-6.5.0/modules/x-pack-core/x-pack-core-6.5.0.jar:/opt/elasticsearch-6.5.0/lib/elasticsearch-core-6.5.0.jar" XPackBuild.java
执行以上两个命令可以看出已经生产了2个class文件
[esuser@localhost espak]$ ls -al
total 16
drwxrwxr-x. 2 esuser esuser 110 Dec 13 14:44 .
drwxr-xr-x. 11 esuser esuser 181 Dec 13 14:33 ..
-rw-rw-r--. 1 esuser esuser 410 Dec 13 14:44 LicenseVerifier.class
-rw-rw-r--. 1 esuser esuser 508 Dec 13 14:34 LicenseVerifier.java
-rw-rw-r--. 1 esuser esuser 1508 Dec 13 14:44 XPackBuild.class
-rw-rw-r--. 1 esuser esuser 1273 Dec 13 14:35 XPackBuild.java
[esuser@localhost espak]$ pwd
/opt/elasticsearch-6.5.0/espak
3.把本来的文件给解压出来,然后覆盖
下面操作所在目录为:/opt/elasticsearch-6.5.0/espak
cd /opt/elasticsearch-6.5.0/espak
cp -a /opt/elasticsearch-6.5.0/modules/x-pack-core/x-pack-core-6.5.0.jar .
jar -xf x-pack-core-6.5.0.jar
rm -rf LicenseVerifier.java XPackBuild.java x-pack-core-6.5.0.jar
cp -a LicenseVerifier.class org/elasticsearch/license/
cp -a XPackBuild.class org/elasticsearch/xpack/core/
rm -rf LicenseVerifier.class XPackBuild.class
jar -cvf x-pack-core-6.5.0.jar *
cp -a x-pack-core-6.5.0.jar /opt/elasticsearch-6.5.0/modules/x-pack-core/
4.重新启动es
kill掉es进程
[esuser@localhost bin]$ ./elasticsearch -d
5.License申请
申请地址
https://license.elastic.co/registration
填写信息后,会有一个邮件发到注册的邮箱,然后安装提示点击链接进行下载
下载后上传服务器,修改过期时间expiry_date_in_millis,我这里修改为2524579200000,即2050-01-01 00:00:00,type修改为platinum
{"license":{"uid":"1e9a1465-3398-44e8-aa06-c76062dcfedf","type":"platinum","issue_date_in_millis":1544659200000,"expiry_date_in_millis":,"max_nodes":100,"issued_to":"xueliang huang (richinfo)","issuer":"Web Form","signature":"AAAAAwAAAA0CkXSNg+Yl6jgouxuAAAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSmkxaktJRVl5MUYvUWh3bHZVUTllbXNPbzBUemtnbWpBbmlWRmRZb25KNFlBR2x0TXc2K2p1Y1VtMG1UQU9TRGZVSGRwaEJGUjE3bXd3LzRqZ05iLzRteWFNekdxRGpIYlFwYkJiNUs0U1hTVlJKNVlXekMrSlVUdFIvV0FNeWdOYnlESDc3MWhlY3hSQmdKSjJ2ZTcvYlBFOHhPQlV3ZHdDQ0tHcG5uOElCaDJ4K1hob29xSG85N0kvTWV3THhlQk9NL01VMFRjNDZpZEVXeUtUMXIyMlIveFpJUkk2WUdveEZaME9XWitGUi9WNTZVQW1FMG1DenhZU0ZmeXlZakVEMjZFT2NvOWxpZGlqVmlHNC8rWVVUYzMwRGVySHpIdURzKzFiRDl4TmM1TUp2VTBOUlJZUlAyV0ZVL2kvVk10L0NsbXNFYVZwT3NSU082dFNNa2prQ0ZsclZ4NTltbU1CVE5lR09Bck93V2J1Y3c9PQAAAQBbRJOy1WgeFasn9hkqXcUu4jbVTH5B51CpsbpQTIukDJUeyo9z0DW1DzXzgUn1y0LQ62VDVcjiJvi0Xci5w9ZYDQPPVwf8PN0Pg8rOkawcJpr4ZmCiBgh/dFmgcOsjOjro1EcVOp3rm9zil89FsACMUcgRiYf//Ejahsx7giFEyYnUNOqfy4umh3aHj+awlg76P1OVxnyu74IjJdWGXluMw+hTJ0EKXcaUEfJpJgBLtPUmyD6jd/LtzV8ysKL6JQTxkUzdlWVdzipskQ8MWt5Nn6ClddwJFVb5lTAOJvLy6jyEmro4Fho5LJ6eRW2NvsWS4Y1Yu6lHVoWBVW4v++Wx","start_date_in_millis":1544659200000}}
6.导入
cd /soft (my.json文件在该目录下)
curl -XPUT -u elastic 'http://192.168.1.85:9200/_xpack/license' -H "Content-Type: application/json" -d @my.json
报错误:
可能遇到Cannot install a [PLATINUM] license unless TLS is configured or security is disabled的错误,解决方法在elasticsearch.yml新增:
xpack.security.enabled: false
然后重新启动
再次导入
curl -XPUT -u elastic:elastic 'http://192.168.1.85:9200/_xpack/license' -H "Content-Type: application/json" -d @my.json
{"acknowledged":true,"license_status":"valid"}
7.检查导入是否成功
[esuser@localhost soft]$ curl -u elastic:elastic "192.168.1.85:9200/_license"
{
"license" : {
"status" : "active",
"uid" : "1e9a1465-3398-44e8-aa06-c76062dcfedf",
"type" : "platinum",
"issue_date" : "2018-12-13T00:00:00.000Z",
"issue_date_in_millis" : 1544659200000,
"expiry_date" : "2049-12-31T16:00:00.000Z",
"expiry_date_in_millis" : 2524579200000,
"max_nodes" : 100,
"issued_to" : "xueliang huang (richinfo)",
"issuer" : "Web Form",
"start_date_in_millis" : 1544659200000
}
}
8.将如下参数修改为true后重新启动
xpack.security.enabled: true
发现启动的时候报错误
[1]: Transport SSL must be enabled for setups with production licenses. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]
安装提示将如下参数设置为true
xpack.security.transport.ssl.enabled
如果有多个节点ES集群,先将xpack.security.enabled设置为false后启动整个集群,然后再导入license。
发现6.5.1以后的版本包如下的错误
javax.net.ssl.SSLHandshakeException: no cipher suites in common
一时半会没找到解决办法