http://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202005%2F08%2F20200508102713_L8aCB.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1649077062&t=40b7b14053ef546a57de4934b9442cbe",

Mac OS安装elasticsearch

一、安装 elasticsearch(单机版)

下载地址:https://www.elastic.co/cn/downloads/elasticsearch
指定版本:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-8-12-2

## 下载 安装包到 /Users/cookie./devtools
## 解压
cd /Users/cookie./devtools
tar -xvzf  elasticsearch-8.12.2-darwin-x86_64.tar.gz

## 修改配置文件
cd elasticsearch-8.12.2/config
cp elasticsearch.yml elasticsearch.yml.bak
vi elasticsearch.yml

## 修改如下内容(注意! 注意:下面的内容需要启动服务器后才会自动生成。)
xpack.security.enabled: false
xpack.security.http.ssl:
  enabled: false

:wq

## 添加快速启停命令
vi ~/.zshrc

## 追加如下内容
alias sa-elasticsearch=" nohup /Users/cookie./devtools/elasticsearch-8.12.2/bin/elasticsearch -d &"
alias st-elasticsearch="ps -ef | grep elasticsearch | grep -v grep | awk '{print $2}' | xargs kill -9"

:wq
source ~/.zshrc

## 启动服务
sa-elasticsearch
tail -f /Users/cookie./devtools/elasticsearch-8.12.2/logs/elasticsearch.log 

## 访问地址
http://127.0.0.1:9200/

二、安装 Kibana

下载地址:https://www.elastic.co/cn/downloads/past-releases/kibana-8-12-2

## 下载安装包 kibana-8.12.2-darwin-x86_64.tar.gz 到 /Users/cookie./devtools

## 解压
cd /Users/cookie./devtools
tar -xvzf kibana-8.12.2-darwin-x86_64.tar.gz

## 修改配置文件
cp kibana-8.12.2/config/kibana.yml kibana-8.12.2/config/kibana.yml.bak

vi

## 修改如下内容(放开注释即可)
elasticsearch.hosts: ["http://localhost:9200"]
## 汉化配置 : 后的空格不能少,不然启动报错:FATAL CLI ERROR YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 143, column 1:
i18n.locale: "zh-CN"

:wq

## 添加快速启停命令
vi ~/.zshrc

## 追加如下内容
alias sa-kibana="nohup /Users/cookie./devtools/kibana-8.12.2/bin/kibana > /Users/cookie./devtools/kibana-8.12.2/logs/kibana.log &"
alias st-kibana="ps -ef | grep kibana | grep -v grep | awk '{print $2}' | xargs kill -9"

:wq
source ~/.zshrc

## 启动服务
sa-kibana 
tail -f /Users/cookie./devtools/kibana-8.12.2/logs/kibana.log

## 访问地址
http://localhost:5601

三、安装 ik 分词器

下载地址:https://github.com/infinilabs/analysis-ik/releases

# 下载 elasticsearch-analysis-ik-8.12.2.zip 。要与 elasticsearch 版本保持一致

# 解压
mkdir -p /Users/cookie./devtools/elasticsearch-8.12.2/plugins/ik
unzip -d /Users/cookie./devtools/elasticsearch-8.12.2/plugins/ik  elasticsearch-analysis-ik-8.12.2.zip

# 重启 elasticsearch 服务
st-elasticsearch
sa-elasticsearch && tail -f /Users/cookie./devtools/elasticsearch-8.12.2/logs/elasticsearch.log 

## 日志中看到  loaded plugin [analysis-ik]  说明安装成功。

## kibana 测试分词器
GET _analyze
{
  "analyzer": "ik_smart",
  "text": "中华人民共和国万岁"
}

GET _analyze
{
  "analyzer": "ik_max_word",
  "text": "中华人民共和国万岁"
}

# 与ES版本不一致报错
# Plugin [analysis-ik] was built for Elasticsearch version 8.12.2 but version 8.13.3 is running

自定义 ik 词库

## 1. 新增词库文件
vi /Users/cookie./devtools/elasticsearch-8.12.2/plugins/ik/config/custom.dic

# 添加 
沸羊羊

:wq

## 2. 配置词库文件
vi /Users/cookie./devtools/elasticsearch-8.12.2/plugins/ik/config/IKAnalyzer.cfg.xml

# 修改配置,原配置为:<entry key="ext_dict"></entry>
<entry key="ext_dict">custom.dic</entry>

## 3. 重启ES服务

四、安装 拼音 分词器

## 下载拼音插件:elasticsearch-analysis-pinyin-8.12.2.zip
https://github.com/medcl/elasticsearch-analysis-pinyin
https://github.com/infinilabs/analysis-pinyin/releases

# 解压
mkdir -p /Users/cookie./devtools/elasticsearch-8.12.2/plugins/py
unzip -d /Users/cookie./devtools/elasticsearch-8.12.2/plugins/py  elasticsearch-analysis-pinyin-8.12.2.zip

# 重启 elasticsearch 服务
st-elasticsearch
sa-elasticsearch && tail -f /Users/cookie./devtools/elasticsearch-8.12.2/logs/elasticsearch.log 

## 日志中看到  loaded plugin [analysis-pinyin]  说明安装成功。


五、Q&A

5.1、启动报错:warning: ignoring JAVA_HOME=/Users/cookie/devtools/jdk-17.0.11.jdk/Contents/Home; using bundled JDK

参考:https://blog.csdn.net/m0_73656761/article/details/135729405

posted @ 2024-05-08 08:33  DeepInThought  阅读(850)  评论(0编辑  收藏  举报