Elasticsearch安装与环境配置

Elasticsearch安装与环境配置

  • 确保机器上已经安装了jdk7以上版本
  • 下载:官网下载地址:https://www.elastic.co/downloads/elasticsearch
  • 将下载后的文件加压到/opt/ela目录下
  • 进入到${Elasticsearch_HOME}/bin目录下,执行./elasticsearch -d脚本,-d表示后台执行

安装成功后,在浏览器访问http://localhost:9200/,返回以下结果:

{
  "name" : "Airborne",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.1.0",
    "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
    "build_timestamp" : "2015-11-18T22:40:03Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

从返回的结果可以看出默认的集群名称为:elasticsearch

Elasticsearch环境配置

Elasticsearch的配置文件是${Elasticsearch_HOME}/config/elasticsearch.yml,常用配置的含义如下:

  • cluster.name:定义集群名称,默认是elasticsearch
  • node.name:定义节点名称
    -node.master:此节点是否为master,master作用就是做协调,协调集群的状态,数据的读取时由集群的各个节点共同完成的,但是数据的修改只能master完成
  • node.data:此节点是否为子节点,功能就是存储数据,存储索引之类的
  • index.number_of_replicas:定义数据副本的数量,这里设为1
  • path.data:数据的存放路径
  • transport.tcp.port:tcp端口号
  • http.port:http端口号
  • discovery.zen.minimum_master_nodes:设置这个集群,有多少个节点有master候选资格,如果集群较大官方建议为2-4个
  • discovery.zen.ping.timeout:集群中自动发现其他节点的超时时间,如果网络延迟较大,建议设置长一点,防止误判
  • discovery.zen.ping.unicast.hosts:设置集群中master集群初始化列表,这个数组里的机器将被自动发现加入集群

比如一个master节点的配置如下:


cluster.name: test_cluster1    ##cluster名
node.name: "test_node_196"    ##节点名称
node.master: true   ##是否是master节点
node.data: true   ##该节点上是否保存数据
index.number_of_replicas: 1   ##备份的数量,这里设为1
path.data: /opt/esdata    ##该节点上数据存储的path
transport.tcp.port: 9300   ##tcp的端口号
http.port: 9200    ##http的端口号
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.timeout: 3s    ##节点间自动发现的响应时间
discovery.zen.ping.unicast.hosts: ["localhost"]    ##节点间自动发现,master节点为localhost

注意:

  • 为了测试,多个node可以在同一台服务器上启动,但通常一个服务器只放一个node
  • 系统启动时,node会使用广播来发现一个现有的cluster,并且试图加入该cluster
  • 配置文件中的冒号后要加空格,否则启动es时会报load配置文件发生错误
  • 当将一个节点的index.number_of_replicas从0变为1时,ES中现有的索引的分片仍然是没有备份的,但修改后新建的索引的分片都有一个备份
posted @ 2018-01-18 17:46  木易森林  阅读(1143)  评论(0编辑  收藏  举报