一、安装ElasticSearch
环境:jdk1.8
1 上传ES的tar包到linux服务器
注意:如果以root用户解压后,需要对普通用户开放ES的执行权限
2 解压
tar -zxvf
3 进入ES 的bin目录下
cd es/bin
4启动(注意:ES不能以root 用户身份运行,确保运行用户对各使用到的目录权限)
./elasticsearch
./elasticsearch -Ecluster.name=xxx -Enode.name=yyy 指定集群名称和节点名称启动
./elasticsearch -h
5 创建新用户es并赋权
想创建的用户目录mkdir /elastics
新建用户es到指定的目录useradd es -d /elastics
设置新用户密码passwd es
将访问目录权限全部赋予用户chown -R es /elastics
用es账户启动
注:生产环境可以配置一些参数提升性能
6 在linux 虚拟机上运行可能的失败问题
内存不够用,默认es配置使用1G堆内存,如果使用的虚拟机没有这么大的内存,请在config/jvm.options中调整。(生产 2-4g)
注意:如果是centos6环境需要修改elasticsearch.yml
添加如下配置
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
另外安装时可能会报如下的错误 bootstrap checks failed
解决办法
问题一:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决:修改切换到root用户修改配置limits.conf 添加下面两行su root
命令:vi /etc/security/limits.conf
-
hard nofile 65536
-
soft nofile 65536
问题二:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解决:切换到root用户,进入limits.d目录下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
- soft nproc 1024
#修改为 - soft nproc 2048
问题三:max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决:切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
切换到es的用户。
然后,重新启动elasticsearch,即可启动成功。
注意修改networkj.host: 服务器IP
此时访问服务器的服务IP:9200
{
"name" : "h5nbwzh",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "H7HJoHF_ScS4ZXJ4dCCqzg",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"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
Kibana是ES的可视化管理工具
1 下载
https://www.elastic.co/downloads/kibana
2 解压
解压到安装目录即可
3 配置
在config/kibana.yml中配置 elasticsearch.url的值为 ES的访问地址
server.hsot=IP
4 启动
./bin/kibana
ps -ef|grep node
5 访问
访问地址:http://localhost:5601
启动报错
Error: EACCES: permission denied, open '/elastics/kibana-6.4.0-linux-x86_64/optimize/.babelcache.jso
错误的解决 将访问目录权限全部赋予用户chown -R es /elastics
三、IKAnalyzer集成
IKAnalyzer中文分词器集成
1获取 ES-IKAnalyzer插件
地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
注意:一定要获取匹配的版本 (与elasticsearch 版本匹配)
2 安装插件
将 ik 的压缩包解压到 ES安装目录的plugins/目录下(最好把解出的目录名改一下,防止安装别的插件时同名冲突),然后重启ES
建议改一下插件名ik
3 扩展词库 配置文件config/IKAnalyzer.cfg.xml
这些扩展词文件放到分词插件的config目录下(可以新建一个目录,然后配置对应路径)
<?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/mydict.dic;custom/single_word_low_freq.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">custom/ext_stopword.dic</entry>
<!--用户可以在这里配置远程扩展字典 -->
<entry key="remote_ext_dict">location</entry>
<!--用户可以在这里配置远程扩展停止词字典,配置远程访问地址-->
<entry key="remote_ext_stopwords">http://xxx.com/xxx.dic</entry>
</properties>
远程词库,可热更新,在一处地方维护
4 测试 IK
打开kibana的dev tools
(1)创建一个索引
curl -XPUT http://localhost:9200/index
(2)创建一个映射mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -H ‘Content-Type:application/json’ -d’
{
“properties”: {
“content”: {
“type”: “text”,
“analyzer”: “ik_max_word”,
“search_analyzer”: “ik_max_word”
}
}
}’
(3)索引一些文档
curl -XPOST http://localhost:9200/index/fulltext/1 -H ‘Content-Type:application/json’ -d’
{“content”:“美国留给伊拉克的是个烂摊子吗”}’
curl -XPOST http://localhost:9200/index/fulltext/2 -H ‘Content-Type:application/json’ -d’
{“content”:“公安部:各地校车将享最高路权”}’
curl -XPOST http://localhost:9200/index/fulltext/3 -H ‘Content-Type:application/json’ -d’
{“content”:“中韩渔警冲突调查:韩警平均每天扣1艘中国渔船”}’
(4)测试搜索
curl -XPOST http://localhost:9200/index/fulltext/_search -H ‘Content-Type:application/json’ -d’
{
“query” : { “match” : { “content” : “中国” }},
“highlight” : {
“pre_tags” : ["", “”],
“post_tags” : ["", “”],
“fields” : {
“content” : {}
}
}
}’