一.前置条件 java
省略java安装 ,用命令检查一下java -version
二. elasticsearch
方法一:多版本(elasticsearch-7.13.4)
-
下载官方安装包https://www.elastic.co/cn/downloads/past-releases#elasticsearch
-
解压下载的安装包
tar -zxvf elasticsearch-7.13.4-darwin-x86_64.tar.gz -
启动
./bin/elasticsearch -
浏览器输入http://127.0.0.1:9200/ 或者curl一下
elsticsearch curl
集群健康
curl -XGET 'http://localhost:9200/_cluster/health?pretty'
查看集群状态
curl -XGET "http://localhost:9200/_cat/nodes?v"
查看所有索引
curl -XGET "http://localhost:9200/_cat/indices"
方法二:默认版本(不推荐,无法指定特定版本)
1. 安装:
brew install elasticsearch #安装 默认7.10.2版本
brew install elasticsearch@7 默认7.10.2版本
brew install elasticsearch@6 #安装指定版本号6.x默认版本。不支持到具体版本
2. 查看和启动
brew info elasticsearch # 查看es信息
brew services start elasticsearch # 启动
3. 其他
brew uninstall elasticsearch # 卸载
brew uninstall --force elasticsearch
brew uninstall --force elasticsearch@6
brew upgrade elasticsearch@7
三. Kibana
-
下载zip
https://www.elastic.co/cn/downloads/past-releases#kibana -
解压
tar -zxvf kibana-7.13.4-darwin-x86_64.tar.gz -
启动
./bin/kibana -
验证
浏览器输入 http://127.0.0.1:5601/app/home#/
-
修改配置国际化为中文,默认是英文的。
kibana/config/kibana.yml
i18n.locale: "zh-CN"
- 连上服务器es集群
kibana/config/kibana.yml
#远程访问kibana地址
server.host: "0.0.0.0"
# 要用于所有查询的Elasticsearch实例的URL。可以配置多个ES
elasticsearch.hosts: ["http://localhost:9200","http://nas.**:9*"]
- 重启kibana
ps -ef|grep kibana
kill -9 ***
nohup ./bin/kibana &
ps -ef|grep kibana
8, 浏览器输入,切换为中文页面
http://127.0.0.1:5601/
四. ik分词器
-
下载zip包
注意:IK的版本一定要与elasticsearch的版本一致,否则elasticsearch无法启动。
https://github/medcl/elasticsearch-analysis-ik/releases/tag/v7.13.4 -
解压到elasticsearch的plugins
mkdir elasticsearch-7.13.4/plugins/ik
tar -zxvf elasticsearch-analysis-ik-7.13.4.zip -C elasticsearch-7.13.4/plugins/ik
-
重启es 和 kbn
./elasticsearch-7.13.4/bin/elasticsearch
./kibana-7.13.4-darwin-x86_64/bin/kibana -
验证分词器
不使用分词效果:
get /_analyze
get /_analyze
{
"text": "中华民族 Chinese nation"
}
{
"tokens" : [
{
"token" : "中",
"start_offset" : 0,
"end_offset" : 1,
"type" : "<IDEOGRAPHIC>",
"position" : 0
},
{
"token" : "华",
"start_offset" : 1,
"end_offset" : 2,
"type" : "<IDEOGRAPHIC>",
"position" : 1
},
{
"token" : "民",
"start_offset" : 2,
"end_offset" : 3,
"type" : "<IDEOGRAPHIC>",
"position" : 2
},
{
"token" : "族",
"start_offset" : 3,
"end_offset" : 4,
"type" : "<IDEOGRAPHIC>",
"position" : 3
},
{
"token" : "chinese",
"start_offset" : 5,
"end_offset" : 12,
"type" : "<ALPHANUM>",
"position" : 4
},
{
"token" : "nation",
"start_offset" : 13,
"end_offset" : 19,
"type" : "<ALPHANUM>",
"position" : 5
}
]
}
使用分词效果:
ik_smart称为智能分词,网上还有别的称呼:最少切分,最粗粒度划分。
ik_max_word称为最细粒度划分。
get /_analyze
get /_analyze
{
"analyzer":"ik_smart",
"text": "中华民族 Chinese nation"
}
{
"tokens" : [
{
"token" : "中华民族",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "chinese",
"start_offset" : 5,
"end_offset" : 12,
"type" : "ENGLISH",
"position" : 1
},
{
"token" : "nation",
"start_offset" : 13,
"end_offset" : 19,
"type" : "ENGLISH",
"position" : 2
}
]
}
get /_analyze
{
"analyzer":"ik_max_word",
"text": "中华民族 Chinese nation"
}
{
"tokens" : [
{
"token" : "中华民族",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "中华",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "民族",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "chinese",
"start_offset" : 5,
"end_offset" : 12,
"type" : "ENGLISH",
"position" : 3
},
{
"token" : "nation",
"start_offset" : 13,
"end_offset" : 19,
"type" : "ENGLISH",
"position" : 4
}
]
}
五.elasticsearch-head插件
- 需要依赖项nodejs和git
brew install node
查看是否安装成功
git --version
node -v
出现依赖缺失ca-certificates, Error: No such file or directory @ rb_sysopen *** ca-certificates-2022-03-29.all.bottle.tar.gz
brew install ca-certificates
-
下载插件并安装
https://github/mobz/elasticsearch-head.git -
zip解压
tar -zxvf elasticsearch-head-master.zip -
修改配置, 9200 和 9100有跨越问题 ,提示 http://localhost:9100/ 集群健康值: 未连接
(1)增加hostname:“*”,允许所有的域名通过.
/elasticsearch-head-master/Gruntfile.js
connect: {
server: {
options: {
hostname:"*",
port: 9100,
base: '.',
keepalive: true
}
}
}
(2)配置多个es集群.
/elasticsearch-head-master/_site/app.js
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200" || || "http://nas.***:9*";
(3)修改es的跨域配置,vim elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
-
安装到node_modules目录
cd elasticsearch-head-master
npm install -
启动服务,停止程序 执行命令注意位置,必须在有npm的package.json
npm run start
nohup npm start &
ps -ef | grep node
ps -ef | grep npm
Kill -9 * -
输入浏览器 http://localhost:9100/
(1)本地es:
(2)远端es:
更多推荐
es笔记-mac版本安装elasticsearch kbn ik elasticsearch-head
发布评论