zoukankan      html  css  js  c++  java
  • 搜索引擎elasticsearch + kibana + X-pack + IK安装部署

    准备安装环境

    这次我们安装以下软件或插件:

    • elasticsearch(es):You Know, for Search
    • kibana:提供很便捷的观察和控制es的网页
    • xpack:安全插件,提供授权认证登陆
    • IK:分词插件,提供功能强大的中文分词

    es建议安装在独立的系统账户下,这里我们创建es账户。
    JAVA版本为1.8。
    下载elasticsearch和kibana,注意两者版本号要严格保持一致。这里我们用6.7.1(届时生产的阿里云也采用6.7)。

    $ cd /home/es
    $ wget https://artifacts.elastic.co/downloads/kibana/kibana-6.7.1-linux-x86_64.tar.gz
    $ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.1.tar.gz
    $ tar -zxvf kibana-6.7.1-linux-x86_64.tar.gz
    $ tar -zxvf elasticsearch-6.7.1.tar.gz
    

    配置启动

    启动elasticsearch

    官方号称开箱即用,这里我们显式的配置几个关键项
    修改es配置文件/home/es/elasticsearch-6.7.1/config/elasticsearch.yml

    path.data: /home/es/data # 数据文件存放目录
    path.logs: /home/es/logs # 日志存放目录
    network.host: 192.168.1.212
    http.port: 9200
    

    启动elasticsearch,-d参数表示后台运行

    $ cd /home/es/elasticsearch-6.7.1/
    $ sh bin/elasticsearch -d
    

    检测elasticsearch是否启动成功:

    浏览器访问:http://192.168.1.212:9200/
    或者:
    $ curl http://192.168.1.212:9200/
    
    输出以下内容表示ES已启动:
    {
      "name" : "uMMV8Hc",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "JHaM0vXORy-In37Duldahg",
      "version" : {
        "number" : "6.7.1",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "2f32220",
        "build_date" : "2019-04-02T15:59:27.961366Z",
        "build_snapshot" : false,
        "lucene_version" : "7.7.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
    

    关闭es,官方没有提供关闭方案,我们直接kill进程

    $ ps -efj|grep elasticsearch
    # 把es相关的进程挨个Kill掉
    

    启动kibana

    这个也是开箱即用的,同样我们显式的配置几个关键项
    修改配置文件:/home/es/kibana-6.7.1-linux-x86_64/config/kibana.yml

    server.port: 5601 # 访问kibana时的ip/port
    server.host: "192.168.1.212"
    elasticsearch.hosts: ["http://192.168.1.212:9200"] # 显式指定ES,不指定的话kibana也会默认连接本机的es
    logging.dest: /home/es/logs/kibana.log # 日志文件
    

    启动kibana,注意启动参数加"&",后台执行

    $ cd /home/es/kibana-6.7.1-linux-x86_64/
    $ ./bin/kibana &
    

    访问kibana,浏览器打开192.168.1.212:5601即可

    关闭kibana

    # 找到后台的kibana进程得费点事
    $ ps -efj |grep src/cli
    es       11759  9289 11759  9289  0 10:35 pts/6    00:00:45 ./bin/../node/bin/node --no-warnings --max-http-header-size=65536 ./bin/../src/cli
    es       12068 11517 12067 11517  0 12:23 pts/7    00:00:00 grep --color=auto src/cli
    # 这个11759的就是kibana进程,我们Kill掉即可
    $ kill 11759
    

    启用X-pack

    X-pack已经集成在当前版本的es中,但是收费项目,我们先试用个30天。
    启用trial licence,成功后日志会打出trial - valid字样

    $ curl -H "Content-Type:application/json" -XPOST  http://192.168.1.212:9200/_xpack/license/start_trial?acknowledge=true
    $ tail -f /home/es/logs/elasticsearch.log
    [uMMV8Hc] license [c5cf3e70-7287-4d56-942a-19192c82043c] mode [trial] - valid
    

    启用X-pack,在/home/es/elasticsearch-6.7.1/config/elasticsearch.yml配置文件中添加下面这行配置

    xpack.security.enabled: true
    

    此时我们再连接192.168.1.212:9200,会报“missing authentication token”,需要先登陆。
    接下来修改密码

    $ bin/elasticsearch-setup-passwords interactive
    Enter password for [elastic]: 
    Reenter password for [elastic]: 
    Enter password for [apm_system]: 
    Reenter password for [apm_system]: 
    Enter password for [kibana]: 
    Reenter password for [kibana]: 
    Enter password for [logstash_system]: 
    Reenter password for [logstash_system]: 
    Enter password for [beats_system]: 
    Reenter password for [beats_system]: 
    Enter password for [remote_monitoring_user]: 
    Reenter password for [remote_monitoring_user]: 
    Changed password for user [apm_system]
    Changed password for user [kibana]
    Changed password for user [logstash_system]
    Changed password for user [beats_system]
    Changed password for user [remote_monitoring_user]
    Changed password for user [elastic]
    

    给kibana配置账号密码,并重启kibana

    $ vi /home/es/kibana-6.7.1-linux-x86_64/config/kibana.yml
    ...
    elasticsearch.username: "kibana"
    elasticsearch.password: "123456"
    ...
    

    重启kibana后,我们在浏览器上连接kibana(192.168.1.212:5601),将弹出登陆页面,此时我们可以用相关权限的账号密码登陆,其中elastic账号拥有管理员权限。

    安装使用IK

    1、安装IK:
    IK的版本号也要求与es和kibana保持一致。
    安装方式可以用elasticsearch-plugin安装,或自行在github上下载zip包,解压到/home/es/elasticsearch-6.7.1/plugins/ik目录
    这里我们用第1种方式:

    $ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.1/elasticsearch-analysis-ik-6.7.1.zip
    

    安装完成后重启es。

    2、IK的作用:
    默认情况下,es处理中文的方式是拆分成单个文字进行匹配,比如“我是中国人”,es默认拆分成我、是、中、国、人这5个字。IK分词器,顾名思义,支持按词分,于是用IK可以拆成我、是、中国人、中国、国人。

    3、使用IK:
    es默认按单个字拆分中文,如果要用IK分词,在创建索引时需指定分词器:

    PUT hereweuseik
    {
      "settings":{
        "number_of_shards": "1",
        "number_of_replicas": "1",
        "analysis":{
    	  // 使用ik_max_word
          "analyzer":{
            "ik":{
              "tokenizer":"ik_max_word"
            }
          }
        }
      },
      "mappings":{
        // 字段定义
      }
    }
    

    使用示例

    关于使用操作的示例,请参见:

    官方Clients

    官方维护的客户端见页面:https://www.elastic.co/guide/en/elasticsearch/client/index.html
    目前包含以下语言:

    • Java REST Client [7.1] —— other versions
    • Java API [7.1] —— other versions
    • JavaScript API [7.x] —— other versions
    • Go API
    • .NET API [6.x] —— other versions
    • PHP API [6.7.x] —— other versions
    • Perl API
    • Python API
    • Ruby API
    • Community Contributed Clients

    golang client的源码在github的elastic/go-elasticsearch仓库
    GitHub:https://github.com/elastic/go-elasticsearch
    GoDoc:https://godoc.org/github.com/elastic/go-elasticsearch

    注:注意客户端版本应匹配es的版本。

  • 相关阅读:
    Leetcode--First Missing Positive
    Leetcode--LRU Cache
    java--遍历自定义数组
    爬网页?--Chrome帮你计算XPath
    log4j2配置
    winedt设置自动显示行号[latex]
    墓地雕塑-LA3708
    ctex moderncv版本更新--用latex写一个漂亮的简历
    用Jekyll在github上写博客——《搭建一个免费的,无限流量的Blog》的注脚
    用gameMaker做个小游戏
  • 原文地址:https://www.cnblogs.com/JoZSM/p/11066166.html
Copyright © 2011-2022 走看看