Elasticsearch之 cerebro 安装配置详细使用

运行环境:
CentOS 7.6
Elasticsearch 6.8.4

软件下载:
https://github.com/lmenezes/cerebro/releases

概述:
cerebro is an open source(MIT License) elasticsearch web admin tool built using Scala, Play Framework, AngularJS and Bootstrap.
celebro 是一个Elasticsearch的web 管理工具,基于scala,play框架和angularJS和Bootstrap前端工具构建。

可以看到cerebro是对Elastic监控的工具,和对Elastic操作的工具。

安装需求:
需要安装Java 8版本
## java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

可以选择rpm安装或者源码包安装:
我这里为了方便快捷直接使用rpm
# wget https://github.com/lmenezes/cerebro/releases/download/v0.8.5/cerebro-0.8.5-1.noarch.rpm


安装:
# rpm -ivh cerebro-0.8.5-1.noarch.rpm 
Preparing...                          ################################# [100%]
Creating system group: cerebro
Creating system user: cerebro in cerebro with cerebro user-daemon and shell /bin/false
Updating / installing...
   1:cerebro-0.8.5-1                  ################################# [100%]
Created symlink from /etc/systemd/system/multi-user.target.wants/cerebro.service to /usr/lib/systemd/system/cerebro.service.
--查询一些信息:
# rpm -ql cerebro-0.8.5-1
/etc/cerebro
/etc/default/cerebro
/usr/bin/cerebro
/usr/lib/systemd/system/cerebro.service
/usr/share/cerebro/README.md
/usr/share/cerebro/bin/cerebro
/usr/share/cerebro/conf/application.conf
/usr/share/cerebro/conf/evolutions
/usr/share/cerebro/conf/evolutions/default
/usr/share/cerebro/conf/evolutions/default/1.sql
/usr/share/cerebro/conf/logback.xml
/usr/share/cerebro/conf/reference.conf
/usr/share/cerebro/conf/routes
....
/usr/share/cerebro/logs
/var/lib/cerebro
/var/log/cerebro
/var/run/cerebro

可以看到配置文件
/usr/share/cerebro/conf/application.conf
日志文件:
/var/log/cerebro
配置:
可以指定配置参数启动:
bin/cerebro -Dhttp.port=1234 -Dhttp.address=127.0.0.1
可以指定配置文件启动:


启动:
bin/cerebro -Dconfig.file=/some/other/dir/alternate.conf


配置:
# vim /usr/share/cerebro/conf/application.conf

# A list of known hosts
hosts = [
  {
   host = "http://192.168.8.102:9200"
   name = "ES Cluster"
  #  headers-whitelist = [ "x-proxy-user", "x-proxy-roles", "X-Forwarded-For" ]
  #}
  # Example of host with authentication
  #{
  #  host = "http://some-authenticated-host:9200"
  #  name = "Secured Cluster"
  #  auth = {
  #    username = "username"
  #    password = "secret-password"
  #  }
  }
]

