1. 程式人生 > >ElasticSearch 6.x 學習筆記:2.head外掛

ElasticSearch 6.x 學習筆記:2.head外掛

2.1 Head外掛簡介

ElasticSearch-head是一個H5編寫的ElasticSearch叢集操作和管理工具,可以對叢集進行傻瓜式操作。

  • 顯示叢集的拓撲,並且能夠執行索引和節點級別操作
  • 搜尋介面能夠查詢叢集中原始json或表格格式的檢索資料
  • 能夠快速訪問並顯示叢集的狀態
  • 有一個輸入視窗,允許任意呼叫RESTful API。這個介面包含幾個選項,可以組合在一起以產生有趣的結果;
  • 5.0版本之前可以通過plugin名安裝,5.0之後可以獨立執行。

2.2 Head外掛安裝

(1)安裝NodeJS

[root@node1 ~]# yum install -y nodejs

(2)安裝npm

[root@node1 ~]#  npm install -g cnpm --registry=https://registry.npm.taobao.org

(3)使用npm安裝grunt

[[email protected] ~]# 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 └── [email protected]1.0.1 [[email protected] ~]#
[root@node1 ~]# 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@node1 ~]#

(4)版本確認

[es@node1 ~]$ node -v
v6.12.0
[es@node1 ~]$ npm -v
3.10.10
[es@node1 ~]$ grunt -version
grunt-cli v1.2.0
[es@node1 ~]$

(5)下載head外掛原始碼

[[email protected] ~]$ wget https://github.com/mobz/elasticsearch-head/archive/master.zip
--2017-12-18 09:58:08--  https://github.com/mobz/elasticsearch-head/archive/master.zip
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/mobz/elasticsearch-head/zip/master [following]
--2017-12-18 09:58:09--  https://codeload.github.com/mobz/elasticsearch-head/zip/master
Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 921421 (900K) [application/zip]
Saving to: ‘master.zip100%[===============================================================>] 921,421     9.64KB/s   in 67s    

2017-12-18 09:59:18 (13.4 KB/s) - ‘master.zip’ saved [921421/921421]

[[email protected] ~]$ ls
master.zip
[[email protected] ~]$ unzip master.zip 

(6)下載依賴
進入elasticsearch-head-master目錄,執行下面命令

[es@node1 elasticsearch-head-master]$ npm install

> phantomjs-prebuilt@2.1.16 install /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1515165531727/phantomjs-2.1.1-linux-x86_64 -> /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
elasticsearch-head@0.0.0 /home/es/elasticsearch-head-master
└─┬ grunt-contrib-jasmine@1.0.3
  └─┬ grunt-lib-phantomjs@1.1.0
    └── phantomjs-prebuilt@2.1.16 

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
[es@node1 elasticsearch-head-master]$ 

如果上面命令安裝較慢或失敗,可以嘗試國內映象安裝

[es@node1 elasticsearch-head-master]$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
[sudo] password for es: 
/usr/bin/cnpm -> /usr/lib/node_modules/cnpm/bin/cnpm
/usr/lib
└─┬ cnpm@5.1.1 
  ├─┬ npminstall@3.3.0 
  │ ├── binary-mirror-config@1.7.3 
  │ ├── moment@2.20.1 
  │ └─┬ tar@4.2.0 
  │   └── minizlib@1.1.0 
  └─┬ urllib@2.25.3 
    └─┬ proxy-agent@2.1.0
      └─┬ pac-proxy-agent@2.0.0
        └─┬ socks-proxy-agent@3.0.1
          └─┬ agent-base@4.1.2
            └─┬ es6-promisify@5.0.0
              └── es6-promise@4.2.2 

[es@node1 elasticsearch-head-master]$ cnpm install
⠸ [6/10] Installing json-schema-traverse@^0.3.0platform unsupported karma@1.3.0 › chokidar@1.7.0 › fsevents@^1.0.0 Package require os(darwin) not compatible with your platform(linux)
[fsevents@^1.0.0] optional install error: Package require os(darwin) not compatible with your platform(linux)
✔ Installed 10 packages
✔ Linked 313 latest versions
PhantomJS not found on PATH
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /home/es/elasticsearch-head-master/node_modules/_phantomjs-prebuilt@2.1.16@phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1515223629881/phantomjs-2.1.1-linux-x86_64 -> /home/es/elasticsearch-head-master/node_modules/_phantomjs-prebuilt@2.1.16@phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /home/es/elasticsearch-head-master/node_modules/_phantomjs-prebuilt@2.1.16@phantomjs-prebuilt/lib/phantom/bin/phantomjs
✔ Run 1 scripts
deprecate grunt-contrib-connect@1.0.2 › http2@^3.3.4 Use the built-in module in node 9.0.0 or newer, instead
deprecate grunt@1.0.1 › coffee-script@~1.10.0 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
anti semver karma@1.3.0 › useragent@2.2.1 › tmp@0.0.x delcares tmp@0.0.x(resolved as 0.0.33) but using ancestor(karma)'s dependency [email protected](resolved as 0.0.28)
✔ All packages installed (365 packages installed from npm registry, used 17s, speed 497.82kB/s, json 323(581.43kB), tarball 7.64MB)
[[email protected] elasticsearch-head-master]$ 

