单机集群配置
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
同理修改 es1
与 es2
配置文件 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
页面, 看到下图, 剩下 es
和 es2
节点
完美~
elasticsearch.yml
配置详解可以参考
https://blog.youkuaiyun.com/gekkoou/article/details/80954557