一、安装 ElasticSearch
1.1 安装 ES
text
// 待补充
// aHR0cHM6Ly93d3cuYmlsaWJpbGkuY29tL3ZpZGVvL0JWMWI4NDExWjd3NT9zcG1faWRfZnJvbT0zMzMuNzg4LnBsYXllci5zd2l0Y2gmdmRfc291cmNlPTIwNWQxYTUyYzhmMmRlMDQ0MDM2ODk0OTEzZGQ3MzhjJnA9NQ==
1.2 创建自定义用户:
shell
# 进入 ES 容器
docker exec -it es bash
# 创建用户
bin/elasticsearch-users useradd 用户名
# 角色赋权
bin/elasticsearch-users roles -a superuser 用户名
bin/elasticsearch-users roles -a kibana_system 用户名
1.3 安装中文分词器
1.3.1 ik 分词器 Github地址:https://github.com/infinilabs/analysis-ik
shell
# 进入 ES 容器
docker exec -it es bash
# 安装
bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.16.0 # ik版本需与elasticsearch 版本好一致
1.3.2 ik 分词器没有与当前 ES一样的版本,怎么办?
ik 安装包地址:https://release.infinilabs.com/analysis-ik/stable/
shell
# 下载安装包: elasticsearch-analysis-ik-8.15.3.zip
# 解压并重新命令为:analysis-ik
# 上传到 ES 容器 plugins 目录下
cd plugins/analysis-ik
vim plugin-descriptor.properties
# 修改版本:保持与 ES 版本一致
version=8.16.0
elasticsearch.version=8.16.0
# 重启 ES
1.3.3 测试
使用 Kibana 的 DevTools 中测试 ik_smart:
shell
POST /_analyze
{
"text":"我是一名go和php程序猿",
"analyzer":"ik_smart"
}
结果:
shell
{"tokens":[{"token":"我","start_offset":0,"end_offset":1,"type":"CN_CHAR","position":0},{"token":"是","start_offset":1,"end_offset":2,"type":"CN_CHAR","position":1},{"token":"一名","start_offset":2,"end_offset":4,"type":"CN_WORD","position":2},{"token":"go","start_offset":4,"end_offset":6,"type":"ENGLISH","position":3},{"token":"和","start_offset":6,"end_offset":7,"type":"CN_CHAR","position":4},{"token":"php","start_offset":7,"end_offset":10,"type":"ENGLISH","position":5},{"token":"程序","start_offset":10,"end_offset":12,"type":"CN_WORD","position":6},{"token":"猿","start_offset":12,"end_offset":13,"type":"CN_CHAR","position":7}]}
二、安装 Kibana
2.1 安装 Kibana(Windows版)
1、下载地址:https://www.elastic.co/cn/downloads/kibana
2、修改配置:
shell
cd D:\kibana-8.15.3\config # 根据实际安装目录修改
vim kibana.yml
# 修改配置信息
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://ip:9200"]
elasticsearch.username: "jason" # 不可以是 elastic
elasticsearch.password: "123456"
三、 问题汇总
Q:FATAL Error: [config validation of [elasticsearch].username]: value of "elastic" is forbidden. This is a superuser account that cannot write to system indices that Kibana needs to function. Use a service account token instead.
A:界面会显示:Kibana server is not ready yet,这是因为 es 不允许使用 elastic 用户登录 kibana,参考 "安装 ElasticSearch->创建自定义用户"