elasticsearch學習——環境搭建2

1、head插件安裝html

打開cmd,而且cd到elasticsearch的bin目錄下面java

接着輸入命令:plugin install mobz/elasticsearch-head,node

而後就會開始安裝head插件,若是出現Installed head into的字樣,證實head插件安裝成功。bootstrap

而後就會在elasticsearch安裝目錄的plugins文件夾裏看到head目錄app

2、head插件界面介紹elasticsearch

一、裝好head插件以後,若是在本機裝的,則訪問localhost:9200/_plugin/head,就能夠看到head插件的界面了ide

這裏介紹一下界面,使用方法多摸索就會了。性能

二、elasticsearch分區,備份等概念介紹ui

cluster:集羣,一個ES集羣由一個或多個節點(Node)組成,每一個集羣都有一個cluster name做爲標識。this

node:節點,即一個 Elasticsearch 的運行實例,一臺機器上能夠運行多個節點

shard:分區,是一個Lucene 實例。Elasticsearch 基於 Lucene,shard 是一個 Lucene 實例,被 Elasticsearch 自動管理。index 是一個邏輯命名空間, shard 是具體的物理概念,建索引、查詢等都是具體的shard在工做。shard 包括primary shard 和 replica shard,寫數據時,先寫到primary shard, 而後,同步到 replica shard,查詢時,primary 和 replica 充當相同的做用。replica shard 能夠有多份,也能夠沒有。

replica:備份

    2.一、主分片和備分片不會出如今同一個節點上(防止單點故障),默認狀況下一個索引建立5個分片,每一個分片一個備份分片(即5primary+5replica=10個分片)
    2.二、若是你只有一個節點,那麼5個replica都沒法分配(unassigned),此時cluster status會變成yellow
    2.三、ES集羣狀態有三種:
            Green:全部主分片和備份分片都準備就緒(分配成功),即便有一臺機器掛了(假設一臺機器一個實例),數據都不會丟失,但會變成Yellow狀(主分片所在節點掛了備份分片會頂上去)
            Yellow:全部主分片準備就緒,但存在至少一個主分片對應的備份分片沒有就緒,此時集羣屬於警告狀態,意味着集羣高可用和容災能力降低,若是恰好這個分片所在的節點掛了,而且你只設置了一個備份(並且這個備份恰好是未就緒狀態),那麼這個分區的數據就會丟失,致使查詢結果不完整,此時集羣進入Red狀態
            Red:至少有一個主分片沒有就緒(直接緣由是找不到對應的備份分片成爲新的主分片),致使查詢結果數據不完整
    2.四、replica shard的存在有兩個做用,一是容災,若是primary shard 掛了,數據也不會丟失,集羣仍然能正常工做;二是提升性能,由於replica 和 primary shard 都能處理查詢,若是設置合理的備份數量能夠增長查詢速度,相應的會增長索引大小。

3、集羣搭建配置

一、將上面獲得的elasticsearch的安裝目錄複製兩份,記住新的名字最好不要含有中文。修改config目錄下的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:
# 集羣的名字,這三個文件的必須同樣
 cluster.name: elasticsearch
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 節點的名字,三個節點的不能同樣,另外兩個能夠寫成node-2,node-3
 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):
#
# 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 `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.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 
 network.host: 127.0.0.1
#
# 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 ----------------------------------
#
# 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"]
#
# 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:
#
# 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 -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true

#shard的數目
 index.number_of_shards: 6

#replica的數目
 index.number_of_replicas: 2

#制定分詞器爲ik
 index.analysis.analyzer.ik.type: "ik"

改好配置文件後就能夠啓動三個集羣名爲elasticsearch的節點了。

相關文章
相關標籤/搜索