Linux下Elasticsearch环境搭建

一、elasticsearch安装并运行

1.下载并解压即可

2.进入elasticsearch的bin目录

3.执行    ./elasticsearch  命令即可运行

4.浏览器中运行:http://ip:9200/    如果出现以下画面表示运行成功

 

二、集群搭建

1.以本人为例,在三台机器上安装了es,来搭建集群

2进入elasticsearch的config目录,打开并编辑elasticsearch.yml

# ======================== Elasticsearch Configuration =========================

# NOTE: Elasticsearch comes with reasonable defaults for most settings.

#       Before you set out to tweak and tune the configuration, make sure you

#       understand what are you trying to accomplish and the consequences.

#

# The primary way of configuring a node is via this file. This template lists

# the most important settings you may want to configure for a production cluster.

#

# Please see the documentation for further information on configuration options:

# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>

#

# ---------------------------------- Cluster -----------------------------------

#

# Use a descriptive name for your cluster:

#三台电脑cluster.name:保持一致

  cluster.name: my-askingdata

#

# ------------------------------------ Node ------------------------------------

#

# Use a descriptive name for the node:

#三台电脑的node.name不能一样

  node.name: node-1

#

# Add custom attributes to the node:

#

#  node.rack: r1

#

# ----------------------------------- Paths ------------------------------------

#

# Path to directory where to store the data (separate multiple locations by comma):

#

# path.data: /path/to/data

#

# Path to log files:

#

# path.logs: /path/to/logs

#

# ----------------------------------- Memory -----------------------------------

#

# Lock the memory on startup:

#

# bootstrap.mlockall: true

#

# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory

# available on the system and that the owner of the process is allowed to use this limit.

#

# Elasticsearch performs poorly when the system is swapping the memory.

#

# ---------------------------------- Network -----------------------------------

#

# Set the bind address to a specific IP (IPv4 or IPv6):

#   ip

  network.host: 192.168.1.106

#

# Set a custom port for HTTP:

#端口

  http.port: 9200

#

# For more information, see the documentation at:

# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>

#

# --------------------------------- Discovery ----------------------------------

#

# Pass an initial list of hosts to perform discovery when new node is started:

# The default list of hosts is ["127.0.0.1", "[::1]"]

#写入三台电脑的ip

  discovery.zen.ping.unicast.hosts: ["192.168.1.106", "192.168.1.108","192.168.1.109"]

#

# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):

#

三、head插件安装和使用

1.在es的plugin 目录下新建head目录

2.下载head并解压进plugin/head目录即可

3.分别启动三台 机器的es

4. 打开http://192.168.1.106:9200/_plugin/head/   

 

 

四、索引的操作

1、索引文档的创建

将如下一条歌曲信息的数据提交到ES中创建索引:

[plain] view plain copy

url:http://127.0.0.1:9200/song001/list001/1  

data:{"number":32768,"singer":"杨坤","size":"5109132","song":"今夜二十岁","tag":"中国好声音","timelen":319}  

索引名字是:song001;

索引的类型是:list001;

本记录的id是:1

返回的信息可以看到创建是成功的,并且版本号是1;ES会对记录修改进行版本跟踪,第一次创建记录为1,同一条记录每修改一次就追加1。

至此一条记录就提交到ES中建立了索引,注意HTTP的方法是PUT,不要选择错了。

2、索引文档的查询

根据索引时的ID查询的文档的RESTful接口如下

url:http://127.0.0.1:9200/song001/list001/1
HTTP方法采用GET的形式。

3、索引文档的更新

根据索引时的ID更新的文档的内容其RESTful接口如下

url:http://127.0.0.1:9200/song001/list001/1
HTTP方法采用PUT的形式。

将歌手名由“杨坤”改成“杨坤独唱”;

结果中的version字段已经成了2,因为我们这是是修改,索引版本递增;created字段是false,表示这次不是新建而是更新。

更新接口与创建接口完全一样,ES会查询记录是否存在,如果不存在就是创建,存在就是更新操作。

 

 

4、索引文档的删除

根据索引时的ID更新的文档的内容其RESTful接口如下

url:http://127.0.0.1:9200/song001/list001/1
HTTP方法采用DELETE的形式。

删除过后,再通过查询接口去查询将得不到结果。

总结:

增删改查的RESTful接口URL形式:http://localhost:9200/<index>/<type>/[<id>]

增删改查分别对应:HTTP请求的PUT、GET、DELETE方法。PUT调用是如果不存在就是创建,已存在是更新。

 

快速bulk插入数据

使用插件elasticsearch-reindexing

下载     https://github.com/codelibs/elasticsearch-reindexing

执行命令在线安装,不用下载   $ $ES_HOME/bin/plugin install org.codelibs/elasticsearch-reindexing/2.1.1

 

在查询时出现max_result_window错误时,

执行以下命令,红字要>=文档总数

curl -XPUT "http://192.168.1.106:9200/shark/_settings" -d '{ "index" : { "max_result_window" :30000 } }'

关闭节点

ps -ef | grep elasticsearch    

kill ****

转载于:https://my.oschina.net/u/3346994/blog/858799

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值