写在前面
本文ES版本为6.7.0
安装
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.0.tar.gz
tar -zxvf elasticsearch-6.7.0.tar.gz -C /home/
安装IK分词器
cd /home/elasticsearch-6.7.0/plugins
mkdir ik
cd ik
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.0/elasticsearch-analysis-ik-6.7.0.zip
unzip elasticsearch-analysis-ik-6.7.0.zip
配置
vi /home/elasticsearch-6.7.0/config/elasticsearch.yml
## 增加以下配置:
network.host: 本机ip
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
indices.fielddata.cache.size: 2gb
配置系统参数
vi /etc/sysctl.conf
# 添加内容如下:
vm.max_map_count=262144
vi /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
配置生效
/sbin/sysctl -p
创建组
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch
chown -R elsearch:elsearch /home/elasticsearch-6.7.0
启动
su elsearch
cd /home/elasticsearch-6.7.0/bin
nohup ./elasticsearch &
查看启动日志
tail -f nohup.out
x-pack破解
找到elasticsearch-6.7.0\modules\x-pack\x-pack-core\x-pack-core-6.3.1.jar,替换为xpackcore6.7.0.jar
jar包主要修改这几个地方
1.“type”:“basic” 替换为 “type”:"platinum" # 基础版变更为铂金版
2.“expiry_date_in_millis”:1561420799999 替换为 “expiry_date_in_millis”:3107746200000# 1年变为50年
初始安装需要重置密码:
bin/elasticsearch-setup-passwords interactive
正常情况下
选择y会让你设置账户密码:
表示密码都设置成功了。
执行查询请求
curl -u elastic:123456 -XGET "http://10.199.136.12:9200/_cat/health?v"
报错1
Unexpected response code [403] from calling GET http://10.199.136.12: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.
解决:执行下面命令
curl -XPUT -u elastic 'http://10.199.136.12:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
报错2
{"error":{"root_cause":[{"type":"illegal_state_exception","reason":"Cannot install a [PLATINUM] license unless TLS is configured or security is disabled"}],"type":"illegal_state_exception","reason":"Cannot install a [PLATINUM] license unless TLS is configured or security is disabled"},"status":500}
解决
vi /home/elasticsearch-6.7.0/config/elasticsearch.yml
# 增加以下配置:
xpack.security.enabled: false
报错3
Unexpected response code [404] from calling GET http://10.199.136.12:9200/_xpack/security/_authenticate?pretty
It doesn't look like the X-Pack security feature is enabled on this Elasticsearch node.
Please check if you have enabled X-Pack security in your elasticsearch.yml configuration file.
ERROR: X-Pack Security is disabled by configuration.
解决
vi /home/elasticsearch-6.7.0/config/elasticsearch.yml
# 增加以下配置:
xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
报错4
ERROR: [1] bootstrap checks failed
[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]
解决
vi /home/elasticsearch-6.7.0/config/elasticsearch.yml
#增加以下配置:
xpack.security.transport.ssl.enabled: true
报错5
使用java去连接的时候报一下错误。
unknown setting [xpack.security.user] please check that any required plugins
解决:
pom中需要引入
<!-- add the elasticsearch repo -->
<repository>
<id>elasticsearch-releases</id>
<url>https://artifacts.elastic.co/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>5.6.1</version>
</dependency>
java中使用:
client = new PreBuiltXPackTransportClient(settings);
创建角色
curl -XPOST -u elastic 'http://10.199.136.12:9200/_security/role/events_admin' -H "Content-Type: application/json" -d '{ "indices" : [ { "names" : [ "events*" ], "privileges" : [ "all" ] }, { "names" : [ ".kibana*" ], "privileges" : [ "manage", "read", "index" ] } ] }'
创建用户
curl -XPOST -u elastic 'http://10.199.136.12:9200/_security/user/edu' -H "Content-Type: application/json" -d '{ "password" : "edu", "full_name" : "edu", "email" : "", "roles" : [ "events_admin" ] }'
本文为博主原创文章,未经博主允许不得转载。
更多内容请访问:IT源点
注意:本文归作者所有,未经作者允许,不得转载