elasticsearch -- head插件

elasticsearch head插件是一個入門級的elasticsearch前端插件;咱們來安裝下;html

 

第一步:安裝nodejs  前端

head插件是nodejs實現的,因此必須先安裝Nodejsjava

參考:http://blog.java1234.com/blog/articles/354.htmlnode

 

第二步:安裝gitgit

咱們要用git方式下載head插件github

參考:http://blog.java1234.com/blog/articles/353.htmlnpm

 

第三步:下載以及安裝head插件json

打開 https://github.com/mobz/elasticsearch-head bootstrap

Running with built in server

  • git clone git://github.com/mobz/elasticsearch-head.gitcentos

  • cd elasticsearch-head

  • npm install

  • npm run start

 

咱們用這種最簡單的方式安裝

 

固然咱們安裝的地方是 /usr/local/ 

 

第四步:配置elasticsearch,容許head插件訪問

進入elasticsearch config目錄 打開 elasticsearch.yml

最後加上

http.cors.enabled: true

http.cors.allow-origin: "*"

 

第五步:測試

啓動elasticsearch,再進入head目錄,執行npm run start 啓動插件

QQ鎴浘20171126134151.jpg

 

說明啓動成功,而後瀏覽器 執行 http://192.168.1.110:9100/

QQ鎴浘20171126134057.jpg

內部輸入 http://192.168.1.110:9200/ 點擊鏈接 若是右側輸出黃色背景字體 說明配置完整OK;

 

 

elasticsearch-head插件添加索引

 

 

elasticsearch提供了豐富的http url接口對外提供服務,

這也使得elasticsearch插件特別多,功能也強大;

 

咱們今天來說下 用head插件來添加索引

這裏有好幾種方式,先講一種原始的,

QQ鎴浘20171126144423.jpg

 

進入主頁,選擇 複合查詢

QQ鎴浘20171126144434.jpg

 

咱們之後執行操做 都在這裏搞;

 

地址欄輸入:http://192.168.1.110:9200/student/

而後點擊「提交請求」,便可;

QQ鎴浘20171126144635.jpg

 

QQ鎴浘20171126144645.jpg

 

右側返回索引添加成功信息;

咱們返回 概要 首頁 點擊 刷新 也能看到新建的索引student

QQ鎴浘20171126144808.jpg

 

這裏方式有點索引 這裏有更加簡單的方式

 

點擊 索引標籤,

QQ鎴浘20171126144922.jpg

 

點擊「新建索引」,

QQ鎴浘20171126144930.jpg

這裏咱們輸入索引名稱便可 固然默認分片數是5 副本數是1 咱們輸入索引名稱student2 分片數10 副本2

假如單個機器部署的話 副本是沒地方分配的 通常集羣都是2臺或者2臺以上機器集羣,副本都不存對應的分片因此機器的,這樣能保證集羣系統的可靠性。

 

咱們點擊"OK" 便可輕鬆創建索引 以及分片數和副本;

 

回到概要首頁;

QQ鎴浘20171126145007.jpg

 

這裏能夠清晰的看到索引 以及分片和副本;

 

固然要刪除索引的話

QQ鎴浘20171126145610.jpg

 

點 動做  而後 刪除 ,便可;

 

比較簡單

 

elasticsearch-head插件添加,修改,刪除文檔

elasticsearch-head插件添加,修改,刪除文檔

 

咱們用head插件來實現下添加,修改,刪除文檔操做;

 

首先是添加文檔,這裏咱們給student索引添加文檔

先進入符合查詢

post方式  http://192.168.1.110:9200/student/first/12/

這裏student是索引 first是類別 12是id

假如id沒寫的話 系統也會給咱們自動生成一個

假如id自己已經存在 那就變成了修改操做;咱們通常都要指定下id

QQ鎴浘20171126152450.jpg

 

咱們輸入Json數據,而後點擊提交,右側顯示建立成功,固然咱們能夠驗證下json

 

點 數據瀏覽,

QQ鎴浘20171126152556.jpg

 

咱們能夠看到新添加的索引文檔

 

修改文檔的話,

方式和添加同樣,只不過咱們必定要指定已經存在的id

地址輸入:http://192.168.1.110:9200/student/first/12/

而後修改下數據,點擊提交:

QQ鎴浘20171126152730.jpg

咱們發現 提示修改爲功;

 

數據瀏覽裏:

QQ鎴浘20171126152819.jpg

 

查詢文檔也有能夠經過請求

http://192.168.1.110:9200/student/first/12/ 選擇get方式,而後點擊提交

QQ鎴浘20171126152957.jpg

 

刪除文檔 

image.png

選擇delete便可;

 

前面咱們講過刪除索引的圖形操做方式;

用http url命令也能夠

輸入:http://192.168.1.110:9200/student/

選擇delete便可

