# ElasticSearch 7.7.0(单机版)+ Ik 分词器 + ES-head 可视化插件

**ElasticSearch 7.7.0(单机版)+ Ik 分词器 + ES-head 可视化插件。**

### ElasticSearch 7.7.0

```bash
docker pull elasticsearch:7.7.0
docker run -d --name es -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -it elasticsearch:7.7.0


- discovery.type=single-node ：单机运行


# 如果启动不起来，设置一下 ·虚拟内存区域的数量·
grep vm.max_map_count /etc/sysctl.conf 
vm.max_map_count=262144
```

**浏览器访问: <http://10.10.194.244:9200>**

```bash
{
  "name" : "b25918c3dce6",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "vW2zNEKERoe2rENiSI3oXQ",
  "version" : {
    "number" : "7.7.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
    "build_date" : "2020-05-12T02:01:37.602180Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
```

### Ik 分词器插件

* ElasticSearch 中的分词器会把中文分为一个一个的字， 所以需要 安装中文分词器IK来解决这个问题。
* IK提供了两个分词算法：ik\_smart和ik\_max\_word，其中ik\_smart为最少切分，ik\_max\_word为最细力度

```bash
docker exec -it es bash     # 进入 ElasticSearch 容器
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.7.0/elasticsearch-analysis-ik-7.7.0.zip
docker restart es          # 最后再重启一下
```

### 安装 es-head 可视化插件

> Github: <https://github.com/mobz/elasticsearch-head/>

```bash
docker pull mobz/elasticsearch-head:5
docker run -d --name es-head -p 9100:9100 mobz/elasticsearch-head:5
```

**解决跨域**

> 因为前后端分离开发，存在跨域问题，需要在服务端做 CORS 的配置

```bash
docker exec -it es /bin/bash

[root@7f213e9fb6bb elasticsearch]# vi config/elasticsearch.yml


# 添加如下两条配置，注意冒号后面有空格，保存并退出。
# 注意在生产环境不要打开这些设置，否则存在安全隐患
http.cors.enabled: true 
http.cors.allow-origin: "*"


# 再重启
docker restart es
```

![](C:%5CUsers%5CAdministrator.DESKTOP-UK43ECI%5CAppData%5CRoaming%5Cmarktext%5Cimages%5C2023-04-11-19-48-09-image.png)

### 集群健康值的几种状态解释

**集群健康值颜色 解释**

* 绿色 最健康的状态，代表所有的分片包括备份都可用
* 黄色 基本的分片可用，但是备份不可用（也可能是没有备份）
* 红色 部分的分片可用，表明分片有一部分损坏。此时执行查询部分数据仍然可以查到，遇到这种情况，还是赶快解决比较好
* 灰色 未连接到elasticsearch服务

### 安装 Kibana

```bash
docker pull kibana:7.7.0

# 单独启动
docker run -d --name kb  -p 宿主机端口:5601 kibana:7.7.0


# 链接 ES 
docker run -d --name kba -e ELASTICSEARCH_HOSTS=http://10.10.194.244:9200  kibana:7.7.0
or
docker run -d --name 容器名  -p 宿主机端口:5601 -v ./config:/usr/share/kibana/config kibana:7.7.0



## config 配置文件，定义 es 链接, 6.7以后系统开始支持中文了，修改语言只需要添加一行配置即可。
i18n.locale: "zh-CN"
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://10.10.194.244:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/es/elasticsearch-7.7.0-dan-ji-ban-+-ik-fen-ci-qi-+-eshead-ke-shi-hua-cha-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
