一、前言
最近在做elasticsearch的工作,把搭建过程记录一下。
测试环境:ubuntu 16.04
二、安装ES
安装详解:官方文档
1、本地单节点安装
#1、获取安装包并解压
$ curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
$ tar -xvf elasticsearch-7.5.1-linux-x86_64.tar.gz
#2、进入解压目录开启单节点服务
$ cd elasticsearch-7.5.1/bin
$ ./elasticsearch
#3、查看健康状态
$ curl -X GET "localhost:9200/_cat/health?v&pretty"
2、本地多节点安装
如果仅仅是单纯的想体验elasticsearch一下,其实单节点就已经可以满足了,功能都是一样的。
#1、获取安装包并解压
$ curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
$ tar -xvf elasticsearch-7.5.1-linux-x86_64.tar.gz
#2、进入解压目录开启多节点服务,这里掩饰启动三个节点,es很吃内存,虚拟机启动的话记得看看内存大小
$ cd elasticsearch-7.5.1/bin
$ ./elasticsearch
$ ./elasticsearch -Epath.data=data2 -Epath.logs=log2
$ ./elasticsearch -Epath.data=data3 -Epath.logs=log3
#3、查看健康状态
$ curl -X GET "localhost:9200/_cat/health?v&pretty"
3、文件插入查询等测试
参考:官方文档
4、批量操作
elsaticsearch支持单条操作也支持批量操作,官网上都有详细介绍,这里贴一下批量插入的操作,主要是给出数据文件的下载链接。
#下载测试用数据文件
$ wget https://raw.githubusercontent.com/elastic/elasticsearch/master/docs/src/test/resources/accounts.json
#批量插入
$ curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
#验证
$ curl "localhost:9200/_cat/indices?v"
#结果显示1000条记录插入成功
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open bank l7sSYV2cQXmu6_4rJWVIww 5 1 1000
三、安装head插件
elasticsearch-head 是用于监控 Elasticsearch 状态的客户端插件,包括数据可视化、执行增删改查操作等。
1、安装head
#下载插件
$ git clone git://github.com/mobz/elasticsearch-head.git
#安装grunt-cli
npm install -g grunt-cli
#安装 grunt
#elasticsearch-head 下载完成后,进入 elasticsearch-head 文件夹,执行命令:
$ npm install grunt --save
#安装依赖的 npm 包
$ npm install
2、配置head
所有依赖包安装成功后,修改 elasticsearch-head 目录下的 Gruntfile.js 文件,在 options 属性内增加 hostname,设置为 0.0.0.0。
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
3、修改 Elasticsearch 配置文件 config/elasticsearch.yml
在配置文件最后增加两个配置项,这样 elasticsearch-head 插件才可以访问 Elasticsearch 。
http.cors.enabled: true
http.cors.allow-origin: "*"
4、启动
在 elasticsearch-head 目录下,执行命令:
grunt server
输出如下内容表示启动成功:
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
访问http://localhost:9100地址,就可以看到当前 Elasticsearch 集群信息。
四、kibana安装
参考:官方文档
五、ES调优实践
https://zhuanlan.zhihu.com/p/45331117
六、参考文章
1、https://www.jianshu.com/p/e3f7bf6277f9
2、官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/elasticsearch-intro.html