• ElasticSearch 安装配置


    1. 安装ElasticSearch

    # wget?https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.tar.gz
    # tar -xvf elasticsearch-1.4.4.tar.gz
    
    • 1
    • 2

    2. 安装插件

    2.1 安装ElasticSearch

    Marvel是ElasticSearch的监控工具,可通过插件方式下载。

    # cd elasticsearch-1.4.4
    # ./bin/plugin -i elasticsearch/marvel/latest
    
    • 1
    • 2

    2.2 安装ServiceWapper

    ServiceWrapper可后台启动,停止服务

    # wget https://github.com/elasticsearch/elasticsearch-servicewrapper/archive/master.zip
    # unzip master -d ./
    # mv elasticsearch-servicewrapper-master/service elasticsearch-1.4.4/bin/
    # rm -Rf elasticsearch-servicewrapper-master
    
    • 1
    • 2
    • 3
    • 4

    bin/service/elasticsearch有如下命令可用:

    console 在前台运行es
    start 在后台运行es
    stop 停止es
    install 使es作为服务在服务器启动时自动启动
    remove 取消启动时自动启
    # bin/plugin --install mobz/elasticsearch-head
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在service目录下有个elasticsearch.conf配置文件,可配置java相关的运行环境参数。

    2.3 安装Head

    # ./bin/plugin --install mobz/elasticsearch-head
    
    • 1

    2.4 安装BigDesk

    # ./bin/plugin --install lukas-vlcek/bigdesk
    
    • 1

    2.5 安装ik分词插件

    # cd plugins
    # mkdir analysis-ik
    # cd analysis-ik
    
    • 1
    • 2
    • 3

    由于网上的jar存在问题,需要从Github上下载最新的源码,用Maven编译后,再将target/release/elasticsearch-analysis-ik-1.2.9.zip上传至服务器的ES_HOME/plugins/analysis-ik目录,并解压此zip包后,删除zip包。

    源码下的config/ik目录拷贝至ES_HOME/conf下,这是词典配置文件。
    启用分词插件,编辑ES_HOME/conf/elasticsearch.yml,加入以下内容:

    index:
            analysis:
                    analyzer:
                            ik:
                                    alias: [news_analyzer_ik,ik_analyzer]
                                    type: org.elasticsearch.index.analysis.IkAnalyzerProvider                                          
    index.analysis.analyzer.default.type : "ik"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    安装好插件后,要使用插件起作用,必须创建索引。

    # curl -XPUT http://localhost:9200/index
    # curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
    {
        "fulltext": {
                 "_all": {
                "analyzer": "ik"
            },
            "properties": {
                "content": {
                    "type" : "string",
                    "boost" : 8.0,
                    "term_vector" : "with_positions_offsets",
                    "analyzer" : "ik",
                    "include_in_all" : true
                }
            }
        }
    }'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    测试:

    # curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
    {
    "text":"我是中国人"
    }'
    
    • 1
    • 2
    • 3
    • 4

    结果如下:

    {
    "tokens": [
    {
    "token": "我",
    "start_offset": 0,
    "end_offset": 1,
    "type": "CN_CHAR",
    "position": 1
    }
    ,
    {
    "token": "中国人",
    "start_offset": 2,
    "end_offset": 5,
    "type": "CN_WORD",
    "position": 2
    }
    ,
    {
    "token": "中国",
    "start_offset": 2,
    "end_offset": 4,
    "type": "CN_WORD",
    "position": 3
    }
    ,
    {
    "token": "国人",
    "start_offset": 3,
    "end_offset": 5,
    "type": "CN_WORD",
    "position": 4
    }
    ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    3. 运行ElasticSearch

    ./bin/service/elasticsearch start
    
    • 1

    可新建一个窗口,测试是否启动成功。

    # curl 'http://localhost:9200/?pretty'
    {
      "status" : 200,
      "name" : "George Washington Bridge",
      "cluster_name" : "elasticsearch",
      "version" : {
        "number" : "1.4.4",
        "build_hash" : "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
        "build_timestamp" : "2015-02-19T13:05:36Z",
        "build_snapshot" : false,
        "lucene_version" : "4.10.3"
      },
      "tagline" : "You Know, for Search"
    }
    #
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    开启防火墙端口9200,9300,在浏览器键入:http://ip:9200/_plugin/marvel

    4. 集群配置

    ElasticSearch的集群可自发现,只要配置相同的集群名称,默认为组播发现机制,默认情况下:

    • http 端口:9200 需要打开给调用
    • 数据传输端口:9300 用于集群之间交换数据
    • 组播端口(UDP):54328

    上述端口一定不要让防火墙阻断,否则,无法完成集群。

    编辑每个ElasticSearch/config/elasticsearch.yml,加入以下代码:

    cluster.name: elasticsearch-cluster
    node.name: "es-node1"
    
    • 1
    • 2

    第一行表示集群名称,一个集群内的所有结点相同,后面是结点在集群内的名称,每个结点不一样,建议配置,不配置会自动分配一个随机名称。

  • 相关阅读:
    如何确定 <board_name>名字
    docker离线安装问题解决
    [Typescript]基础篇之函数
    【Mac】破解死循环,成功安装 Homebrew、curl、wget,快速配置 zsh
    Django序列化与反序列化
    【单元测试】--单元测试最佳实践
    Serverless 数仓技术与挑战(内含 PPT 下载)
    免费IP代理靠谱吗?靠谱的IP代理有哪些?
    Apache Commons IO组件简介说明
    【无标题】
  • 原文地址:https://blog.csdn.net/m0_59092234/article/details/126359132