## **Head插件安装**
**1. Head插件简介**
ElasticSearch-head是一个H5编写的ElasticSearch集群操作和管理工具,可以对集群进行傻瓜式操作。
* 显示集群的拓扑,并且能够执行索引和节点级别操作
* 搜索接口能够查询集群中原始json或表格格式的检索数据
* 能够快速访问并显示集群的状态
* 有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果;
* 5.0版本之前可以通过plugin名安装,5.0之后可以独立运行。
**2. Head插件安装**
(1)安装NodeJS
```
[root@cyj ~]# yum install -y nodejs
```
(2)安装npm
```
[root@cyj~]# npm install -g cnpm --registry=https://registry.npm.taobao.org
```
(3)使用npm安装grunt
```
[root@cyj~]# npm install -g grunt
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN gentlyRm not removing /usr/bin/grunt as it wasn't installed by /usr/lib/node_modules/grunt
/usr/bin/grunt -> /usr/lib/node_modules/grunt/bin/grunt
/usr/lib
└── grunt@1.0.1
[root@cyj ~]#
[root@cyj ~]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
/usr/bin/grunt -> /usr/lib/node_modules/grunt-cli/bin/grunt
/usr/lib
└─┬ grunt-cli@1.2.0
├─┬ findup-sync@0.3.0
│ └─┬ glob@5.0.15
│ ├─┬ inflight@1.0.6
│ │ └── wrappy@1.0.2
│ ├── inherits@2.0.3
│ ├─┬ minimatch@3.0.4
│ │ └─┬ brace-expansion@1.1.8
│ │ ├── balanced-match@1.0.0
│ │ └── concat-map@0.0.1
│ ├── once@1.4.0
│ └── path-is-absolute@1.0.1
├── grunt-known-options@1.1.0
├─┬ nopt@3.0.6
│ └── abbrev@1.1.1
└── resolve@1.1.7
[root@cyj ~]#
```
(4)版本确认
```
[es@cyj ~]$ node -v
v6.12.0
[es@cyj ~]$ npm -v
3.10.10
[es@cyj ~]$ grunt -version
grunt-cli v1.2.0
[es@cyj ~]$
```
(5)下载head插件源码
```
[es@cyj ~]$ git clone git://github.com/mobz/elasticsearch-head.git
[es@cyj ~]$ cd elasticsearch-head
[es@cyj ~]$ npm install
[es@cyj ~]$ npm run start
```
**3. 配置elasticsearch**
(1)配置 ElasticSearch,使得HTTP对外提供服务
```
[es@cyj elasticsearch-6.4.2]$ vi config/elasticsearch.yml
```
添加如下内容
```
# 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格
http.cors.enabled: true
http.cors.allow-origin: "*"
```
## **Kibana插件**
(1) 下载kibana插件
https://www.elastic.co/downloads/kibana
![](https://box.kancloud.cn/0a039fe4cfbe3b1f96b1d10b05650813_1181x947.png)
注意,ElasticSearch版本是6.4.2,kibana的版本必须对应,所以,此处下载kibana-6.4.2-linux-x86_64.tar.gz
```
[es@cyj ~]$ wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.2-linux-x86_64.tar.gz
--2018-01-06 04:30:47-- https://artifacts.elastic.co/downloads/kibana/kibana-6.4.2-linux-x86_64.tar.gz
Resolving artifacts.elastic.co (artifacts.elastic.co)... 184.73.156.41, 54.235.82.130, 184.72.218.26, ...
Connecting to artifacts.elastic.co (artifacts.elastic.co)|184.73.156.41|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 65947685 (63M) [application/x-gzip]
Saving to: ‘kibana-6.1.1-linux-x86_64.tar.gz’
100%[============================================================================================>] 65,947,685 190KB/s in 16m 34s
2018-01-06 04:47:24 (64.8 KB/s) - ‘kibana-6.4.2-linux-x86_64.tar.gz’ saved [65947685/65947685]
[es@node1 ~]$
```
(2) 解压
```
[es@cyj ~]$ tar -zxvf kibana-6.4.2-linux-x86_64.tar.gz
[es@node1 ~]$ cd kibana-6.4.2-linux-x86_64
[es@node1 kibana-6.4.2-linux-x86_64]$
```
(3) 修改配置
修改kibana配置文件kibana.yml
需要修改的主要有三处
```
#设置kibana监听的端口
server.port: 5601
#设置kibana的地址
server.host: xxxx.xxxx.xxxx.xxxx
#设置elastcisearch的地址端口
elasticsearch.url: "http://xxxx.xxxx.xxxx.xxxx:9200"
```
(4) 启动kibana
```
[root@cyj kibana-6.4.2-linux-x86_64]# ./bin/kibana
```
(5) 浏览器访问http://xxxx.xxxx.xxxx.xxxx:5601
![](https://box.kancloud.cn/0b5f368e8579be746301434e57a391e9_1895x970.png)
## **IK分词器插件**
(1) 源码
https://github.com/medcl/elasticsearch-analysis-ik
![](https://box.kancloud.cn/446ff6916416f7f684842e06d4c1eff5_1127x988.png)
(2) releases
https://github.com/medcl/elasticsearch-analysis-ik/releases
请下载对应elasticsearch版本的ik分词器
![](https://box.kancloud.cn/b21d9b33e4477532f30429f3ccf0a27f_1212x965.png)
(3) 安装插件
```
[root@cyj elasticsearch]# ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.1/elasticsearch-analysis-ik-6.4.1.zip
[root@cyj elasticsearch]# ll plugins/
total 4
drwxr-xr-x 2 root root 4096 Sep 20 17:16 analysis-ik
[root@cyj elasticsearch]#
```
(4) 测试IK中文分词器的基本功能
* **ik_smart**
其中pretty本意”漂亮的”,表示以美观的形式打印出JSON格式响应。
```
GET _analyze?pretty
{
"analyzer": "ik_smart",
"text":"安徽省长江流域"
}
```
分词结果:
```
{
"tokens": [
{
"token": "安徽省",
"start_offset": 0,
"end_offset": 3,
"type": "CN_WORD",
"position": 0
},
{
"token": "长江流域",
"start_offset": 3,
"end_offset": 7,
"type": "CN_WORD",
"position": 1
}
]
}
```
* **ik_max_word**
```
GET _analyze?pretty
{
"analyzer": "ik_max_word",
"text": "安徽省长江流域"
}
```
分词结果:
```
{
"tokens": [
{
"token": "安徽省",
"start_offset": 0,
"end_offset": 3,
"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": "长江流域",
"start_offset": 3,
"end_offset": 7,
"type": "CN_WORD",
"position": 3
},
{
"token": "长江",
"start_offset": 3,
"end_offset": 5,
"type": "CN_WORD",
"position": 4
},
{
"token": "江流",
"start_offset": 4,
"end_offset": 6,
"type": "CN_WORD",
"position": 5
},
{
"token": "流域",
"start_offset": 5,
"end_offset": 7,
"type": "CN_WORD",
"position": 6
}
]
}
```