编辑
2025-06-25
笔记
0

目录

安装 Elastic Stack
建立中文索引
开放外网访问
遇到的问题

安装 Elastic Stack

CenOS 7

shell
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch # ES 7 cat << EOF > /etc/yum.repos.d/elasticsearch.repo [elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOF # ES 8 cat << EOF > /etc/yum.repos.d/elasticsearch.repo [elasticsearch] name=Elasticsearch repository for 8.x packages baseurl=https://mirrors.tuna.tsinghua.edu.cn/elasticstack/8.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOF yum install -y elasticsearch kibana logstash systemctl daemon-reload systemctl enable elasticsearch.service systemctl enable kibana.service systemctl enable logstash.service

Ubuntu

shell
sudo apt install apt-transport-https wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - # ES 7 echo "deb https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list # ES 8 echo "deb https://mirrors.tuna.tsinghua.edu.cn/elasticstack/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list sudo apt update && sudo apt install -y elasticsearch kibana logstash systemctl daemon-reload systemctl enable elasticsearch.service systemctl enable kibana.service systemctl enable logstash.service

建立中文索引

IK Analysis for Elasticsearch

shell
ES_VERSION=7.6.1 JAVA_HOME=/usr/share/elasticsearch/jdk/ \ /usr/share/elasticsearch/bin/elasticsearch-plugin install \ https://get.infini.cloud/elasticsearch/analysis-ik/$ES_VERSION
  • 建立 mapping 的时候, 增加 analyzer 属性 IK分词器(ik_max_word / ik_smart)
    • ik_max_word :会将文本做最细粒度的拆分
    • ik_smart :会将文本做最粗粒度的拆分

Pinyin Analysis for Elasticsearch

shell
ES_VERSION=7.6.1 JAVA_HOME=/usr/share/elasticsearch/jdk/ \ /usr/share/elasticsearch/bin/elasticsearch-plugin install \ https://get.infini.cloud/elasticsearch/analysis-pinyin/$ES_VERSION

开放外网访问

shell
cat << EOF >> /etc/elasticsearch/elasticsearch.yml network.host: 0.0.0.0 http.port: 9200 discovery.type: single-node EOF systemctl restart elasticsearch.service

遇到的问题

"Validation Failed: 1: this action would add [2] shards, but this cluster currently has [1903]/[1000] maximum normal shards open;"

shell
cat << EOF >> /etc/elasticsearch/elasticsearch.yml cluster.max_shards_per_node: 10000 EOF systemctl restart elasticsearch.service

Error enabling rule: could not create API key - feature_not_enabled_exception: [feature_not_enabled_exception] Reason: api keys are not enabled

bash
cat << EOF >> /etc/elasticsearch/elasticsearch.yml xpack.security.authc.api_key.enabled: true EOF systemctl restart elasticsearch.service
bash
/usr/share/kibana/bin/kibana-encryption-keys generate cat << EOF >> /etc/kibana/kibana.yml xpack.encryptedSavedObjects.encryptionKey: b9d7e558c8e03ca80e698384189d4751 xpack.reporting.encryptionKey: ca8c1a3551bfba02cf0ffd3dbb0df52b xpack.security.encryptionKey: d0b8fe87528c2da203ac402bf7d6308c EOF systemctl restart kibana.service

本文作者:菜鸟

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 许可协议。转载请注明出处!