Elasticsearch 5 集羣

1 準備工做

/etc/profile添加vim高亮顯示css

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>\\$ "html


服務器信息:
java

   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),所以建議提早安裝好。node


驗證版本:
swift

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 源

導入簽名:vim

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 相關產品均須要使用這個源。markdown

1.3 操做系統配置

官方提供了生產環境下 Elasticsearch 所在操做系統的相關建議,詳見這裏cors

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]
解決辦法:
一、虛擬內存設置,編輯 /etc/sysctl.conf ,追加:
vm.max_map_count=262144
二、修改文件句柄限制,編輯 /etc/security/limits.conf ,追加:
root># vim /etc/security/limits.conf 
*    soft nofile 65536
*    hard nofile 65536

問題四:
elasticsearch5.0啓動失敗,出現以下提示:
一、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

二、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/ root@192.168.91.222:/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/ root@192.168.91.222:/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

相關文章
相關標籤/搜索