Elasticsearch集群搭建

时间:2022-12-18 15:55:25

现有两部机器:192.168.31.86,192.168.31.87

 
参考以往博文对Elasticsearch进行配置完成:http://www.cnblogs.com/zhongshengzhen/p/elasticsearch_mysql.html
1、注意事项
集群需要在同一网段
 
2、配置elasticsearch.yml
cluster.name :配置es的集群名称,不同的集群用名字来区分, 如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。
 
node.name:节点名称,一部服务器一个节点,分别为node-1,node-2,node-3 。
 
http.port :服务端口,一般默认是9200,如果在同一部服务器上面配置多个elasticsearch服务,则端口需要不同
 
discovery.zen.ping.unicast.hosts:自动检索可用节点,设置了这个参数才会自动检测可用的节点。 同一集群名下,elasticsearch会自动去发现其他的节点。
 
具体配置:
192.168.31.86:
cluster.name: mycluster
node.name: node-1
#指定了该节点可能成为 master 节点,还可以是数据节点

node.master: true

node.data: true
network.host: 192.168.31.86
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["192.168.31.86", "192.168.31.87"]
 
192.168.31.87:
cluster.name: mycluster
node.name: node-2
#指定了该节点可能成为 master 节点,还可以是数据节点

node.master: true

node.data: true
network.host: 192.168.31.87
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["192.168.31.86", "192.168.31.87"]
 
然后分别启动两个节点的ES服务。
 
安装Head

Head是一个用来监控Elasticsearch状态的客户端插件。
 
检查两个节点的情况:
192.168.31.86:
[zsz@zsz elasticsearch-2.3.2]$ curl '192.168.31.86:9200/_cat/indices?v'

health status index    pri rep docs.count docs.deleted store.size pri.store.size

green  open   myindex    5   1        163            0      294kb          147kb

green  open   customer   5   1          0            0      1.5kb           795b 
 
192.168.31.87:
[zsz@VS-SUPSV-TEST1 elasticsearch-2.3.2]$ curl '192.168.31.87:9200/_cat/indices?v'

health status index    pri rep docs.count docs.deleted store.size pri.store.size

green  open   myindex    5   1        163            0      294kb          147kb

green  open   customer   5   1          0            0      1.5kb           795b 
 
发现是GREEN的绿色健康状态,说明备份被分配完成,可用。集群配置完成。
 
测试集群中两个节点的查询情况:
[zsz@zsz ~]$ curl '192.168.31.87:9200/myindex/_search?q=ghdfdfgddfg'

{"took":13,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.49305484,"hits":[{"_index":"myindex","_type":"mytype","_id":"AVeoqjX_-bv4eY7Nx-xL","_score":0.49305484,"_source":{"pk":14,"user_pk":10,"media_pk":2,"topic_pk":0,"access_source_pk":0,"p_channel_pk":0,"c_channel_pk":0,"title":"ghdfdfgddfg","cover_url":{"S":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_2.jpg"],"L":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_1.jpg"]},"summary":"\"好奇号\"发回火星最新影像 地貌酷似地球","read_count":0,"like_count":0,"share_count":0,"favorites_count":0,"check_status":3,"release_status":1,"isurgent":1,"created_at":"2016-08-15T14:07:19.000+08:00","updated_at":"2016-10-04T10:11:56.000+08:00"}}]}}
 
[zsz@zsz ~]$ curl '192.168.31.86:9200/myindex/_search?q=ghdfdfgddfg'

{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.49305484,"hits":[{"_index":"myindex","_type":"mytype","_id":"AVeoqjX_-bv4eY7Nx-xL","_score":0.49305484,"_source":{"pk":14,"user_pk":10,"media_pk":2,"topic_pk":0,"access_source_pk":0,"p_channel_pk":0,"c_channel_pk":0,"title":"ghdfdfgddfg","cover_url":{"S":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_2.jpg"],"L":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_1.jpg"]},"summary":"\"好奇号\"发回火星最新影像 地貌酷似地球","read_count":0,"like_count":0,"share_count":0,"favorites_count":0,"check_status":3,"release_status":1,"isurgent":1,"created_at":"2016-08-15T14:07:19.000+08:00","updated_at":"2016-10-04T10:11:56.000+08:00"}}]}}
 
