1 安装java环境
1.1 下载JDK
jdk-8u121-linux-x64.tar.gz
1.2 解压jdk
tar -zxvf jdk-8u121-linux-x64.tar.gz
解压到 /usr/local/ 下
/usr/local/jdk1.8.0_121/
1.3 配置环境变量
再/etc/profile 最后面添加
export JAVA_HOME=/usr/local/jdk1.8.0_121
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
使用环境变量生效
source /etc/profile
1.4 验证
$ java -version
2 安装ES(elasticsearch)
2.1下载
elasticsearch-6.4.2.rpm
2.2 安装
rpm -ivh elasticsearch-6.4.2.rpm
2.3修改ES配置文件
cluster.name: TRAS-ES # 集群名称
node.name: node1 # 主机名
path.data: /ES/data # 数据路径
path.logs: /ES/logs # 日志路径
network.host: 192.168.1.101
http.port: 9200
2.4 启动
systemctl start elasticsearch
2.5 验证
$ curl 'http://192.168.1.101:9200/'
{
"name" : "node1",
"cluster_name" : "TRAS-ES",
"cluster_uuid" : "g_YrGeWpT4aEMKAdigk-rQ",
"version" : {
"number" : "6.4.2",
"build_flavor" : "default",
"build_type" : "tar",
"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"
}
3.设置x-pack
3.1 生成CA证书
- 进入
/usr/share/elasticsearch/bin/
目录执行如下命令来生成证书。./elasticsearch-certutil ca --ca-dn "CN=uupt Elatic CA" --out /etc/elasticsearch/certs/uupt-elastic-ca.p12
内容和参数的含义可以自行百度,百度上的说明还是能看明白的。若需要使用TLS/SSL证书可以参考官方文档。 - 生成cert证书 同样的,可以在
/usr/share/elasticsearch/bin/
目录执行如下命令来生成证书。./elasticsearch-certutil cert -ca /etc/elasticsearch/certs/uupt-elastic-ca.p12 --out /etc/elasticsearch/certs/uupt-elastic-certificates.p12
该证书生成程序会以交互式的方式完成证书的生成,建议cert证书生成时不带密码,以降低配置复杂性(输入密码时直接回车就好)
3.2合理的保存证书
在保存证书时有两点需要注意
- cert证书中包含了CA证书的密码,所以不应被随意读取,注意权限的调整
- 也许是由于Java或程序自身的限制,Elasticsearch无法读取非配置目录
/etc/elasticsearch/
下的文件,所以你应该将cert证书储存在/etc/elasticsearch/certs/
文件夹中,并给予适当的权限,我的设置是chmod 660 /etc/elasticsearch/certs/*
- 若访问权限不足会在日志中出现
java.nio.file.AccessDeniedException:
的报错提示
- 在Elasticsearch中配置证书文件 修改配置文件
/etc/elasticsearch/elasticsearch.yml
,在文件结尾添加:
xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/uupt-elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/uupt-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
查找原因。 - 设置用户密码
- 进入
/usr/share/elasticsearch/bin/
目录执行如下命令来生成密码。./elasticsearch-setup-passwords auto
(自动生成)或./elasticsearch-setup-passwords interactive
(手动设置) 若是自动生成,过程提示如下,如报错请参考第二步。 - 该凭据是其他应用程序连接Elasticsearch的凭据,请保存好.
3.3 破解x-pack
- 相关说明 不同于手工安装的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源码 我们重点关心项目中的两个文件
- org.elasticsearch.license.LicenseVerifier.java
- org.elasticsearch.xpack.core.XPackBuild.java 两个文件文件相较于之前的版本有一定的变化,但是不影响破解过程。原始文件我就不贴了,直接给出修改后的Java文件。你可以在本地新建一个同名的Java文件并将上面给出的代码拷贝到文件中,这样你就拥有了两个修改过的x-pack程序的Java源码文件。 org.elasticsearch.license.LicenseVerifier.java
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; } } 123456789101112131415161718192021
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); } }
- 编译java程序 你需要将这两个文件编译为class文件,编译依赖的文件在命令中已经给出。 编译LicenseVerifier.java
javac -cp "/usr/share/elasticsearch/modules/x-pack-core/*:/usr/share/elasticsearch/lib/*" LicenseVerifier.java
编译XPackBuild.javajavac -cp "/usr/share/elasticsearch/modules/x-pack-core/*:/usr/share/elasticsearch/lib/*" XPackBuild.java
提示:如果编译迟迟不能结束,你可能需要将Elasticsearch关闭再重新编译即可。 编译替换的过程需要关闭Elasticsearch。 - 获取源文件 在完成编译程序之后需要将编译好的程序添加到x-pack-core-6.4.2.jar文件中,我们可以采用先解压再替换在压缩的方式构建新的jar文件。进入文件所在目录,备份文件,拷贝出来
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文件 解压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
该命令可以指定目录 - 替换class文件 将刚刚编译好的破解的class替换到相同的位置中
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包 压缩jar文件:
jar -cvf x-pack-core-6.4.2.crack.jar -C x-pack-core-6.4.2/ .
(不可忽略那个英文句号) - 替换x-pack文件 将我们生成的被破解的jar替换到Elasticsearch的目录中:
cp x-pack-core-6.4.2.crack.jar /usr/share/elasticsearch/modules/x-pack-core/x-pack-core-6.4.2.jar
另外需要注意需要替换集群中所有的x-pack-core-6.4.2.jar - 重启Elasticsearch
systemctl restart elasticsearch.service
4.升级为铂金版
4.1 申请证书
普通的证书内容如下
{ "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”
上传license.json,更新许可证
curl -XPUT -u elastic:chageme 'http://192.168.1.101:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
4.2 验证
curl -u elastic:xxxxxxxxxxx http://192.168.1.101:9200/ { "name" : "fkGwAWM", "cluster_name" : "yace-es", "cluster_uuid" : "1HvCWCwbQVaeGI9lPuE0fA", "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" }
5.安装elasticsearch-head 插件
为了便于管理ES,本文使用head插件,这是最初级的管理工具,在浏览器中显示ES集群,索引等信息,十分好用。
5.1 安装node.js:
5.2 下载head安装包
下载地址:https://github.com/mobz/elasticsearch-head/archive/master.zip
$ cd /home $ wget https://github.com/mobz/elasticsearch-head/archive/master.zip $ unzip master.zip $ mv elasticsearch-head-master elasticsearch-head
由于head 插件不能放在elasticsearch-6.4.2 文件夹里,head 插件需要单独放,单独去执行; 所以在elasticsearch-6.4.2 同级目录下解压了 head 插件;解压出来的文件名字,
5.3 安装grunt
npm install grunt --save-dev npm install npm audit fix
5.4 检查是否安装成功
$ grunt -version grunt-cli v1.3.1 grunt v1.0.1
5.5 修改head插件配置
修改配置文件,cd 进入elasticsearch-head 文件夹下,执行命令vim Gruntfile.js文件:增加hostname属性,设置为*;
$ vim Gruntfile.js ... ... 77 watch: { 78 "scripts": { 79 files: ['src/**/*', 'test/spec/*' ], 80 tasks: ['default'], 81 options: { 82 spawn: false 83 } 84 }, 85 "grunt": { 86 files: [ 'Gruntfile.js' ] 87 } 88 }, 89 90 connect: { 91 server: { 92 options: { 93 port: 9100, 94 hostname: '*', # 添加此行 95 base: '.', 96 keepalive: true 97 } 98 } 99 } 100 101 }); 102
修改 vim _site/app.js 文件:修改head的连接地址:
$ pwd /data/ES/elasticsearch-head $ vim _site/app.js 把 4354 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; 改为: 4354 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.101:9200";
在elasticsearch中启用CORS
$ vim /etc/elasticsearch/elasticsearch.yml ... ... # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true # 追加 # http.cors.enabled: true http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
5.6 运行elasticsearch-head
前台运行
$ grunt server (node:13043) ExperimentalWarning: The http2 module is an experimental API. Running "connect:server" (connect) task Waiting forever... Started connect web server on http://localhost:9100
后台运行
$ grunt server &
查看是否后台运行
$ ps -ef|grep grunt elsearch 17512 30633 1 17:26 pts/1 00:00:00 grunt elsearch 17583 30633 0 17:26 pts/1 00:00:00 grep --color=auto grunt
执行完成后就OK了
5.7 web访问elasticsearch-head
http://192.168.1.101:9100/?auth_user=elastic&auth_password=xxxxxxxxxx
文章转载请说明出处:八零岁月 » ES 6.4.2 配置安装
评论前必须登录!