Elasticsearch 5 集群
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Elasticsearch 5 集群相关的知识,希望对你有一定的参考价值。
1 准备工作
/etc/profile添加vim高亮显示
export PS1="\[\e]0;\a\]\n\[\e[1;32m\]\[\e[1;33m\]\H\[\e[1;35m\]<\$(date +\"%Y-%m-%d %T\")> \[\e[32m\]\w\[\e[0m\]\n\u>\\$ "
服务器信息:
192.168.91.220 (elasticsearch-node1) 192.168.91.221 (elasticsearch-node2) 192.168.91.222 (elasticsearch-node3)
1.1 安装 Java 环境
yum install vim openssh-clients lrzsz -y
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
这里 java-1.8.0-openjdk-devel
非必须安装,但以后安装插件时可能会需要 Java 的编译器(javac),因此建议提前安装好。
验证版本:
220.elk.node0.com<2016-12-13 12:02:42> ~ root># java -version openjdk version "1.8.0_111" OpenJDK Runtime Environment (build 1.8.0_111-b15) OpenJDK 64-Bit Server VM (build 25.111-b15, mixed mode)
1.2 配置 ES 的 yum 源
导入签名:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
设置 yum 源
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
Elastic Stack 相关产品均需要使用这个源。
1.3 操作系统配置
官方提供了生产环境下 Elasticsearch 所在操作系统的相关建议,详见这里
1. 跨域支持 根据官网建议添加了如下配置到elasticsearc.yml主配置文件 http.cors.enabled: true http.cors.allow-origin: "*" 问题二: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048] 解决方法:进入limits.d下的配置文件:vim /etc/security/limits.d/90-nproc.conf ,修改配置如下: vim /etc/security/limits.d/90-nproc.conf * soft nproc 1024 修改为: * soft nproc 2048 问题三: max file descriptors [64000] for elasticsearch process is too low, increase to at least [65536] 解决办法: 1、虚拟内存设置,编辑 /etc/sysctl.conf ,追加: vm.max_map_count=262144 2、修改文件句柄限制,编辑 /etc/security/limits.conf ,追加: root># vim /etc/security/limits.conf * soft nofile 65536 * hard nofile 65536 问题四: elasticsearch5.0启动失败,出现如下提示: 1、Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error=‘Cannot allocate memory‘ (errno=12) 由于elasticsearch5.0默认分配jvm空间大小为2g,修改jvm空间分配 # vim config/jvm.options -Xms2g -Xmx2g 修改为 -Xms512m -Xmx512m
2、Elasticsearch安装
node0 部署
220.elk.inzwc.com<2016-12-13 12:21:06> ~
root># useradd elasticsearch
220.elk.inzwc.com<2016-12-13 12:22:40> ~
root># chown -R elasticsearch:elasticsearch /opt/elasticsearch-node0/
root># tar -zxvf elasticsearch-5.0.2.tar.gz -C /opt/
root># cd /opt
root># mv elasticsearch-5.0.2 elasticsearch-node0
修改配置
root># cat /opt/elasticsearch-node0/config/elasticsearch.yml
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#cluster
cluster.name: "es-cluster"
node.name: "es-node0"
node.master: true
node.data: true
http.enabled: true
node1 部署
221.elk.inzwc.com<2016-12-13 12:21:10> ~
root># useradd elasticsearch
221.elk.inzwc.com<2016-12-13 12:21:24> ~
root># chown -R elasticsearch:elasticsearch /opt/elasticsearch-node1/
220.elk.node0.com<2016-12-13 12:04:43> /opt
root># scp -rp elasticsearch-node0/ [email protected]:/opt/elasticsearch-node1
221.elk.node1.com<2016-12-13 12:07:32> /opt/elasticsearch-node1/config
root># cat /opt/elasticsearch-node1/config/elasticsearch.yml
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#cluster
cluster.name: "es-cluster"
node.name: "es-node1"
node.master: true
node.data: true
http.enabled: true
PS:node.name
node2 部署
222.elk.inzwc.com<2016-12-13 12:21:15> ~
root># useradd elasticsearch
222.elk.inzwc.com<2016-12-13 12:23:20> ~
root># chown -R elasticsearch:elasticsearch /opt/elasticsearch-node2/
220.elk.node0.com<2016-12-13 12:04:43> /opt
root># scp -rp elasticsearch-node0/ [email protected]:/opt/elasticsearch-node2
222.elk.node2.com<2016-12-13 12:07:32> /opt/elasticsearch-node3/config
root># cat /opt/elasticsearch-node2/config/elasticsearch.yml
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#cluster
cluster.name: "es-cluster"
node.name: "es-node2"
node.master: true
node.data: true
http.enabled: true
PS:node.name
以上是关于Elasticsearch 5 集群的主要内容,如果未能解决你的问题,请参考以下文章
elasticsearch代码片段,及工具类SearchEsUtil.java
Elasticsearch - 尚硅谷(5. Elasticsearch 环境)学习笔记
elasticsearch7.5.0+kibana-7.5.0+cerebro-0.8.5集群生产环境安装配置及通过elasticsearch-migration工具做新老集群数据迁移