声明:本文不包含任何交易,如有侵权,请联系我进行删除
本环境版本为:elasticsearch-6.6.2
从6.3+版本起,xpack已内置于es,已不需要安装插件。
正题开始:
第一步:生成ca证书
在elasticsearch/bin目录下执行:(我四条命令均是一直按回车,不设置密码)
./elasticsearch-certutil ca ##会让输入密码,也可以直接回车使用默认密码
./elasticsearch-certutil cert --ca elastic-stack-ca.p12
./elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
执行完成后,在bin下产生elastic-stack-ca.p12、elastic-certificates.p12 两个文件,在config目录下产生elasticsearch.keystore文件(如果不在config下,将elasticsearch.keystore移动到config)。将三个文件发送至所有es服务对应目录下。
第二步:配置x-pack
在config下创建certs目录。(所有es服务均需要操作)
mkdir certs
将elastic-stack-ca.p12、elastic-certificates.p12 两个文件放在certs目录下(所有es服务均需要操作)
三个文件结构如下图:(一定注意文件位置!!)
添加配置 elasticsearch.yml (所有es服务均需要操作)
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
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
第三步:开启x-pack试用和破解
开启试用:
curl -H "Content-Type:application/json" -XPOST http://10.91.1.87:9200/_xpack/license/start_trial?acknowledge=true
不开启试用,执行./elasticsearch-setup-passwords interactive会报如下错误
破解x-pack方法
创建一个临时录目录,并进入目录
mkdir /root/xpack
创建 LicenseVerifier.java
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;
}
}
创建 XPackBuild.java
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);
}
}
分别编译 LicenseVerifier.java 和 XPackBuild.java
javac -cp "/opt/bdp/data01/es01/elasticsearch-6.6.2/lib/elasticsearch-6.6.2.jar:/opt/bdp/data01/es01/elasticsearch-6.6.2/lib/lucene-core-7.6.0.jar:/opt/bdp/data01/es01/elasticsearch-6.6.2/modules/x-pack-core/x-pack-core-6.6.2.jar" LicenseVerifier.java
javac -cp "/opt/bdp/data01/es01/elasticsearch-6.6.2/lib/elasticsearch-6.6.2.jar:/opt/bdp/data01/es01/elasticsearch-6.6.2/lib/lucene-core-7.6.0.jar:/opt/bdp/data01/es01/elasticsearch-6.6.2/modules/x-pack-core/x-pack-core-6.6.2.jar:/opt/bdp/data01/es01/elasticsearch-6.6.2/lib/elasticsearch-core-6.6.2.jar" XPackBuild.java
编译后生成两个与 .java同名的 .class文件
将原来的x-pack-core-6.6.2.jar class文件覆盖。
mkdir tmp && cd tmp
cp /opt/bdp/data01/es01/elasticsearch-6.6.2/modules/x-pack-core/x-pack-core-6.6.2.jar ./
jar -xf x-pack-core-6.6.2.jar ##解压
cp ../LicenseVerifier.class org/elasticsearch/license/ ##替换文件
cp ../XPackBuild.class org/elasticsearch/xpack/core/ ##替换文件
jar -cvf x-pack-core-6.6.2.jar * ##再压缩
将生成的 x-pack-core-6.6.2.jar 发送到所有es,覆盖原来的jar文件
第四步:重启机器并设置密码
重启es
此时 通过 curl http://10.91.1.87:9200/_cluster/health?pretty 无法观察集群状态
观察其中一台master日志,集群状态由red变为yellow
Cluster health status changed from [RED] to [YELLOW]
执行生成密码:
./elasticsearch-setup-passwords interactive
输入自己的密码。直至结束。
通过用户密码查看集群将康状态,可以查看,x-pack生效。
第五步:申请license
查看当前es集群的license信息
curl -u "elastic":"123123" http://10.91.1.81:9200/_license
type 表示在试用,expiry_date 显示一个月后过期
登录官网,申请一个license
国家选 china , 邮箱写自己能接收邮件的邮箱,其他随便写。
接收邮件并下载json文件。
打开文件并修改内容:
"type": "platinum" ##白金版
"expiry_date_in_millis": 2547615064000 ##到期日期2050-09-24 14:51:04
第六步:上传license
上传license 三台master都要执行
curl -XPUT -u "elastic":"123123" 'http://10.91.1.81:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
再次查看license信息,到期时间已经变为2050年了
至此 结束,搞了一天半(烦死了),查了各种文档博客,此篇为综合了自己的操作和文档支持揉搓的我的整体心酸流程,希望其他人不要踩坑,顺利完成。
参考文献:
感谢各位博客大佬提供的文档支持!!!!!
Elasticsearch6.3.2之x-pack-腾讯云开发者社区-腾讯云
Elasticsearch 安装 X-pack_elasticsearch xpack-CSDN博客
ElasticSearch学习(十二)—— es7.2日志警告SSLHandshakeException: no cipher suites in common-CSDN博客