Elastic产品简介以及ElasticSearch搜索

参考官网:https://www.elastic.co/

中文网站:https://www.elastic.co/cn/

1. elastic产品简介

  elastic有一系列的产品,其中有

(1)Elasticsearch: Distributed, RESTful search and analytics.

(2)Kibana:Visualize your data. Navigate the Stack.

(3)Beats:Collect, parse, and ship in a lightweight fashion. 

(4)Logstash:Ingest, transform, enrich, and output. 

 

  ELK是elasricsearch、logstash、kibana的首字母缩写。由于加了Beats不太好加首字母,因此 Elasticsearch、Kibana、Beats 和 Logstash也称为 ELK Stack。能够安全可靠地获取任何来源、任何格式的数据,然后实时地对数据进行搜索、分析和可视化。

2.ElasticSearch安装与启动

  es提供了linux、windows等操作系统的安装包,也提供了docker的安装包。

  安装JDK环境这里就不说了,我安装的是JDK8。

0.官方给出的步骤如下

1.下载安装包

例如我下载的是:

 解压后目录如下:

2.启动服务

windows下面用binelasticsearch.bat启动

启动后控制台输入启动信息如下:

浏览器访问,linux的话可以用curl或者浏览器

   可以看到有版本信息以及集群信息。

启动后用jps查看java进程:

C:UsersAdministrator>jps -l -v
18804 org.elasticsearch.bootstrap.Elasticsearch -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=COMPAT -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=C:UsersADMINI~1AppDataLocalTempelasticsearch -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -XX:MaxDirectMemorySize=536870912 -Delasticsearch -Des.path.home=E:ELKelasticsearch-7.6.2 -Des.path.conf=E:ELKelasti

3.ES的主要配置

es的配置文件都位于config目录中。
1. elasticsearch.yml 

   es的相关配置,这个文件关键的配置信息如下:

(1)cluster.name 集群名称,以此作为是否是同一集群的判断条件
(2)node.name 节点名称,以此作为集群中不同节点的区分条件。
(3)network.host/http.port 网络地址和端口,用于http和transport服务使用
(4)path.data 数据存储地址
(5)path.log 日志存储地址

ES有两种模式:Development模式和Product模式,两者区别如下

(1)以transport的地址是否绑定在localhost为判断标准, 也就是 network.host ,默认绑定在localhost
(2)Development模式下在启动时会以warning的方式提示配置检查异常
(3)Production模式下在启动时会以error的方式提提示配置检查异常并退出

ES修改参数的第二种方式:bin/elasticsearch -Ehttp.port=19200,例如:

E:ELKelasticsearch-7.6.2in>elasticsearch.bat -Ehttp.port=19200

结果:

2. jvm.options   

  设置jvm内存相关参数以及GC相关参数。可以看到JVM堆的大小,默认是1g。


3. log4j2.properties 

  修改日志,可以修改哪些日志的启动以及关闭。类似于我们普通web项目的日志配置。

3. ElasticSearch搭建集群

第一种是复制三个ELK软件之后修改 elasticsearch.yml 文件,第二种是bat直接指定参数。

1. 创建三个data目录,如下:

 2. 进入es/bin下执行下面三条命令:

elasticsearch.bat -Ehttp.port=9200 -Epath.data=E:/data/0
elasticsearch.bat -Ehttp.port=19200 -Epath.data=E:/data/1
elasticsearch.bat -Ehttp.port=29200 -Epath.data=E:/data/2

3. 查看集群信息

访问:http://localhost:9200/_cat/nodes?v

   有一些内存信息以及集群信息,*表示是主节点。

也可以访问集群的详细信息:http://localhost:9200/_cluster/stats?pretty

{
  "_nodes" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "38N5jPU9S26K8zu7Cajb6w",
  "timestamp" : 1596635967456,
  "status" : "green",
  "indices" : {
    "count" : 0,
    "shards" : { },
    "docs" : {
      "count" : 0,
      "deleted" : 0
    },
    "store" : {
      "size_in_bytes" : 0
    },
    "fielddata" : {
      "memory_size_in_bytes" : 0,
      "evictions" : 0
    },
    "query_cache" : {
      "memory_size_in_bytes" : 0,
      "total_count" : 0,
      "hit_count" : 0,
      "miss_count" : 0,
      "cache_size" : 0,
      "cache_count" : 0,
      "evictions" : 0
    },
    "completion" : {
      "size_in_bytes" : 0
    },
    "segments" : {
      "count" : 0,
      "memory_in_bytes" : 0,
      "terms_memory_in_bytes" : 0,
      "stored_fields_memory_in_bytes" : 0,
      "term_vectors_memory_in_bytes" : 0,
      "norms_memory_in_bytes" : 0,
      "points_memory_in_bytes" : 0,
      "doc_values_memory_in_bytes" : 0,
      "index_writer_memory_in_bytes" : 0,
      "version_map_memory_in_bytes" : 0,
      "fixed_bit_set_memory_in_bytes" : 0,
      "max_unsafe_auto_id_timestamp" : -9223372036854775808,
      "file_sizes" : { }
    }
  },
  "nodes" : {
    "count" : {
      "total" : 3,
      "coordinating_only" : 0,
      "data" : 3,
      "ingest" : 3,
      "master" : 3,
      "ml" : 3,
      "voting_only" : 0
    },
    "versions" : [
      "7.6.2"
    ],
    "os" : {
      "available_processors" : 12,
      "allocated_processors" : 12,
      "names" : [
        {
          "name" : "Windows 8.1",
          "count" : 3
        }
      ],
      "pretty_names" : [
        {
          "pretty_name" : "Windows 8.1",
          "count" : 3
        }
      ],
      "mem" : {
        "total_in_bytes" : 38281224192,
        "free_in_bytes" : 11522334720,
        "used_in_bytes" : 26758889472,
        "free_percent" : 30,
        "used_percent" : 70
      }
    },
    "process" : {
      "cpu" : {
        "percent" : 0
      },
      "open_file_descriptors" : {
        "min" : -1,
        "max" : -1,
        "avg" : 0
      }
    },
    "jvm" : {
      "max_uptime_in_millis" : 327302,
      "versions" : [
        {
          "version" : "1.8.0_121",
          "vm_name" : "Java HotSpot(TM) 64-Bit Server VM",
          "vm_version" : "25.121-b13",
          "vm_vendor" : "Oracle Corporation",
          "bundled_jdk" : true,
          "using_bundled_jdk" : false,
          "count" : 3
        }
      ],
      "mem" : {
        "heap_used_in_bytes" : 775278448,
        "heap_max_in_bytes" : 3116630016
      },
      "threads" : 137
    },
    "fs" : {
      "total_in_bytes" : 125829115904,
      "free_in_bytes" : 18643275776,
      "available_in_bytes" : 18643275776
    },
    "plugins" : [ ],
    "network_types" : {
      "transport_types" : {
        "security4" : 3
      },
      "http_types" : {
        "security4" : 3
      }
    },
    "discovery_types" : {
      "zen" : 3
    },
    "packaging_types" : [
      {
        "flavor" : "default",
        "type" : "zip",
        "count" : 3
      }
    ],
    "ingest" : {
      "number_of_pipelines" : 0,
      "processor_stats" : { }
    }
  }
} 

   会以json的形式打印集群的信息。

补充:ES提供的一些其他查看集群以及节点信息的连接: 

/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates

关于ES数据类型以及其他API参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

原文地址:https://www.cnblogs.com/qlqwjy/p/13430542.html