Elasticsearch 搭建
window环境
版本
- elasticsearch-7.2.0-windows-x86_64.zip
- kibana-7.2.0-windows-x86_64.zip
- jdk1.8
下载地址:https://www.elastic.co/cn/downloads/
elasticsearch部署
需要jdk1.8以上的运行环境
解压缩elasticsearch-7.2.0-windows-x86_64.zip
[外链图片转存失败(img-tPtHIsZD-1564469476387)(G:\document\picture\1564207020097.png)]
文件夹说明:
[外链图片转存失败(img-NCeWzVId-1564469476388)(G:\document\picture\1564367043394.png)]
配置文件
es使用zip,tar安装,配置文件在config下
rpm安装,配置文件在/etc/elasticsearch下
mis安装,配置文件在config下,且会自动将config目录地址写入环境变量ES_PATH_CONF
[外链图片转存失败(img-TkwvXIC7-1564469476388)(G:\document\picture\1564367241594.png)]
对于elasticsearch.yml:
配置格式是YAML 有如下两种
path:
data: /var/lib/es
logs: /var/log/es
和
path.data: /var/lib/es
path.logs: /var/log/es
例如:
cluster.name: elasticsearch # 配置es的集群名称,默认是elasticsearch
node.name: node-1 # 节点名,一台物理服务器就是一个节点,一个或多个节点组成一个cluster集群,集群是一个逻辑概念,节点是物理概念
network.host: 0.0.0.0 # 设置绑定主机的ip地址,设置为0.0.0.0表示绑定任何ip,允许外网访问,生产环境建议设置为具体的ip
http.port: 9200 # 设置对外服务的http端口,默认9200
transport.tcp.port: 9300 # 集群节点之间通信端口
node.master: true # 指定该节点是否有资格被选举成为master节点,默认是true,若原来的master宕机会重新选举新的
node.data: true # 指定该节点是否存储索引数据,默认true
#discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301", "0.0.0.0:9302"] # 设置集群中master节点的初始列表
discovery.zen.minimum_master_nodes: 1 # 主节点数量的最小值,公式为(master_eligible_nodes/2) + 1 若有3个符合要求的主节点,此处设置2
bootstrap.memory_lock: false # 设置为true可以锁住es使用的内存,避免内存与swap分区交换数据
node.max_local_storage_nodes: 1 # 单机允许的最大存储节点数,通常单机启动一个节点设置1,开发环境单机启动多个节点设置大于1
# discovery.zen.ping.timeout: 3s 设置ES自动发现节点连接超时的时间,默认为3秒,如果网络延迟高可设置大些。
path.data: G:\serverTool\elasticsearch-6.8.1\data # 设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开。
path.logs: G:\serverTool\elasticsearch-6.8.1\logs # 设置日志文件的存储路径,默认是es根目录下的logs文件夹
http.cors.enabled: true
http.cors.allow‐origin: /.*/
jvm.options:设置最小及最大的JVM堆内存大小
在jvm.options中设置-Xms和-Xmx
1.两值相等
2.将Xmx设置为不超过物理内存的一半
log4j2.properties
日志文件设置,es使用log4j
elasticsearch-6.8.1\bin\elasticsearch.bat 启动
访问http://localhost:9200/ 显示如下启动成功
{
"name" : "BJzMIbc",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "IACBwwtwQyCOHqL8b9fwJQ",
"version" : {
"number" : "6.8.1",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "1fad4e1",
"build_date" : "2019-06-18T13:16:52.517138Z",
"build_snapshot" : false,
"lucene_version" : "7.7.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
设置中文分词器ik
[外链图片转存失败(img-6kqm6XnA-1564469476388)(G:\document\picture\1564371870644.png)]
github下载ik分词器https://github.com/medcl/elasticsearch-analysis-ik/releases
解压缩到plugins下的ik目录下
[外链图片转存失败(img-wnzxV2io-1564469476389)(G:\document\picture\1564372474690.png)]
重启es
ik有两种analyzer
ik_max_word: 会将文本做最细粒度的拆分,如浮点数 分为浮点数,浮点,点数
ik_smart: 会做最粗粒度的拆分 如浮点数 分为浮点数
[外链图片转存失败(img-ndDQOiuq-1564469476390)(G:\document\picture\1564372521727.png)]
自定义词库
需要分词器支持专有词语,可以自定义词库
ik的词库文件为config下的main.dic
[外链图片转存失败(img-c8OhFhBW-1564469476390)(G:\document\picture\1564372948541.png)]
在config下新建.dic文件,文件格式为utf-8
其中自定义词汇
然后在配置文件IKAnalyzer.cfg.xml中配置自己新建的.dic
<?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">自定义字典.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>