Elasticsearch 安装并使用

 

Elasticsearch 简称es.是一个开源的分布式 RESTful 搜索和分析引擎

实际应用场景:存储日志

官网地址:https://www.elastic.co/cn/

注:Elasticsearch启动不能通过root用户,只能通过普通用户。默认端口:9200

es安装步骤:

1.下载并解压

wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-6.3.2.tar.gz

tar -xzvf elasticsearch-6.3.2.tar.gz 

cd 到./elasticsearch-6.3.2/config/  目录下

2.编辑配置文件,将network.host: 0.0.0.0改为任意访问ip并保存

vi config/elasticsearch.yml

3.执行./bin/elasticsearch

4.执行常见错误解决方案:

问题一 .can not run elasticsearch as root:

解决方案: 不能用root用户登录来执行,切换为普通用户

问题二.max virtual memory areas vm.max_count [65530] likely too low,increase to at least [262144]

解决方案:虚拟内存小,加大虚拟内存 。

在root用户下,

修改配置 /etc/sysctl.conf  

添加下面配置:

vm.max_map_count=655360

执行命令:sysctl -p

问题三:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

解决方案:

vi /etc/security/limits.conf 

添加如下内容:

* soft nofile 65536

* hard nofile 131072

* soft nproc 2048

* hard nproc 4096

问题四:报错elastic: Error 403 (Forbidden): blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]; [type=cluster_block_exception]

解决方案:

curl -XPUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

返回结果如下即可

{"acknowledged":true}

5.没有错误的话切换到普通用户重新执行启动命令:./bin/elasticsearch

  后台启动命令:./bin/elasticsearch & [推荐 ]   bin/elasticsearch -d

 验证是否启动成功:curl http://本机IP:9200 ,返回json就表示成功

es健康检查

curl -XGET 'http://127.0.0.1:9200/_cluster/health'

es安装可视化页面kibana 

 图形化界面使用教程:https://yq.aliyun.com/articles/205028

kibana  API : https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html

1.下载并解压

wget  https://www.elastic.co/cn/downloads/kibana
https://artifacts.elastic.co/downloads/kibana/kibana-6.3.2-linux-x86_64.tar.gz

tar -xzf kibana-6.2.2-linux-x86_64.tar.gz

cd ./kibana/config/ 目录下

 2. 编辑 vi config/kibana.yml

server.port: 5601                                      //默认端口

server.host: "0.0.0.0"                                // 任意端口可以访问

elasticsearch.url: "http://localhost:9200"            // 已安装好的es的ip地址 

 3. 进入目录执行命令:./bin/kibana  后台启动命令./bin/kibana &

 4. 获取所有ype 

curl -XGET 'http://localhost:9200/_mapping?pretty=true'

5. 删除指定index 

curl -XDELETE http://localhost:9200/xxx

6. 删除指定条件数据  https://blog.csdn.net/QYHuiiQ/article/details/90812570

   新建脚本es-index-delete-by-query-30d.sh  。加入

LAST_DATA=`date -d "-30 days" "+%Y-%m-%dT00:00:00"`
echo ${LAST_DATA}

curl -XPOST 'http://127.0.0.1:9200/这里写要删除的index/_delete_by_query' -H 'Content-Type: application/json' -d '
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "value.timestamp": {
              "lte":"'${LAST_DATA}'"
            }
          }
        }
      ]
    }
  }
}
'

uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif转存失败重新上传取消uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif正在上传…重新上传取消uploading.4e448015.gif正在上传…重新上传取消

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装使用Elasticsearch,您可以按照以下步骤进行操作: 1. 下载并安装Java:Elasticsearch是用Java编写的,因此您需要先安装Java。您可以从Oracle官方网站下载并安装适合您操作系统的Java版本。 2. 下载Elasticsearch:在Elasticsearch官方网站(https://www.elastic.co/downloads/elasticsearch)上下载适合您操作系统的Elasticsearch版本。 3. 解压缩Elasticsearch:将下载的文件解压缩到您选择的目录中。 4. 配置Elasticsearch:进入解压缩后的Elasticsearch目录,找到config文件夹。在该文件夹中,您可以编辑elasticsearch.yml文件以进行配置。您可以根据需要更改默认配置,例如集群名称、网络绑定地址等。 5. 启动Elasticsearch:在命令行中进入Elasticsearch目录,并运行bin/elasticsearch命令来启动Elasticsearch。请确保在启动之前Java已正确配置,并且没有其他进程在占用所需的端口。 6. 验证安装使用curl或浏览器访问http://localhost:9200,您应该能够看到Elasticsearch的版本信息。如果您能成功访问,表示安装成功。 一旦您安装Elasticsearch,您可以使用其RESTful API进行索引、搜索和管理数据。您还可以使用Kibana等工具来可视化和分析数据。请记住,Elasticsearch是一个功能强大而复杂的工具,您可能需要学习更多关于其配置和使用的知识。可以查阅Elasticsearch官方文档以获取更多详细信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值