目录(centos)
elasticsearch
java环境配置网上自己找文档
# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
下载 elasticsearch
analysis-ik的最新只适用6.7.0所以这边elasticsearch只安装6.7.0版本
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.0.rpm
安装 elasticsearch
# rpm -ivh elasticsearch-6.7.0.rpm
设置开机启动
# systemctl daemon-reload
# systemctl enable elasticsearch.service
# systemctl start elasticsearch
配置文件
# vim /etc/elasticsearch/elasticsearch.yml
//外网可访问
network.host: 0.0.0.0
//访问端口
http.port: 9200
检测端口占用情况 netstat -plntu
如果半天没启动起来有可能是内存不够出错,改成512m
# vim /etc/elasticsearch/jvm.options
-Xms512m
-Xmx512m
//保存重启
#systemctl restart elasticsearch
查看状态
curl '127.0.0.1:9200'
说明已经安装成功
analysis-ik
elasticsearch自带分词效果
# curl -H 'Content-Type: application/json' -XGET '127.0.0.1:9200/_analyze?pretty' -d '{"text":"我是中国人"}'
analysis-ik 分词效果
# curl -H 'Content-Type: application/json' -XGET '127.0.0.1:9200/_analyze?pretty' -d '{"analyzer":"ik_max_word","text":"我是中国人"}'
安装 ik-analyzer
# /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.0/elasticsearch-analysis-ik-6.7.0.zip
//重启elasticsearch
#systemctl restart elasticsearch
自定义词库
添加自定义字典文件
vim /etc/elasticsearch/analysis-ik/IKAnalyzer.cfg.xml
添加字典
echo '我是' > /etc/elasticsearch/analysis-ik/diy.dic
//保存重启
systemctl restart elasticsearch
elasticsearch-head
安装
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
修改配置文件
vim _site/app.js
# 修改 『http://localhost:9200』字段到本机ES端口与IP
修改elasticsearch支持跨域访问并重启
vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true #最下方添加
http.cors.allow-origin: "*"
systemctl restart elasticsearch