测试192.168.31.86节点对数据修改后,两个节点的数据是否同步
 
[zsz@zsz ~]$ curl -XPOST '192.168.31.86:9200/myindex/mytype/AVeoqjX_-bv4eY7Nx-xL/_update?pretty' -d '{        

          "doc": { "summary ": "TEST UPDATE DATA" }

        }'

{

  "_index" : "myindex",

  "_type" : "AVeoqjX_-bv4eY7Nx-xL",

  "_id" : "_update",

  "_version" : 1,

  "_shards" : {

    "total" : 2,

    "successful" : 2,

    "failed" : 0

  },

  "created" : true

}
 
[zsz@zsz ~]$ curl '192.168.31.86:9200/myindex/_search?q=ghdfdfgddfg'

{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.44561866,"hits":[{"_index":"myindex","_type":"mytype","_id":"AVeoqjX_-bv4eY7Nx-xL","_score":0.44561866,"_source":{"pk":14,"user_pk":10,"media_pk":2,"topic_pk":0,"access_source_pk":0,"p_channel_pk":0,"c_channel_pk":0,"title":"ghdfdfgddfg","cover_url":{"S":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_2.jpg"],"L":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_1.jpg"]},"summary":"\"好奇号\"发回火星最新影像 地貌酷似地球","read_count":0,"like_count":0,"share_count":0,"favorites_count":0,"check_status":3,"release_status":1,"isurgent":1,"created_at":"2016-08-15T14:07:19.000+08:00","updated_at":"2016-10-04T10:11:56.000+08:00","summary ":"TEST UPDATE DATA"}}]}}
 
