如何理解Elasticsearch单机双节点集群部署
这篇文章,我们还是做些基础的学习,在Elasticsearch如何进行CRUD。
Elasticsearch单机双节点集群部署
环境:CentOS 7.2 JDK 1.8.0_74
一、安装第一个ElasticSearch(主节点)
1、创建es用户,启动es不能使用root用户
useradd es passwd es
root用户进入/home/es目录下
2、获取ElasticSearch安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.2.tar.gz
3、解压、改名(方便集群时区别另一个ES)
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node2
4、修改配置文件
vi elasticsearch-node2/config/elasticsearch.yml
修改内容如下:
cluster.name: my-application 各节点此名称必须一致node.name: node-2 节点名称,不能与其他节点相同 network.host: ***.***.***.*** 自己的服务器IPhttp.port: **** 访问端口transport.tcp.port: **** 集群各节点间的通讯端口 discovery.zen.ping.unicast.hosts: ["主节点IP:通讯端口","辅节点IP:通讯端口"]
文件最后追加以下内容,以便连接head显示健康值(注意每行代码前面不要有空格)
http.cors.enabled: truehttp.cors.allow-origin: "*"
5、启动
sh elasticsearch-node2/bin/elasticsearch
[2018-01-24T15:36:41,990][INFO ][o.e.n.Node ] [KMyyO-3] started [2018-01-24T15:36:41,997][INFO ][o.e.g.GatewayService ] [KMyyO-3] recovered [0] indices into cluster_state
启动成功,浏览器中输入 IP:访问端口
网页显示以下内容,说明部署成功
{ "name" : "node-2", "cluster_name" : "my-application", "cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww", "version" : { "number" : "6.1.2", "build_hash" : "5b1fea5", "build_date" : "2018-01-10T02:35:59.208Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search"}
6、报错及其处理
【类型一】
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
该问题是因为运行es不能使用root用户,因此要切换es用户再次启动
chown -R es:es elasticsearch-node2/su - es sh elasticsearch-node2/bin/elasticsearch
【类型二】
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方法,换回root用户,修改配置文件
vi /etc/security/limits.conf#在最后面追加下面内容es hard nofile 65536es soft nofile 65536
【类型三】
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法,换回root用户,修改配置文件
vi /etc/sysctl.conf #在最后面追加下面内容vm.max_map_count=655360#执行命令:sysctl -p
二、安装第二个ElasticSearch(辅节点)
安装方法与第一个一致,注意修改配置文件
root用户进入/home/es目录下
1、解压、改名
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node3
2、修改配置文件
vi elasticsearch-node3/config/elasticsearch.yml
修改内容如下:
cluster.name: my-application 各节点此名称必须一致node.name: node-3 节点名称,不能与其他节点相同network.host: ***.***.***.*** 自己的服务器IPhttp.port: **** 访问端口(注意不要与第一个端口重复) transport.tcp.port: **** 集群各节点间的通讯端口(注意不要与第一个端口重复)discovery.zen.ping.unicast.hosts: ["主节点IP:通讯端口","辅节点IP:通讯端口"]
文件最后同样追加下面代码
http.cors.enabled: truehttp.cors.allow-origin: "*"
3.启动
sh elasticsearch-node3/bin/elasticsearch
浏览器,浏览器中输入 IP:访问端口
网页显示以下内容,说明第二个部署成功
{ "name" : "node-3", "cluster_name" : "my-application", "cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww", "version" : { "number" : "6.1.2", "build_hash" : "5b1fea5", "build_date" : "2018-01-10T02:35:59.208Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search"}
三、安装Elasticsearch-head插件
1、安装head插件之前需要安装node.js
curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install -y nodejs
安装完成后执行命令查看node与npm版本
[root@host]# node -vv8.12.0[root@host]# npm -v6.4.1
2、从git获取head插件
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
3、解压安装包(可以改名,方便操作)
unzip master.zip mv elasticsearch-head-master/ head
4、修改配置文件
vi head/Gruntfile.js
更改head端口号
connect: { server: { options: { port: ****, 改为head访问端口 base: '.', keepalive: true } } }
vi head/_site/app.js
更改head链接地址
init: function(parent) { this._super(); this.prefs = services.Preferences.instance(); this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://主节点IP:访问端口";
5、启动head
nohup npm run start > ../head.log 2>&1 &
6、浏览器登录head
URL输入服务器IP:head访问端口
链接地址输如主节点的访问地址
7、安装head常见错误
【类型一】启动成功,但是网页不能访问
解决方法
关闭服务器防火墙
service iptables stop
【类型二】集群健康值未连接
在elasticsearch.yml里追加下列代码(注意代码前面不要有空格)
http.cors.enabled: truehttp.cors.allow-origin: "*"
问:为什么es节点用node2、node3?
答:因为之前用node1搭建了一套未集群的ES,所以后面集群就用2和3了
相关推荐:
Atas ialah kandungan terperinci 如何理解Elasticsearch单机双节点集群部署. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Alat AI Hot

Undress AI Tool
Gambar buka pakaian secara percuma

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Clothoff.io
Penyingkiran pakaian AI

Video Face Swap
Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

Alat panas

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6
Alat pembangunan web visual

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)