Elasticsearch 6.4的安装配置
CentOS 7.2,预装Java8,注意软链ln -s /usr/java/jdk1.8.0_192/bin/java /usr/bin/java
。
安装6.4.0版本
# 获取rpm包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.rpm
# 安装
rpm -ivh elasticsearch-6.4.0.rpm
一般是装在/usr/share/elasticsearch/下。
配置
设置data的目录
# 创建/data/es-data目录,用于elasticsearch数据的存放
mkdir -p /data/es-data
# 修改该目录的拥有者为elasticsearch
chown -R elasticsearch:elasticsearch /data/es-data
设置log的目录
# 创建/data/es-log目录,用于elasticsearch日志的存放
mkdir -p /log/es-log
# 修改该目录的拥有者为elasticsearch
chown -R elasticsearch:elasticsearch /log/es-log
修改配置文件/etc/elasticsearch/elasticsearch.yml
#设置data存放的路径为/data/es-data
path.data: /data/es-data
#设置logs日志的路径为/log/es-log
path.logs: /log/es-log
#设置内存不使用交换分区
bootstrap.memory_lock: false
#配置了bootstrap.memory_lock为true时反而会引发9200不会被监听,原因不明
#设置允许所有ip可以连接该elasticsearch
network.host: 0.0.0.0
#开启监听的端口为7700
http.port: 7700
#增加新的参数,为了让elasticsearch-head插件可以访问es (5.x版本,如果没有可以自己手动加)
#http.cors.enabled: true
#http.cors.allow-origin: "*"
启动elasticsearch
# 启动
systemctl start elasticsearch
# 查看状态
systemctl status elasticsearch
# 设置开机启动
systemctl enable elasticsearch
参考:https://www.cnblogs.com/straycats/p/8053937.html
如果要用supervisor启动,要用非root用户执行,supervisor的配置如下:
[program:elasticsearch]
command=/usr/bin/sh ./elasticsearch
directory=/usr/share/elasticsearch/bin
user=elasticsearch
redirect_stderr=true
autorestart=true
stdout_logfile=/var/log/elasticsearch.out.log
参考:https://www.cnblogs.com/ENU7/p/9545366.html
分词插件
IK Analyzer是一个开源的,基于Java语言开发的轻量级的中文分词工具包。当安装完Elasticsearch之后,默认已经含有一个分词法,就是standard,这个分词法对英文的支持还可以,但是对中文的支持非常差劲。
curl http://localhost:7700/_analyze -X POST -H "Content-Type:application/json" -d '{"analyzer": "whitespace","text":"hello world,你好"}' -v
返回:
{
"tokens": [{
"token": "hello",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
}, {
"token": "world",
"start_offset": 6,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 1
}, {
"token": "你",
"start_offset": 12,
"end_offset": 13,
"type": "<IDEOGRAPHIC>",
"position": 2
}, {
"token": "好",
"start_offset": 13,
"end_offset": 14,
"type": "<IDEOGRAPHIC>",
"position": 3
}]
}
注意选对对应ES的analysis-ik的版本:https://github.com/medcl/elasticsearch-analysis-ik
# 安装插件
/usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
# 重启
systemctl restart elasticsearch
# 测试
curl http://localhost:7700/_analyze -X POST -H "Content-Type:application/json" -d '{"analyzer": "ik_max_word","text":"hello world,你好"}' -v
返回
{
"tokens": [{
"token": "hello",
"start_offset": 0,
"end_offset": 5,
"type": "ENGLISH",
"position": 0
}, {
"token": "world",
"start_offset": 6,
"end_offset": 11,
"type": "ENGLISH",
"position": 1
}, {
"token": "你好",
"start_offset": 12,
"end_offset": 14,
"type": "CN_WORD",
"position": 2
}]
}
参考: