1. 程式人生 > >Centos7.4 安裝elasticsearch6.1.3集群部署

Centos7.4 安裝elasticsearch6.1.3集群部署

ES elasticsearch

Centos7.4 安裝elasticsearch6.1.3集群部署


安裝elasticsearch


1.依賴環境安裝

這裏使用的java 是1.8.0_77的版本.使用的是rpm 安裝包的形式進行部署安裝 。

配置環境變量


[root@node1 ~]# cat .bash_profile
export JAVA_HOME=/usr/java/jdk1.8.0_77/ # JAVA_HOME變兩個路徑
export JAVA_BIN=/usr/java/jdk1.8.0_77/bin
export PATH=${JAVA_HOME}bin:$PATH

檢測java環境安裝是否正常


[root@node1 ~]# java -version

java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)


2.elasticsearch使用的是6.1.3版本。elasticsearch-6.1.3.tar.gz


[root@node1 local]# tar -zxvf elasticsearch-6.1.3.tar.gz
[root@node1 local]# ls
bin elasticsearch-6.1.3 elasticsearch-6.1.3.tar.gz etc games include lib lib64 libexec sbin share src

修改配置文件


node1
[root@node1 local]# cd node1/config/
[root@node1 config]# cat elasticsearch.yml | grep -v "^#"
cluster.name: elasticsearch #集群的名稱
node.name: node1 #節點的名稱
bootstrap.memory_lock: false #另一種選擇是在Linux / Unix系統上使用mlockall或在Windows上使用 VirtualLock,以嘗試將進程地址空間鎖定到RAM中,防止任何Elasticsearch 內存被換出。

bootstrap.system_call_filter: false #為禁用系統調用過濾器false
network.host: 133.1.11.39 #綁定到回送地址

http.port: 9200 #設置對外服務的http端口,默認為9200
discovery.zen.ping.unicast.hosts: ["133.1.11.39","133.1.11.39:9202","133.1.11.39:9203"]
discovery.zen.minimum_master_nodes: 2


node2
cluster.name: elasticsearch
node.name: node2
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 133.1.11.39

http.port: 9202
discovery.zen.ping.unicast.hosts: ["133.1.11.39","133.1.11.39:9202","133.1.11.39:9203"]
discovery.zen.minimum_master_nodes: 2

node3
cluster.name: elasticsearch
node.name: node3
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 133.1.11.39

http.port: 9203
discovery.zen.ping.unicast.hosts: ["133.1.11.39","133.1.11.39:9202","133.1.11.39:9203"]
discovery.zen.minimum_master_nodes: 2


[root@node1 config]# vim jvm.options 
-Xms512m
-Xmx512m


3.需要修改的配置參數

vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

vim /etc/security/limits.d/90-nproc.conf
* soft nproc 2048

vim /etc/sysctl.conf
vm.max_map_count=655360
sysctl -p

4.啟動elasticsearch 不能使用root 用戶需要進行創建用戶

[root@node1 ~]# groupadd es
[root@node1 ~]# useradd es -g es -p es
[root@node1 ~]# chown -R es:es /usr/local/node1


啟動elasticsearch


[root@node1 bin]# ./elasticsearch -d


5.進行訪問測試


[root@node1 bin]# curl http://133.1.11.39:9200
{
"name" : "node1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dJo2cKFfSO-M-qwMF9upjg",
"version" : {
"number" : "6.1.3",
"build_hash" : "af51318",
"build_date" : "2018-01-26T18:22:55.523Z",
"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"
}



安裝head 插件


1.安裝NodeJS


[root@node1 ~]# wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.5.0-linux-x64.tar.gz
[root@node1 ~]#tar -zxvf node-v4.5.0-linux-x64.tar.gz -C /usr/local

配置環境變量
export NODE_HOME=/usr/local/node-v4.5.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin/
export NODE_PATH=$NODE_HOME/lib/node_modules
[root@node1 ~]#source /etc/profile

2.安裝npm


[root@node1 ~]# npm install -g cnpm --registry=https://registry.npm.taobao.org

3.使用npm安裝grunt


/usr/local/node-v4.5.0-linux-x64/bin/grunt -> /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt/bin/grunt
[email protected] /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected])

[root@node1 ~]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
/usr/local/node-v4.5.0-linux-x64/bin/grunt -> /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli/bin/grunt
[email protected] /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
└── [email protected] ([email protected]

4.版本確認


[root@node1 ~]# node -v
v4.5.0
[root@node1 ~]# npm -v
2.15.9
[root@node1 ~]# grunt -version
grunt-cli v1.2.0

5.下載head插件源碼


[root@node1 ~]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
[root@node1 ~]# unzip master.zip -d /usr/local/

6.下載依賴

[root@node1 elasticsearch-head-master]# npm install -g grunt-cli 
/usr/local/node-v4.5.0-linux-x64/bin/grunt -> /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli/bin/grunt
[email protected] /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])


[root@node1 elasticsearch-head-master]# grunt -version
grunt-cli v1.2.0
[root@node1 elasticsearch-head-master]# npm install

二. 配置ElasticSearch

停止ElasticSearch


[root@node1 local]# jps
28516 Jps
12072 Elasticsearch

1.配置 ElasticSearch,使得HTTP對外提供服務

node1 上面配置
[root@node1 ]# vim config/elasticsearch.yml
# 增加新的參數,這樣head插件可以訪問es。設置參數的時候:後面要有空格
http.cors.enabled: true
http.cors.allow-origin: "*"

2.修改head插件配置文件


[root@node1 elasticsearch-head-master]# vim Gruntfile.js
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
修改修改連接地址:_site/app.js
[root@node1 elasticsearch-head-master]# vim _site/app.js
_node_handler: function(data) {
if(data) {
// this.prefs.set("app-base_uri", this.cluster.base_uri);
this.prefs.set("app-base_uri" )|| "http://133.1.11.39:9200";
if(data.version && data.version.number)
this.cluster.setVersion(data.version.number);

3.啟動elasticsearch,head


[root@node1 bin]# ./elasticsearch -d #分別啟動3個節點
[root@node1 elasticsearch-head-master]# nohup grunt server &

4.註意坑


如果出現集群無法鏈接
請註意刪除node1 下面/usr/local/node1/data 下面的目錄,不然造成數據不統一 不能呢鏈接head 插件




Centos7.4 安裝elasticsearch6.1.3集群部署