2.3 配置

(0)停止ElasticSearch
如果ElasticSearch已經啟動,需要先停止

[es@node1 ~]$ jps
3261 Elasticsearch
3375 Jps
[es@node1 ~]$ kill 3261

(1)配置 ElasticSearch,使得HTTP對外提供服務

[es@node1 elasticsearch-6.1.1]$ vi config/elasticsearch.yml

新增如下內容

# 增加新的引數,這樣head外掛可以訪問es。設定引數的時候:後面要有空格
http.cors.enabled: true
http.cors.allow-origin: "*"

(2)修改Head外掛配置檔案

[es@node1 elasticsearch-head-master]$ vi Gruntfile.js

找到connect:server,新增hostname一項,如下

connect: {
                        server: {
                                options: {
                                        hostname: 'node1',
                                        port: 9100,
                                        base: '.',
                                        keepalive: true
                                }
                        }
                }

2.4 啟動

(1)啟動elasticsearch
首先確認elasticsearch已經啟動

[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
[es@node1 elasticsearch-6.1.1]$ jps
3451 Jps
3436 Elasticsearch
[es@node1 elasticsearch-6.1.1]$

(2)啟動head
通過命令grunt server啟動head

[[email protected] elasticsearch-head-master]$ grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://node1:9100

或者通過命令npm run start也可以啟動head

[[email protected] elasticsearch-head-master]$ npm run start

> [email protected]0.0.0 start /home/es/elasticsearch-head-master
> grunt server

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://node1:9100

這裡寫圖片描述
如果出現“未連線”,請修改localhost為node1,然後單擊“連線”按鈕

這裡寫圖片描述

2.5 簡單應用

(1)建立索引

[root@node1 ~]# curl -XPUT node1:9200/test
{"acknowledged":true,"shards_acknowledged":true,"index":"test"}[root@node1 ~]# 

(2)檢視head變化
這裡寫圖片描述

相關推薦

ElasticSearch 6.x 學習筆記2.head外掛

2.1 Head外掛簡介 ElasticSearch-head是一個H5編寫的ElasticSearch叢集操作和管理工具,可以對叢集進行傻瓜式操作。 顯示叢集的拓撲,並且能夠執行索引和節點級別操作 搜尋介面能夠查詢叢集中原始json或表格格式的檢索資料

ElasticSearch 6.x 學習筆記12.欄位型別

12.1 欄位型別概述 一級分類 二級分類 具體型別 核心型別 字串型別 string,text,keyword 整數型別 integer,long,

ElasticSearch 6.x 學習筆記6.索引

6.1 建立索引 (1)簡單方式 PUT test { "acknowledged": true, "shards_acknowledged": true, "index": "t

ElasticSearch 6.x 學習筆記15.檢索入門

15.1 準備資料 [es@node1 ~]$ vi website.json [es@node1 ~]$ cat website.json { "index":{ "_index": "website", "_type": "blog", "_id"

ElasticSearch 6.x 學習筆記31.Java API之詞項查詢

1、term查詢 Find documents which contain the exact term specified in the field specified. package cn.hadron; import cn.hadron.

ElasticSearch 6.x 學習筆記7.文件

7.1 新建文件 index/type/id1 (1)一般格式 PUT blog/csdn/1 { "id":1, "title":"Elastic

ElasticSearch 6.x 學習筆記20.搜尋排序

20.1 按照文件新增順序排序 GET website/_search GET website/_search { "query": { "match_all": {} } }

Spark2.x學習筆記2、Scala簡單例子

2、 Scala簡單例子2.1 互動式程式設計spark-shell是Spark互動式執行模式,提供了互動式程式設計,邊敲程式碼邊執行,不需要建立程式原始檔,方便除錯程式,有利於快速學習Spark。[[email protected] spark-2.2.0]# bin/spark-shell U

Spark2.x學習筆記6、在Windows平臺下搭建Spark開發環境(Intellij IDEA)

Spark2.x學習筆記 6、 在Windows平臺下搭建Spark開發環境(Intellij IDEA+Maven) 6.1 整合開發環境IDE 為了方便應用程式開發與測試,提高開發效率,一般使用整合開發工具IDE。同樣,為了方便Spark應用程式編

LogStash官方文件6.x學習筆記---------day1

上個星期之前看過一段時間,對logstash基礎有一定了解。現在來好好記錄一下我的學習的東西。 logstash的工作流程:    由input--->filter---->output構成。 執行模型: Logstash事件處理管道協調input--

Spark2.x學習筆記3、 Spark核心概念RDD

Spark學習筆記:3、Spark核心概念RDD 3.1 RDD概念 彈性分散式資料集(Resilient Distributed Datasets,RDD) ,可以分三個層次來理解: 資料集:故名思議,RDD 是資料集合的抽象,是複雜物理介質上存在資料的一種邏輯檢視。

Spark2.x學習筆記14、Spark SQL程式設計

Spark2.x學習筆記:14、 Spark SQL程式設計 14.1 RDD的侷限性 RDD僅表示資料集,RDD沒有元資料,也就是說沒有欄位語義定義。 RDD需要使用者自己優化程式,對程式設計師要求較高。 從不同資料來源讀取資料相對困難。 合併多個數

作業系統精髓與設計原理(原書第6版)——學習筆記2

 1.3.1 取指令和執行指令 指令暫存器(InstructionRegister,IR)放置取到的指令。指令中包含確定處理器要執行的操作位,處理器解釋指令並執行對應的操作。大體上,這些操作可

go學習筆記2.變數、型別、常量

基本型別 1.基本型別列表 複製程式碼程式碼如下: 型別        長度     說明 bool         1      true/false,預設false, 不能把非0值當做true(不用數字代表true/false) byte        

Flink學習筆記2、Flink介紹

2、Flink介紹 Some of you might have been already using Apache Spark in your day-to-day life and might have been wondering if I have S

Cocos2d-x 3.x學習筆記猩先生帶你打飛機(四)遊戲場景:背景與我機的建立、敵機的建立、物理世界構建

一、背景與我機的建立 現在我們要建立新的一個場景了。選擇開始遊戲即從選單場景跳到遊戲場景。現在先完善HelloWorldScene的程式碼 找到我們開始遊戲的回撥方法,新增程式碼: //開始遊戲 void HelloWorld::menuStartCa

‎Cocos2d-x 學習筆記(3.2) TransitionScene 過渡場景和場景切換的過程

1. 簡介 過渡場景TransitionScene直接繼承了場景Scene。能夠在場景切換過程中實現“過渡”效果,而不是讓視窗在下一幀突然展示另一個場景。 2. create 建構函式: TransitionScene::TransitionScene() : _inSc

ES[7.6.x]學習筆記(七)IK中文分詞器

在上一節中,我們給大家介紹了ES的分析器,我相信大家對ES的全文搜尋已經有了深刻的印象。分析器包含3個部分:字元過濾器、分詞器、分詞過濾器。在上一節的例子,大家發現了,都是英文的例子,是吧?因為ES是外國人寫的嘛,中國如果要在這方面趕上來,還是需要螢幕前的小夥伴們的~ 英文呢,我們可以按照空格將一句話、一

ES[7.6.x]學習筆記(八)資料的增刪改

在前面幾節的內容中,我們學習索引、欄位對映、分析器等,這些都是使用ES的基礎,就像在資料庫中建立表一樣,基礎工作做好以後,我們就要真正的使用它了,這一節我們要看看怎麼向索引裡寫入資料、修改資料、刪除資料,至於搜尋嘛,因為ES的主要功能就是搜尋,所以搜尋的相關功能我們後面會展開講。 ## Document的建

ES[7.6.x]學習筆記(九)搜尋

搜尋是ES最最核心的內容,沒有之一。前面章節的內容,索引、動態對映、分詞器等都是鋪墊,最重要的就是最後點選搜尋這一下。下面我們就看看點選搜尋這一下的背後,都做了哪些事情。 ## 分數(score) ES的搜尋結果是按照相關分數的高低進行排序的,咦?! 怎麼沒說搜尋先說搜尋結果的排序了?咱們這裡先把這個概念