QQ鎴浘20171126153232.jpg

elasticsearch使用head插件打開和關閉索引

elasticsearch使用head打開和關閉索引

 

打開/關閉索引接口容許關閉一個打開的索引或者打開一個已經關閉的索引。

關閉的索引只能顯示索引元數據信息,不可以進行讀寫操做。

 

好比咱們新建一個索引student2

咱們用 POST http://192.168.1.110:9200/student2/_close/  關閉索引

點擊提交請求;

 

再概要首頁裏,能夠刷新下 看到student2被關閉;

QQ鎴浘20171127093801.jpg

變成了灰色;

 

POST http://192.168.1.110:9200/student2/_open/ 打開索引;

點擊提交請求,

回到概要首頁,點擊刷新,

QQ鎴浘20171127094112.jpg

 

又正常了。

elasticsearch head插件 增長索引映射

 

 

elasticsearch head插件 增長索引映射

 

elasticsearch HTTP API 容許你向索引(index)添加文檔類型(type),或者向文檔類型(type)中添加字段(field)。

 

PUT http://192.168.1.110:9200/student/

{

   "mappings":{

       "first":{

            "properties":{

               "name":{"type":"keyword"}

             }

        }

   }

}

mapping是映射關鍵字  properties是添加指定文檔類型的字段的關鍵字

點擊提交,添加student索引

添加文檔類型first    

添加字段name 類型是keyword

(keyword類型適合短詞彙內容,好比郵件,姓名,性別等等,text類型適合長文本,能夠分詞,好比文章標題,文章內容等)

 

PUT http://192.168.1.110:9200/student/_mapping/third/

{

   "properties":{

      "name2":{"type":"keyword"}

    }

}

 

向已經存在的索引student添加文檔類型爲third,包含字段name2,字段類型是keyword字符串

 

elasticsearch head插件 查詢索引映射關係

 

elasticsearch head插件 查詢索引映射關係

 

http://192.168.1.110:9200/student/  GET  直接加索引名稱便可 能查到全部信息

 

QQ鎴浘20171127134021.jpg

 

 

第二種方式 利用head插件圖形工具:

QQ鎴浘20171127134120.jpg

 

進入概要首頁,選擇索引,而後索引信息,

QQ鎴浘20171127134126.jpg

 

直接顯示索引的映射狀態信息;

 

elasticsearch-.yml(中文配置詳解)

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
集羣名稱,默認是elasticsearch
# cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
節點名稱,默認從elasticsearch-2.4.3/lib/elasticsearch-2.4.3.jar!config/names.txt中隨機選擇一個名稱
# node.name: node-1
#
# Add custom attributes to the node:

# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
能夠指定es的數據存儲目錄,默認存儲在es_home/data目錄下
# path.data: /path/to/data
#
# Path to log files:
能夠指定es的日誌存儲目錄,默認存儲在es_home/logs目錄下
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
# 鎖定物理內存地址,防止elasticsearch內存被交換出去,也就是避免es使用swap交換分區
# bootstrap.memory_lock: true
#
#
#
確保ES_HEAP_SIZE參數設置爲系統可用內存的一半左右
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.

當系統進行內存交換的時候,es的性能不好
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
#
爲es設置ip綁定,默認是127.0.0.1,也就是默認只能經過127.0.0.1 或者localhost才能訪問
es1.x版本默認綁定的是0.0.0.0 因此不須要配置,可是es2.x版本默認綁定的是127.0.0.1,須要配置
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
#
#
爲es設置自定義端口,默認是9200
注意:在同一個服務器中啓動多個es節點的話,默認監聽的端口號會自動加1:例如:9200,9201,9202...
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
當啓動新節點時,經過這個ip列表進行節點發現,組建集羣
默認節點列表:
127.0.0.1,表示ipv4的迴環地址。
# [::1],表示ipv6的迴環地址
#
在es1.x中默認使用的是組播(multicast)協議,默認會自動發現同一網段的es節點組建集羣,
在es2.x中默認使用的是單播(unicast)協議,想要組建集羣的話就須要在這指定要發現的節點信息了。
注意:若是是發現其餘服務器中的es服務,能夠不指定端口[默認9300],若是是發現同一個服務器中的es服務,就須要指定端口了。
# Pass an initial list of hosts to perform discovery when new node is started:

# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
#
#
#
經過配置這個參數來防止集羣腦裂現象 (集羣總節點數量/2)+1
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
一個集羣中的N個節點啓動後,才容許進行數據恢復處理,默認是1
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
在一臺服務器上禁止啓動多個es服務
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
設置是否能夠經過正則或者_all刪除或者關閉索引庫,默認true表示必須須要顯式指定索引庫名稱
生產環境建議設置爲true,刪除索引庫的時候必須顯式指定,不然可能會誤刪索引庫中的索引庫。
# Require explicit names when deleting indices:
#

