最近正在学习服务器应用平台的搭建的相关知识。有幸从朋友与书上了解到Elastic套件的使用,我花了两天的时间把最新的套件部署在我的服务器上,中间踩了数不清的坑。我把整个过程都记录了下来与各位有需要的朋友们分享一下。
Update
经过测试该安装破解方案已兼容Elasticsearch6.4.2至Kibana6.5.1版本
hostnamectl set-hostname xxx
yum update -y
yum install java-1.8.0* -y
从现在开始我们就要开始安装Elastic套件了,注意细节、提示与顺序
该过程的官方文档请参考如下链接
安装过程概览:https://www.elastic.co/products
Elasticsearch下载:https://www.elastic.co/downloads/elasticsearch
官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/index.html
根据文档的指引有以下步骤:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
/etc/yum.repos.d/
中添加源elasticsearch.repo
vim /etc/yum.repos.d/elasticsearch.repo
,并在添加完成后保存elasticsearch.repo
中写入源信息:[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
yum update -y && yum install elasticsearch -y
该过程的官方文档请参考如下链接
配置说明:https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html
根据文档的提示,我提取出一些关键信息
/usr/share/elasticsearch/
/etc/elasticsearch/
network.host: 0.0.0.0
http.port: 9200
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
官方文档重点翻译:
您应该很少需要更改Java虚拟机(JVM)选项。如果需要修改,最可能的更改是设置堆大小。设置JVM选项(包括系统属性和JVM标志)的首选方法是通过jvm.options配置文件修改。
您最好将最小堆大小(Xms)和最大堆大小(Xmx)设置为彼此相等。
Elasticsearch可用的堆越多,它可用于缓存的内存就越多。但是请注意,过多的堆可能会使您的机器陷入长时间的垃圾收集暂停。
设置Xmx为不超过物理RAM的50%,以确保有足够的物理RAM留给内核文件系统缓存。
官方关于JVM的文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
此配置文件的默认位置在/etc/elasticsearch/jvm.options
,视情况修改Xms
和Xms
,过多或过少的占用内存可能会导致程序崩溃或无法启动。
示例值:
-Xms2g
-Xmx2g
Elasticsearch 安装完成并初步配置后可以先不急着启动,可以使用命令systemctl start elasticsearch.service
启动Elasticsearch。
若想测试并验证安装结果,可以启动后访问http://
(默认地址http://域名或IP:9200
)进行验证,注意避免因为本机IP配置错误而导致无法连接的情况。
如能正常访问将显示如下格式的json数据
{
"name" : "qEgqyT5",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "wow17Li0SK-hgw-bOszN9g",
"version" : {
"number" : "6.4.2",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "04711c2",
"build_date" : "2018-09-26T13:34:09.098244Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
该过程的官方文档请参考如下链接
Kibana下载:https://www.elastic.co/downloads/kibana
官方文档:https://www.elastic.co/guide/en/kibana/6.4/index.html
根据文档的指引有以下步骤:
yum install kibana -y
/etc/kibana/kibana.yml
# 本机IP根据个人需要填写公网IP、内网IP或任意IP
server.host: "0.0.0.0"
#配置Kibana所连接的ES集群链接
elasticsearch.url: "http://localhost:9200"
systemctl enable kibana.service
systemctl start kibana.service
http://:
访问Kibana,可以用浏览器进行访问。默认地址http://域名或IP:5601
,效果如图。可以根据个人需要安装Beats与Logstash,通过上文中配置的yum进行安装,组建的配置普遍的都比较简单,一般都是设置主机地址和证书即可。
详细内容可参考官方文档:https://www.elastic.co/guide/en/beats/metricbeat/current/index.html
Beats简介:https://www.elastic.co/cn/products/beats
Logstash简介:https://www.elastic.co/cn/products/logstash
yum install metricbeat -y
/etc/metricbeat/metricbeat.yml
output.elasticsearch:
hosts: ["xxx.xxx.xxx.xxx:9200"]
setup.kibana:
host: "xxx.xxx.xxx.xxx:5601"
setup.dashboards.enabled: true
chkconfig --add metricbeat
systemctl start metricbeat
若想破解白金版服务,需要启动安全设置,也就是要在每个节点中安装证书
该过程的官方文档请参考如下链接
https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-security.html
在以下内容中我将主要陈述该版本的方法和之前版本的不同点,理由只简单陈述
Unexpected response code [403] from calling GET http://10.10.1.10:9200/_xpack/security/_authenticate?pretty
It doesn't look like the X-Pack security feature is available on this Elasticsearch node.
Please check if you have installed a license that allows access to X-Pack Security feature.
ERROR: X-Pack Security is not available.
Cannot connect to the Elasticsearch cluster currently configured for Kibana.
如图
为避免此问题,请先点击试用再配置x-pack的相关证书。
certutil
程序脚本,在路径/usr/share/elasticsearch/bin/x-pack/
中。但是,在6.4中已经不可用 (文件存在但是运行时会提示不可用),新的CA证书生成程序在/usr/share/elasticsearch/bin/
目录中,名为elasticsearch-certutil
/usr/share/elasticsearch/bin/
目录执行如下命令来生成证书。./elasticsearch-certutil ca --ca-dn "CN=WolfBolin Elatic CA" --out /etc/elasticsearch/certs/wolfbolin-elastic-ca.p12
/usr/share/elasticsearch/bin/
目录执行如下命令来生成证书。./elasticsearch-certutil cert -ca /etc/elasticsearch/certs/wolfbolin-elastic-ca.p12 --out /etc/elasticsearch/certs/wolfbolin-elastic-certificates.p12
/etc/elasticsearch/
下的文件,所以你应该将cert证书储存在/etc/elasticsearch/certs/
文件夹中,并给予适当的权限,我的设置是chmod 660 /etc/elasticsearch/certs/*
java.nio.file.AccessDeniedException:
的报错提示/etc/elasticsearch/elasticsearch.yml
,在文件结尾添加:xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/wolfbolin-elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/wolfbolin-elastic-certificates.p12
注意:两个证书是一样的,都是生成的cert证书。证书的名字和路径别弄错了!!!
若证书有密码可参考文档https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-tls.html#tls-transport
配置完成后重启Elasticsearch
systemctl restart elasticsearch.service
若在重启过程中出现错误与导致不能启动的,可以分析日志/var/log/elasticsearch/elasticsearch.log
查找原因。
阶段性成果
在配置了安全证书后,若尝试访问则会在网页上提示,此时Kibana是不可访问Elasticsearch的
Cannot connect to the Elasticsearch cluster currently configured for Kibana.
Refer to the Kibana logs for more details and refresh to try again.
setup-passwords
在6.4中已不可用(文件存在但是运行时会提示不可用),新的密码设置程序在/usr/share/elasticsearch/bin/
目录中,名为setup-passwords
/usr/share/elasticsearch/bin/
目录执行如下命令来生成密码。./elasticsearch-setup-passwords auto
(自动生成)或./elasticsearch-setup-passwords interactive
(手动设置)[root@sbox-wolfbolin bin]# ./elasticsearch-setup-passwords auto
Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]y
Changed password for user kibana
PASSWORD kibana = nEeVHfxms4Q4S6mWmzzH
Changed password for user logstash_system
PASSWORD logstash_system = zmb8xXkFk7KlLWYPHfO0
Changed password for user beats_system
PASSWORD beats_system = ejSOoRx87tx43IfokIot
Changed password for user elastic
PASSWORD elastic = RFWJ2dN0crlHk0ebUHN4
该凭据是其他应用程序连接Elasticsearch的凭据,请保存好
/etc/kibana/kibana.yml
elasticsearch.username:"elastic"
elasticsearch.password:"RFWJ2dN0crlHk0ebUHN4"
此帐号密码是Kibana连接Elasticsearch的凭据,若使用kibana账户则无法链接。
/etc/metricbeat/metricbeat.yml
,安装如下格式修改相关字段,密码按照上述自己修改的密码填写:output.elasticsearch:
hosts: ["myEShost:9200"]
username: "beats_system"
password: "ejSOoRx87tx43IfokIot"
setup.kibana:
host: "kibana_host:5601"
username: "kibana"
password: "nEeVHfxms4Q4S6mWmzzH"
重启应用以刷新配置:systemctl restart metricbeat
systemctl restart kibana.service
相关说明
不同于手工安装的x-pack,Elasticsearch6.4内包含的x-pack位于modules/x-pack-core
中,即:/usr/share/elasticsearch/modules/x-pack-core/x-pack-core-6.4.2.jar
文件。
反编译jar文件
在这个步骤中你完全可以跳过反编译的过程,直接使用我文章中给出的Java程序进行编译和替换。但如果有需要的可以该文件传出来并用luyten
反编译软件对jar包进行反编译,luyten项目地址:https://github.com/deathmarine/Luyten
修改x-pack源码
我们重点关心项目中的两个文件
package org.elasticsearch.license;
import java.nio.*;
import org.elasticsearch.common.bytes.*;
import java.security.*;
import java.util.*;
import org.elasticsearch.common.xcontent.*;
import org.apache.lucene.util.*;
import org.elasticsearch.core.internal.io.*;
import java.io.*;
public class LicenseVerifier
{
public static boolean verifyLicense(final License license, final byte[] publicKeyData) {
return true;
}
public static boolean verifyLicense(final License license) {
return true;
}
}
org.elasticsearch.xpack.core.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);
}
}
javac -cp "/usr/share/elasticsearch/modules/x-pack-core/*:/usr/share/elasticsearch/lib/*" LicenseVerifier.java
javac -cp "/usr/share/elasticsearch/modules/x-pack-core/*:/usr/share/elasticsearch/lib/*" XPackBuild.java
cd /usr/share/elasticsearch/modules/x-pack-core/
cp x-pack-core-6.4.2.jar x-pack-core-6.4.2.jar.bak
cp x-pack-core-6.4.2.jar /home/x-pack-core-6.4.2.jar
jar -xvf x-pack-core-6.4.2.jar
该命令会解压到当前目录unzip x-pack-core-6.4.2.jar -d ./x-pack-core-6.4.2
该命令可以指定目录cp LicenseVerifier.class ./x-pack-core-6.4.2/org/elasticsearch/license/
cp XPackBuild.class ./x-pack-core-6.4.2/org/elasticsearch/xpack/core/
jar -cvf x-pack-core-6.4.2.crack.jar -C x-pack-core-6.4.2/ .
(不可忽略那个英文句号)cp x-pack-core-6.4.2.crack.jar /usr/share/elasticsearch/modules/x-pack-core/x-pack-core-6.4.2.jar
systemctl restart elasticsearch.service
{
"license": {
"uid": "c6570128-85c2-4f72-8d8f-b1425455b9ee",
"type": "basic",
"issue_date_in_millis": 1540080000000,
"expiry_date_in_millis": 1571702399999,
"max_nodes": 100,
"issued_to": "elastic",
"issuer": "elastic",
"signature": "AAAAAwAAAA07qIy5rp9i1qa5VS3vAAAB...",
"start_date_in_millis": 1540080000000
}
}
修改type字段为platinum,表示铂金版
修改expiry_date_in_millis字段为2147482800000,表示时间尽头
修改max_nodes字段为1000,表示集群数量
{
"license": {
"uid": "c6570128-85c2-4f72-8d8f-b1425455b9ee",
"type": "basic",
"issue_date_in_millis": 1540080000000,
"expiry_date_in_millis": 1571702399999,
"max_nodes": 100,
"issued_to": "elastic",
"issuer": "elastic",
"signature": "AAAAAwAAAA07qIy5rp9i1qa5VS3vAAAB...",
"start_date_in_millis": 1540080000000
}
}
注:“2147482800” 表示 “北京时间2038-1-19 11:00:00”