一、文档
下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz
官网地址:https://www.elastic.co/
二、安装
1.下载并解压,添加用户
cd /data1
#解压
tar -zxf elasticsearch-7.11.1-linux-x86_64.tar.gz
##创建数据目录
cd elasticsearch-7.11.1/
mkdir data
#创建用户和用户组
groupadd es
useradd es -g es
2.修改配置文件elasticsearch.yml
vi config/elasticsearch.yml
修改以下配置
#配置elasticsearch的集群名称
cluster.name: es
#节点名
node.name: node-1
#数据存放目录
path.data: /data1/elasticsearch-7.11.1/data
#日志
path.logs: /data1/elasticsearch-7.11.1/logs
#是否开启内存锁定,避免内存与swap分区交换数据
bootstrap.memory_lock: true
#设置绑定主机的ip地址,设置为0.0.0.0表示绑定任何ip,允许外网访问,生产环境建议设置为具体的ip
network.host: 0.0.0.0
#设置对外服务的http端口,默认为9200
http.port: 9200
##设置集群中master节点的初始列表
discovery.seed_hosts: ["192.168.25.202"]
cluster.initial_master_nodes: ["node-1"]
3.设置jdk(使用es自带jdk)
修改
elasticsearch-env
,在判断JAVA_HOME的命令
f [ ! -z “$JAVA_HOME” ]; then
之前设置
JAVA_HOME
vim bin/elasticsearch-env
4.使用下列命令生成证书到config目录
cd /data1/elasticsearch-7.11.1
#执行成功config目录会多出一个elastic-certificates.p12文件
./bin/elasticsearch-certutil ca -out config/elastic-certificates.p12 -pass ""
#赋予用户访问目录权限
chown -R es:es /data1/elasticsearch-7.11.1
#切换到es用户,启动elasticsearch
su es
./bin/elasticsearch
#启动成功会自动在config目录下生成elasticsearch.keystore文件
观察日志是否启动成功,常见问题请看启动失败常见问题。
启动成功继续第四步。
三、启动失败常见问题
1、bootstrap checks failedmax virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:
切换到root用户修改配置
sysctl.conf
vi /etc/sysctl.conf
# 添加下面配置:
vm.max_map_count=655360
# 并执行命令:
sysctl -p
2、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量
ulimit -Hn
ulimit -Sn
修改
/etc/security/limits.conf
文件,增加配置,用户退出后重新登录生效
* soft nofile 65536
* hard nofile 65536
3、max number of threads [3818] for user [es] is too low, increase to at least [4096]
问题同上,最大线程个数太低。修改配置文件
/etc/security/limits.conf
(和问题1是一个文件),增加配置
* soft nproc 32000
* hard nproc 32000
可通过命令查看
ulimit -Hu
ulimit -Su
4、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改
/etc/sysctl.conf
文件,增加配置
vm.max_map_count=262144
# 执行命令sysctl -p生效
vi /etc/sysctl.conf
sysctl -p
5、Exception in thread “main” java.nio.file.AccessDeniedException:
elasticsearch用户没有该文件夹的权限,执行命令
chown -R es:es /usr/local/elasticsearch/
6,ERROR: [1] bootstrap checks failed[1]: memory locking requested for elasticsearch process but memory is not locked
修改文件
/etc/security/limits.conf
,后添加以下内容.
* hard memlock unlimited
* soft memlock unlimited
需要重启系统
四、x-pack安全配置
1.修改配置文件elasticsearch.yml
vi config/elasticsearch.yml
新增以下配置,重启es
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
#跨域设置
http.cors.enabled: true
http.cors.allow-origin: /.*/
#开启监控功能
xpack.monitoring.collection.enabled: true
2.自动生成密码
新打开一个终端,使用cd命令切换到elasticsearch目录,手动生成密码。默认会生成好几个管理员账户,其中一个叫elastic的用户是超级管理员。根据提示设置密码
cd /data1/elasticsearch-7.11.1/bin/
#手动生成密码
./elasticsearch-setup-passwords interactive
3.打开浏览器访问http://192.168.25.202:9200,就会弹出用户名密码验证框。使用超级管理员elastic登录,再输入密码即可正常访问。
五、修改ES堆内存
编辑es下config目录的jvm.options(可选调整)
-Xms4g
-Xmx4g
六、Ik分词器插件
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.11.1/elasticsearch-analysis-ik-7.11.1.zip
下载与es对应版本的中文分词器。将解压后的后的文件夹放入es根目录下的plugins目录下,重启es即可使用。
1、细粒度拆分 ik_max_word
GET http://localhost:9200/_analyze
{
"analyzer":"ik_max_word",
"text":"农业银行"
}
2、粗粒度拆分 ik_smart
GET http://localhost:9200/_analyze
{
"analyzer":"ik_smart",
"text":"农业银行"
}
3、配置扩展词典
首先进入es根目录中的
plugins
文件夹下的
ik
文件夹,进入config目录,创建
custom.dic
文件,写入弗雷尔卓德。同时打开
IKAnalyzer.cfg
文件,将新建的
custom.dic
配置其中,重启es。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">custom.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>