# action.destructive_requires_name: true

 

 

elasticsearch5.5多機集羣配置

elasticsearch5.5多機集羣配置

 

ELasticsearch 5.5要求JDK版本最低爲1.8;

 

配置集羣以前  先把要加羣集羣的節點的裏的data目錄下的Node目錄 刪除,不然集羣創建會失敗。

 

我這邊虛擬機配置了兩臺centos IP分別是 192.168.1.110 和 192.168.1.111 ;

 

分別配置下elasticsearch.yml配置文件

110機器:

# ---------------------------------- Cluster -----------------------------------

#

# Use a descriptive name for your cluster:

#

cluster.name: my-application

#

# ------------------------------------ Node ------------------------------------

#

# Use a descriptive name for the node:

#

node.name: node-1

#

# Add custom attributes to the node:

#

#node.attr.rack: r1

#

# ----------------------------------- Paths ------------------------------------

#

# Path to directory where to store the data (separate multiple locations by comma):

#

#path.data: /path/to/data

#

# Path to log files:

#

#path.logs: /path/to/logs

#

# ----------------------------------- Memory -----------------------------------

#

# Lock the memory on startup:

#

#bootstrap.memory_lock: true

#

# Make sure that the heap size is set to about half the memory available

# on the system and that the owner of the process is allowed to use this

# limit.

#

# Elasticsearch performs poorly when the system is swapping the memory.

#

# ---------------------------------- Network -----------------------------------

#

# Set the bind address to a specific IP (IPv4 or IPv6):

#

network.host: 192.168.1.110

#

# Set a custom port for HTTP:

#

http.port: 9200

#

# For more information, consult the network module documentation.

#

# --------------------------------- Discovery ----------------------------------

#

# Pass an initial list of hosts to perform discovery when new node is started:

# The default list of hosts is ["127.0.0.1", "[::1]"]

#

discovery.zen.ping.unicast.hosts: ["192.168.1.110"]

#

# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):

#

#discovery.zen.minimum_master_nodes: 3

#

# For more information, consult the zen discovery module documentation.

#

# ---------------------------------- Gateway -----------------------------------

#

# Block initial recovery after a full cluster restart until N nodes are started:

#

#gateway.recover_after_nodes: 3

#

# For more information, consult the gateway module documentation.

#

# ---------------------------------- Various -----------------------------------

#

# Require explicit names when deleting indices:

#

#action.destructive_requires_name: true

http.cors.enabled: true

http.cors.allow-origin: "*"

 

111機器:

# ---------------------------------- Cluster -----------------------------------

#

# Use a descriptive name for your cluster:

#

cluster.name: my-application

#

# ------------------------------------ Node ------------------------------------

#

# Use a descriptive name for the node:

#

node.name: node-2

#

# Add custom attributes to the node:

#

#node.attr.rack: r1

#

# ----------------------------------- Paths ------------------------------------

#

# Path to directory where to store the data (separate multiple locations by comma):

#

#path.data: /path/to/data

#

# Path to log files:

#

#path.logs: /path/to/logs

#

# ----------------------------------- Memory -----------------------------------

#

# Lock the memory on startup:

#

#bootstrap.memory_lock: true

#

# Make sure that the heap size is set to about half the memory available

# on the system and that the owner of the process is allowed to use this

# limit.

#

# Elasticsearch performs poorly when the system is swapping the memory.

#

# ---------------------------------- Network -----------------------------------

#

# Set the bind address to a specific IP (IPv4 or IPv6):

#

network.host: 192.168.1.111

#

# Set a custom port for HTTP:

#

http.port: 9200

#

# For more information, consult the network module documentation.

#

# --------------------------------- Discovery ----------------------------------

#

# Pass an initial list of hosts to perform discovery when new node is started:

# The default list of hosts is ["127.0.0.1", "[::1]"]

#

discovery.zen.ping.unicast.hosts: ["192.168.1.110"]

#

# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):

#

#discovery.zen.minimum_master_nodes: 3

#

# For more information, consult the zen discovery module documentation.

#

# ---------------------------------- Gateway -----------------------------------

#

# Block initial recovery after a full cluster restart until N nodes are started:

#

#gateway.recover_after_nodes: 3

 

 

 

這裏兩臺機器的cluster.name必須一致 這樣纔算一個集羣

node.name節點名稱每臺取不一樣的名稱,用來表示不一樣的集羣節點

network.host配置成本身的局域網IP

http.port端口就固定9200

discovery.zen.ping.unicast.hosts主動發現節點咱們都配置成110節點IP

 

配置完後 重啓es服務;

 

而後head插件咱們查看下:

QQ鎴浘20171204103904.jpg

 

說明集羣配置OK 。

相關文章
相關標籤/搜索