虚拟机搭建Elasticsearch2.4.1集群

本文详细介绍了如何使用VirtualBox和Ubuntu 16.04搭建Elasticsearch 2.4.1集群,包括配置虚拟机网络、安装Elasticsearch、配置集群参数、安装管理插件等关键步骤。

虚拟机工具:VirtualBox

Ubuntu 镜像:ubuntu-16.04.2-server-amd64.iso 下载地址(http://101.96.8.142/releases.ubuntu.com/16.04.2/ubuntu-16.04.2-server-amd64.iso)

Elasticsearch 版本:2.4.1 下载地址(https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.1/elasticsearch-2.4.1.tar.gz)

JDK:1.8 +


配置虚拟机和网络

  1. 打开 VirtualBox 安装 Ubuntu镜像 (步骤略)
  2. 设置虚拟机上网方式为“桥接网卡”,这样,虚拟机可以通过物理机上网。,如图:
  3. 为了区分多台虚拟机,我将虚拟机重命名,如第一台:ubuntu01-192.168.6.4 ,如图:
  4. 将虚拟机自动获取ip改成静态ip。 打开虚拟机,输入用户名,密码。输入命令ifconfig获取自动获取ip
  5. 修改成静态ip。输入命令:sudo vi /etc/network/interfaces  输入密码,进入修改页面,其中:gateway 和 dsn-nameservers是必须要配置的,dsn-nameservers不配的话上不了外网。修改如图:
  6. 保存并重启网络,输入:sudo /etc/init.d/networking restart 
  7. 复制虚拟机镜像。
  8. 其中,副本名称改成新的虚拟机名称
配置Elasticsearch集群
  1. 将下载好的elasticsearch-2.4.1.tar.gz 解压。(命令:tar -zxvf elasticsearch-2.4.1.tar.gz)
  2. elasticsearch为了防止集群发生脑裂,elasticsearch要求节点只少2n+1台,我搭建了三台。
  3. 分别打开三台虚拟机,进入elasticsearch-2.4.1/config 下,编辑elasticsearch.yml。
            ubuntu01-192.168.6.4节点

cluster.name: my-application      //cluster.name:为集群名称,同一集群cluster.name必须一样,加入新节点时可以自动加入该集群

node.name: node-1                  //节点名称  不同几点名称要不一致

network.host: 192.168.6.4        //该节点ip

http.port: 9200                        //该节点端口,不同节点端口要不一致

discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"]    //设置新节点被启动时能够发现的主节点列表(主要用于不同网段机器连接)

ubuntu02-192.168.6.7节点

cluster.name: my-application 
node.name: node-2 
network.host: 192.168.6.7
http.port: 19200 
discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"] 


ubuntu03-192.168.6.8节点

cluster.name: my-application 
node.name: node-3 
network.host: 192.168.6.8
http.port: 29200 
discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"] 

          4. 启动每台elasticsearch , 进入 elasticsearch/bin下,执行./elasticsearch -d 

          5. ubuntu01-192.168.6.4节点执行curl -XGET "http://192.168.6.4:9200"

返回:

 {
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "MIRxeE5ZTGe1fhf3HbeHHQ",
  "version" : {
    "number" : "2.4.1",
    "build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
    "build_timestamp" : "2016-09-27T18:57:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"
}


ubuntu02-192.168.6.7节点执行curl -XGET "http://192.168.6.7:19200"

返回:
 {
  "name" : "node-2",
  "cluster_name" : "my-application",
  "cluster_uuid" : "MIRxeE5ZTGe1fhf3HbeHHQ",
  "version" : {
    "number" : "2.4.1",
    "build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
    "build_timestamp" : "2016-09-27T18:57:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"

}

ubuntu01-192.168.6.8节点执行curl -XGET "http://192.168.6.8:29200"

返回:
 {
  "name" : "node-3",
  "cluster_name" : "my-application",
  "cluster_uuid" : "MIRxeE5ZTGe1fhf3HbeHHQ",
  "version" : {
    "number" : "2.4.1",
    "build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
    "build_timestamp" : "2016-09-27T18:57:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"

}


 说明三个节点es可以正常运行。

         6.  安装es集群管理插件Elasticsearch-head

              进入其中一台虚拟机,如ubuntu01-192.168.6.4节点,进入elasticsearch/bin下,执行./plugin install mobz/elasticsearch-head

             按装完成,访问http://192.168.6.4:9200/_plugin/head/

              看到如下:

       7.  或安装插件kopf,进入elasticsearch/bin下,执行./plugin install lmenezes/elasticsearch-kopf  ,访问http://192.168.6.4:9200/_plugin/kopf  会更美观一些。

       8. 试一下分片。

        PUT /http://192.168.6.4:9200/fristindex

          {

  "settings": {

    "number_of_shards": 3,   //分片个数

    "number_of_replicas": 2 // 每个分片对应的备份数量

  }

}   

返回

{
    "acknowledged": true
}     

刷新http://192.168.6.4:9200/_plugin/head/    便可以看到效果


         9. 添加新的节点  只需要定义 cluster.name,node.name,network.host,http.port四个属性即可,(discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"] 保持不变)。启动es刷新http://192.168.6.4:9200/_plugin/head/    便可以看到效果




写博客真是个累活,累死我了~~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值