[zsz@zsz ~]$ curl '192.168.31.87:9200/myindex/_search?q=ghdfdfgddfg'

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.44561866,"hits":[{"_index":"myindex","_type":"mytype","_id":"AVeoqjX_-bv4eY7Nx-xL","_score":0.44561866,"_source":{"pk":14,"user_pk":10,"media_pk":2,"topic_pk":0,"access_source_pk":0,"p_channel_pk":0,"c_channel_pk":0,"title":"ghdfdfgddfg","cover_url":{"S":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_2.jpg"],"L":["http://ochz1y8tu.bkt.clouddn.com/lg-6Q2Cy2yjF_SqLSo5YaKJKx2E520160829102601_1.jpg"]},"summary":"\"好奇号\"发回火星最新影像 地貌酷似地球","read_count":0,"like_count":0,"share_count":0,"favorites_count":0,"check_status":3,"release_status":1,"isurgent":1,"created_at":"2016-08-15T14:07:19.000+08:00","updated_at":"2016-10-04T10:11:56.000+08:00","summary ":"TEST UPDATE DATA"}}]}}
 
在192.168.31.86机器上更新的数据,分别查询192.168.31.86和192.168.31.87,发觉数据是同步了的。elasticsearch集群自我完成了实时同步。
 
 
常见问题:
1、问题报错:no rute to host
解决方案:由于端口没开启,处理办法
(1)关闭服务器防火墙,不推荐。
(2)开放端口:
/sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 9300 -j ACCEPT
/etc/rc.d/init.d/iptables save

/etc/rc.d/init.d/iptables restart

/etc/init.d/iptables status 
 
 
 
 
 

Elasticsearch集群搭建的更多相关文章

  1. elasticsearch集群搭建实例

    elasticsearch集群搭建实例 下个月又开始搞搜索了,几个月没动这块还好没有落下. 晚上在自己虚拟机上搭建了一个简易搜索集群,分享一下. 操作系统环境: Red Hat 4.8.2-16 el ...

  2. 和我一起打造个简单搜索之ElasticSearch集群搭建

    我们所常见的电商搜索如京东,搜索页面都会提供各种各样的筛选条件,比如品牌.尺寸.适用季节.价格区间等,同时提供排序,比如价格排序,信誉排序,销量排序等,方便了用户去找到自己心里理想的商品. 站内搜索对 ...

  3. Elasticsearch集群搭建及使用Java客户端对数据存储和查询

    本次博文发两块,前部分是怎样搭建一个Elastic集群,后半部分是基于Java对数据进行写入和聚合统计. 一.Elastic集群搭建 1. 环境准备. 该集群环境基于VMware虚拟机.CentOS ...

  4. ElasticStack之Elasticsearch集群搭建

    需搭建服务器环境 操作系统 Host:port node 1 CentOS 7.2.1511 11.1.11.127:9200 node1 2 CentOS 7.2.1511 11.1.11.128: ...

  5. CentOS 7下ElasticSearch集群搭建案例

    最近在网上看到很多ElasticSearch集群的搭建方法,本人在这人使用Elasticsearch5.0.1版本,介绍如何搭建ElasticSearch集群并安装head插件和其他插件安装方法. 一 ...

  6. Es学习第十课,ElasticSearch集群搭建

    前面几课我们已经把ES的基本概念和查询了解了,大家知道ES的核心优势就是天生支持分布式,所以,这课我们专门讲讲怎么搭建实现ES的集群部署. ES分布式原理 1.es分布式概念 主分片(Primary ...

  7. elasticsearch 集群搭建及启动常见错误

    1.系统环境 三台服务器(最好是单数台,跟master选举方式有关),确保机器互相ping的通,且都需要装了jdk 8环境,机器IP和 elasticsearch 的节点名称如下: cluster n ...

  8. Elasticsearch集群搭建教程及生产环境配置

    Elasticsearch 是一个极其强大的搜索和分析引擎,其强大的部分在于能够对其进行扩展以获得更好的性能和稳定性. 本教程将提供有关如何设置 Elasticsearch 集群的一些信息,并将添加一 ...

  9. elasticsearch集群搭建报错: not enough master nodes discovered during pinging

    自己用一台 阿里云 服务器 搭建ES集群的时候,总是报上面的问题. 而且两个ES服务都是报同样的问题.自己的配置文件如下: es服务1配置文件 cluster.name: elasticsearch ...

随机推荐

  1. Ext.Net 学习随笔 003 Panel基本使用

    Panel() 1.使用Content和Html属性设置Panel内容 前台View代码 @(X.Panel() .ID("panel1") .Width() .Height() ...

  2. 【BZOJ-3122】随机数生成器 BSGS

    3122: [Sdoi2013]随机数生成器 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1362  Solved: 531[Submit][Sta ...

  3. 浅谈C++的this指针

    之所以写这篇文章,主要是为了回答网友 zhancaihua123同学的下面几个问题: father* p=new son;p->disp(...);father是父类,son是子类.disp是一 ...

  4. PHP+socket游戏数据统计平台发包接包类库

    <?php /** * @title: PHP+socket游戏数据统计平台发包接包类库 * @version: 1.0 * @author: perry <perry@1kyou.com ...

  5. HDNOIP201206施工方案

    HDNOIP201206施工方案 难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 c国边防军在边境某处的阵地是由n个地堡组成的. ...

  6. android在桌面弹出一个窗口

    android在桌面弹出一个窗口 遇到了这种需求,要和iPhone一样的效果. 下面是简单实现功能,优化和美化部分,有时间慢慢搞. 方法应该有不少吧,我用的是弹出一个activity,将这个activ ...

  7. selenium 学习笔记 ---新手学习记录(6) 问题总结(java)

    1.查看网页的cookie信息 //查看cookie 登录后的cookie Set<Cookie> setcoke= driver.manage().getCookies(); for(C ...

  8. ELK 环境搭建4-Kafka &plus; zookeeper

    一.安装前准备 1.节点 192.168.30.41 192.168.30.42 192.168.30.43 2.操作系统: Centos7.5 3.安装包 a.java8: jdk-8u181-li ...

  9. android AsyncHttpClient使用

    1.www.github.com下载jar包 loopj/android-async-http 将下载好的文件导入项目中 2.main.xml <?xml version="1.0&q ...

  10. vuex的使用二

    1.先看项目的目录结构 2.在main.js里需要引入store这个文件并挂在实例上 import store from './store/store' ............ new Vue({ ...