Elasticsearch 單機集羣配置 與 宕機模擬

單機集羣配置

1. 集羣安裝

下載 elasticsearch 解壓並把目錄改名爲 es, 複製兩份, 第一份 es1, 第二份 es2

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.0.tar.gz
tar -zxf elasticsearch-6.3.0
mv elasticsearch-6.3.0 es
cp -r es ./es1
cp -r es ./es2

假設現在3個es節點都爲 master
修改 es 配置文件

vim ./es/config/elasticsearch.yml

修改如下

# 集羣名稱
cluster.name: my-test
# 節點名稱
node.name: es
node.master: true
node.data: true

network.host: 127.0.0.1
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300", "127.0.0.1:9301"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true

同理修改 es1es2 配置文件 elasticsearch.yml, 修改如下

# es1
cluster.name: my-test
node.name: es1
node.master: true
node.data: true

network.host: 127.0.0.1
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true
# es2
cluster.name: my-test
node.name: es2
node.master: true
node.data: true

network.host: 127.0.0.1
http.port: 9202
transport.tcp.port: 9302
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true

2. head插件安裝

head插件
https://github.com/mobz/elasticsearch-head
安裝方法此處不做詳細介紹

本文牆裂推薦, 使用 chrome 插件 ElasticSearch Head (一鍵打開, 無需繁瑣安裝)
https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm

head插件使用方法也不做詳細介紹了


3.驗證

分別到 es/bin es1/bin es2/bin 目錄下執行命令

elasticsearch -d

chrome 瀏覽器打開插件 ElasticSearch Head, 看到下圖即爲成功

這裏寫圖片描述
漂亮~


宕機模擬

執行命令記下 es1 的pid, 並殺掉進程

ps -ef | grep es1
kill -9 es1的pid

刷新插件 Elasticsearch Head 頁面, 看到下圖, 剩下 eses2 節點

這裏寫圖片描述
完美~


elasticsearch.yml 配置詳解可以參考
https://blog.csdn.net/gekkoou/article/details/80954557





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章