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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7.4 安装elasticsearch6.1.3集群部署相关的知识,希望对你有一定的参考价值。

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


安装elasticsearch


1.依赖环境安装

这里使用的java 是1.8.0_77的版本.使用的是rpm 安装包的形式进行部署安装 。

配置环境变量


[[email protected] ~]# 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环境安装是否正常


[[email protected] ~]# 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


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

修改配置文件


node1
[[email protected] local]# cd   node1/config/
[[email protected] 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


[[email protected] 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 用户需要进行创建用户

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


启动elasticsearch


[[email protected] bin]# ./elasticsearch -d


5.进行访问测试


[[email protected] 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


[[email protected] ~]# wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.5.0-linux-x64.tar.gz
[[email protected] ~]#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
[[email protected] ~]#source /etc/profile

2.安装npm


[[email protected] ~]#  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])

[[email protected] ~]#  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.版本确认


[[email protected] ~]# node -v
v4.5.0
[[email protected] ~]# npm -v
2.15.9
[[email protected] ~]#  grunt -version
grunt-cli v1.2.0

5.下载head插件源码


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

6.下载依赖

[[email protected] 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])


[[email protected] elasticsearch-head-master]#  grunt -version
grunt-cli v1.2.0
[[email protected] elasticsearch-head-master]# npm install

二. 配置ElasticSearch

停止ElasticSearch


[[email protected] local]# jps
28516 Jps
12072 Elasticsearch

1.配置 ElasticSearch,使得HTTP对外提供服务

node1 上面配置
[[email protected] ]# vim config/elasticsearch.yml
# 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格
http.cors.enabled: true
http.cors.allow-origin: "*"

2.修改head插件配置文件


[[email protected] elasticsearch-head-master]# vim Gruntfile.js
connect: {
                       server: {
                               options: {
                                       hostname: '0.0.0.0',
                                       port: 9100,
                                       base: '.',
                                       keepalive: true
                               }
                       }
               }
  修改修改连接地址:_site/app.js
[[email protected] 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


[[email protected] bin]# ./elasticsearch -d #分别启动3个节点
[[email protected] elasticsearch-head-master]# nohup  grunt  server &

4.注意坑


如果出现集群无法链接
请注意删除node1 下面/usr/local/node1/data 下面的目录,不然造成数据不统一 不能呢链接head 插件




以上是关于Centos7.4 安装elasticsearch6.1.3集群部署的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7.4到Elasticsearch一路坑

Elasticsearch 7.6集群搭建(基于Centos7.4)

elasticsearch的安装部署

Centos7.4部署配置Elasticsearch5.6集群

CentOS7.4到Elasticsearch一路坑(零)

CentOS7.4到Elasticsearch一路坑