cerebro的启动 状态查看和关闭:
# systemctl stop cerebro  
# systemctl start cerebro
# systemctl status cerebro
● cerebro.service - Elasticsearch web admin tool
   Loaded: loaded (/usr/lib/systemd/system/cerebro.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-12-12 14:36:39 CST; 6s ago
  Process: 11484 ExecStartPre=/bin/chmod 755 /run/cerebro (code=exited, status=0/SUCCESS)

为了便于问题排除可以直接使用命令启动cerebro:
# /usr/bin/cerebro
默认启动的:
[info] play.api.Play - Application started (Prod) (no global state)
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
允许网络范围内的任意主机登陆访问:


登陆:
192.168.8.102:9000

若在配置文件中配置好了则可以直接可以查看到cluster的名称:点击cluster的名称直接登陆即可。

若没有配置则需要指定clusters的名称和node address

 

登陆进入则是默认的overview界面:

单机nodes可以看到节点的类型和监控信息:

 mores标签可以看到集群的相关信息:

 REST标签则提供了对Elasticsearch进行操作的基本命令:GET PUT POST DELETE

PUT操作:
# curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
> {
>   "name": "John Doe"
> }
> '
{
  "_index" : "customer",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

GET操作:
# curl -X GET "localhost:9200/customer/_doc/1?pretty"
{
  "_index" : "customer",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "John Doe"
  }
}

批量操作:
# curl "localhost:9200/_cat/indices?v"
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   customer OBC93MybQeuiHtNm_m_9-g   5   1          1            0      8.5kb          4.2kb
green  open   bank     x8KA6MJRSYqPiNbeRfuCqA   5   1       1000            0    950.4kb        475.2kb

--查询操作:
#curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": { "match_all": {} },
  "sort": [
    { "account_number": "asc" }
  ]
}
'
--查询一条记录:
# curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
> {
>   "query": { "match_all": {} },
>   "sort": [
>     { "account_number": "asc" }
>   ],
>   "from": 10,
>   "size": 1
> }
> '
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1000,
    "max_score" : null,
    "hits" : [
      {
        "_index" : "bank",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : null,
        "_source" : {
          "account_number" : 10,
          "balance" : 46170,
          "firstname" : "Dominique",
          "lastname" : "Park",
          "age" : 37,
          "gender" : "F",
          "address" : "100 Gatling Place",
          "employer" : "Conjurica",
          "email" : "dominiquepark@conjurica.com",
          "city" : "Omar",
          "state" : "NJ"
        },
        "sort" : [
          10
        ]
      }
    ]
  }
}


#curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": { "match": { "address": "mill lane" } }
}
'

#curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": { "match_phrase": { "address": "mill lane" } }
}
'

复杂查询:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "must": [
        { "match": { "age": "40" } }
      ],
      "must_not": [
        { "match": { "state": "ID" } }
      ]
    }
  }
}
'

查询:balance在2000和3000之间的
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "must": { "match_all": {} },
      "filter": {
        "range": {
          "balance": {
            "gte": 20000,
            "lte": 30000
          }
        }
      }
    }
  }
}
'

--聚合操作:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "size": 0,
  "aggs": {
    "group_by_state": {
      "terms": {
        "field": "state.keyword"
      }
    }
  }
}
'

curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "size": 0,
  "aggs": {
    "group_by_state": {
      "terms": {
        "field": "state.keyword"
      },
      "aggs": {
        "average_balance": {
          "avg": {
            "field": "balance"
          }
        }
      }
    }
  }
}
'




 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是Elasticsearch安装配置步骤: 1. 安装Java环境 Elasticsearch是基于Java开发的,因此在安装Elasticsearch之前,需要先安装Java环境。建议使用Java 8或更高版本。 2. 下载Elasticsearch 可以在Elasticsearch官网上下载最新版本的Elasticsearch。 3. 解压缩文件 下载完成后,将压缩包解压缩到您希望安装的目录下。 4. 配置Elasticsearch 打开解压缩后的Elasticsearch目录,找到config文件夹,编辑elasticsearch.yml文件,配置以下参数: - cluster.name:集群名称,不同的集群需要有不同的名称。 - node.name:节点名称,每个节点需要有一个唯一的名称。 - network.host:节点绑定的IP地址,如果是本机测试,可以使用默认值127.0.0.1。 - http.port:节点对外提供服务的端口号,默认为9200。 5. 启动ElasticsearchElasticsearch目录下,执行以下命令启动Elasticsearch: ``` ./bin/elasticsearch ``` 6. 测试Elasticsearch 使用浏览器或curl等工具访问http://localhost:9200/,如果能够正常返回以下信息,则表示Elasticsearch已经成功安装: ``` { "name" : "node-1", "cluster_name" : "my_cluster", "cluster_uuid" : "abcde12345", "version" : { "number" : "7.5.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "e9ccaed468e2fac2275a2a0c065cdc250424e41b", "build_date" : "2019-11-26T01:06:52.518245Z", "build_snapshot" : false, "lucene_version" : "8.3.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } ``` 以上就是Elasticsearch安装配置步骤,希望能够对您有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值