elasticsearch -- head插件
2019獨角獸企業重金招聘Python工程師標準>>>
elasticsearch head插件是一個入門級的elasticsearch前端插件;我們來安裝下;
?
第一步:安裝nodejs??
head插件是nodejs實現的,所以必須先安裝Nodejs
參考:http://blog.java1234.com/blog/articles/354.html
?
第二步:安裝git
我們要用git方式下載head插件
參考:http://blog.java1234.com/blog/articles/353.html
?
第三步:下載以及安裝head插件
打開?https://github.com/mobz/elasticsearch-head?
Running with built in server
-
git clone git://github.com/mobz/elasticsearch-head.git
-
cd elasticsearch-head
-
npm install
-
npm run start
-
open?http://localhost:9100/
?
我們用這種最簡單的方式安裝
?
當然我們安裝的地方是 /usr/local/?
?
第四步:配置elasticsearch,允許head插件訪問
進入elasticsearch config目錄 打開?elasticsearch.yml
最后加上
http.cors.enabled: true
http.cors.allow-origin: "*"
?
第五步:測試
啟動elasticsearch,再進入head目錄,執行npm run start 啟動插件
?
說明啟動成功,然后瀏覽器 執行?http://192.168.1.110:9100/
內部輸入?http://192.168.1.110:9200/?點擊連接 如果右側輸出黃色背景字體 說明配置完整OK;
?
?
elasticsearch-head插件添加索引
?
?
elasticsearch提供了豐富的http url接口對外提供服務,
這也使得elasticsearch插件特別多,功能也強大;
?
我們今天來講下 用head插件來添加索引
這里有好幾種方式,先講一種原始的,
?
進入主頁,選擇 復合查詢
?
我們以后執行操作 都在這里搞;
?
地址欄輸入:http://192.168.1.110:9200/student/
然后點擊“提交請求”,即可;
?
?
右側返回索引添加成功信息;
我們返回 概要 首頁 點擊 刷新 也能看到新建的索引student
?
這里方式有點索引 這里有更加簡單的方式
?
點擊 索引標簽,
?
點擊“新建索引”,
這里我們輸入索引名稱即可 當然默認分片數是5 副本數是1 我們輸入索引名稱student2 分片數10 副本2
假如單個機器部署的話 副本是沒地方分配的 一般集群都是2臺或者2臺以上機器集群,副本都不存對應的分片所以機器的,這樣能保證集群系統的可靠性。
?
我們點擊"OK" 即可輕松建立索引 以及分片數和副本;
?
回到概要首頁;
?
這里可以清晰的看到索引 以及分片和副本;
?
當然要刪除索引的話
?
點 動作? 然后 刪除 ,即可;
?
比較簡單
?
elasticsearch-head插件添加,修改,刪除文檔
elasticsearch-head插件添加,修改,刪除文檔
?
我們用head插件來實現下添加,修改,刪除文檔操作;
?
首先是添加文檔,這里我們給student索引添加文檔
先進入符合查詢
post方式??http://192.168.1.110:9200/student/first/12/
這里student是索引 first是類別 12是id
假如id沒寫的話 系統也會給我們自動生成一個
假如id本身已經存在 那就變成了修改操作;我們一般都要指定下id
?
我們輸入Json數據,然后點擊提交,右側顯示創建成功,當然我們可以驗證下json
?
點 數據瀏覽,
?
我們可以看到新添加的索引文檔
?
修改文檔的話,
方式和添加一樣,只不過我們一定要指定已經存在的id
地址輸入:http://192.168.1.110:9200/student/first/12/
然后修改下數據,點擊提交:
我們發現 提示修改成功;
?
數據瀏覽里:
?
查詢文檔也有可以通過請求
http://192.168.1.110:9200/student/first/12/?選擇get方式,然后點擊提交
?
刪除文檔?
選擇delete即可;
?
前面我們講過刪除索引的圖形操作方式;
用http url命令也可以
輸入:http://192.168.1.110:9200/student/
選擇delete即可
elasticsearch使用head插件打開和關閉索引
elasticsearch使用head打開和關閉索引
?
打開/關閉索引接口允許關閉一個打開的索引或者打開一個已經關閉的索引。
關閉的索引只能顯示索引元數據信息,不能夠進行讀寫操作。
?
比如我們新建一個索引student2
我們用 POST?http://192.168.1.110:9200/student2/_close/? 關閉索引
點擊提交請求;
?
再概要首頁里,可以刷新下 看到student2被關閉;
變成了灰色;
?
POST?http://192.168.1.110:9200/student2/_open/?打開索引;
點擊提交請求,
回到概要首頁,點擊刷新,
?
又正常了。
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? 直接加索引名稱即可 能查到所有信息
?
?
?
第二種方式 利用head插件圖形工具:
?
進入概要首頁,選擇索引,然后索引信息,
?
直接顯示索引的映射狀態信息;
?
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插件我們查看下:
?
說明集群配置OK 。
轉載于:https://my.oschina.net/u/1458864/blog/2050766
總結
以上是生活随笔為你收集整理的elasticsearch -- head插件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: maven项目,httpclient j
- 下一篇: linux安装python3.6以后报错