ES集群构建(本人亲测有效)

一、下载


wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz

二、解压源文件

    tar -vxf elasticsearch-5.6.16.tar.gz


三、切换普通用户


    因为elasticsearch默认不允许root用户启动
    1、创建用户:elasticsearch

    [root@iZbp1bb2egi7w0ueys548pZ bin]# adduser elasticsearch


      2、创建用户密码,需要输入两次

    [root@iZbp1bb2egi7w0ueys548pZ bin]# passwd elasticsearch


      3、将对应的文件夹权限赋给该用户

    [root@iZbp1bb2egi7w0ueys548pZ local]# chown -R elasticsearch elasticsearch-6.0.0


      4、切换至elasticsearch用户

    [root@iZbp1bb2egi7w0ueys548pZ etc]# su elasticsearch

四、配置主节点


    1、修改配置文件
    vi /elasticsearch/conf/elasticsearch.yml
 

    #集群名称,主从节点必须一致,才能保证为同一个集群
    cluster.name: elastic-cluster
    #节点名称
    node.name: master
    #该节点有机会成为master节点
    node.master: true
    #节点是否为数据节点
    node.data: false
    #列表主要由集群中那些 Master-eligible(node.master设置为 true(默认)的节点) 的节点组成。
    discovery.zen.ping.unicast.hosts: ["ht.es1.com","ht.es2.com"]
    #选举主节点时,最少参与选举的Master-eligible的个数。一般设置为 (主节点个数/2)+1
    discovery.zen.minimum_master_nodes: 1
    #设置是否打开多播发现节点,默认是true。
    discovery.zen.ping.multicast.enabled:true
    #数据目录
    path.data: /usr/local/soft/elasticsearch-master/data/
    #日志目录
    path.logs: /usr/local/soft/elasticsearch-master/logs/
    #锁定内存,避免和swap去交互,导致性能下降
    bootstrap.memory_lock: true
    #设置是否压缩tcp上交互传输的数据
    transport.tcp.compress: true
    //绑定ip
    network.host: 192.168.162.72
    //api访问端口设置
    http.port: 9200
    //节点内部通讯的tcp端口
    transport.tcp.port: 9300
    //允许跨域
    http.cors.enabled: true
    //允许跨域的节点
    http.cors.allow-origin: "*"

    2、启动服务 -d 后台启动

    ./elasticsearch/bin/elasticsearch -d 

报错:ERROR: [1] bootstrap checks failed
解决方案:
    需要设置下系统配置文件,首先要切换到root用户,接着做以下修改:
    1、修改/etc/security/limits.conf    文件最后添加以下内容:
  

* soft nofile 65536
* hard nofile 65536
* soft nproc 32000
* hard nproc 32000
* hard memlock unlimited
* soft memlock unlimited


    2、修改/etc/systemd/system.conf    分别修改以下内容:
    

DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity

    3、执行以下操作,立即生效
    /bin/systemctl daemon-reload
    
    4、max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

    解决:切换到root用户修改配置sysctl.conf
         vi /etc/sysctl.conf
    添加下面配置:
         vm.max_map_count=262144
    并执行命令:
         sysctl -p


五、配置从节点1

 

1、vi /elasticsearch/conf/elasticsearch.yml

    

cluster.name: elastic-cluster
node.name: slave1
path.data: /usr/local/soft/elasticsearch-slave1/data/
path.logs: /usr/local/soft/elasticsearch-slave1/logs/
bootstrap.memory_lock: true
network.host: 192.168.162.72
http.port: 9201
//主节点地址,若有多个,则配置多个
discovery.zen.ping.unicast.hosts: ["192.168.162.72"]
http.cors.enabled: true
http.cors.allow-origin: "*"


2、启动服务 -d 后台启动

./elasticsearch/bin/elasticsearch -d 

六、配置从节点2

 

1、vi /elasticsearch/conf/elasticsearch.yml

    

cluster.name: elastic-cluster
node.name: slave2
path.data: /usr/local/soft/elasticsearch-slave2/data/
path.logs: /usr/local/soft/elasticsearch-slave2/logs/
bootstrap.memory_lock: true
network.host: 192.168.162.72
http.port: 9202
//主节点地址,若有多个,则配置多个
discovery.zen.ping.unicast.hosts: ["192.168.162.72"]
http.cors.enabled: true
http.cors.allow-origin: "*"

2、启动服务 -d 后台启动
    

./elasticsearch/bin/elasticsearch -d 

七、配置jvm.options

 

默认配置
-Xms2g
-Xmx2g
当系统内存不足时,需要调小这个值。否则启动多个节点时,由于内存不足,om会自动kill掉进程。
-Xms512m
-Xmx512m

八、配置elasticsearch-head(es可视化界面)

 

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
open http://localhost:9100/


 注意:
 当启动主点后,端口9200和9300同时启动
9200作为Http协议,节点和外部通讯,调用restful接口用9200。
9300作为Tcp协议,ES集群节点之间的通讯使用。
springboot集成ES的时候需要使用的9300 端口

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值