ElasticSearch5.4.1 搜索引擎搭建文档

  1. 安装配置JDK环境
    JDK安装(不能安装JRE)
    JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
    下载包:jdk-8u131-linux-x64.rpm
    yum localinstall jdk-8u131-linux-x64.rpm
  2. mvn 安装
    MVN下载地址
    cd /usr/local
    wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
    tar xzf apache-maven-3.3.9-bin.tar.gz
    mv apache-maven-3.3.9 maven
    vi /etc/profile.d/maven.sh
    export M2_HOME=/usr/local/maven
    export PATH=${M2_HOME}/bin:${PATH}
    source /etc/profile.d/maven.sh
    mvn -version
  3. 安装ElasticSearch5.41
    yum install epel-release
    yum install npm nodejs
    centos7 若安装nodejs失败,请执行如下命令再重试
    rpm -ivh https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.rpm
    yum localinstall elasticsearch-5.4.1.rpm
    修改配置文件
    vim /etc/elasticsearch/elasticsearch.yml
    修改network.host:localhost 为当前服务器ip地址
    追加2行
    # 增加新的参数,这样head插件可以访问es
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    若安装了xpack,关闭密码,需添加如下一行,默认无需添加
    xpack.security.enabled: false
    启动: systemctl start elasticsearch
    开机启动:systemctl enable elasticsearch
    测试
    访问 http://localhost:9200/地址
    默认密码Username: elastic Password: changeme
    注意network.host参数,不能使用外网ip,若需要开发外网访问,设置为:0.0.0.0
  4. elasticsearch-head (此操作巨慢)
    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    '''
    添加淘宝源(依然慢)
    npm install -g cnpm --registry=https://registry.npm.taobao.org
    '''
    npm install
    vim _site/app.js
    查找9200修改参数localhost为本机ip
    npm run start
    测试
    访问 http://localhost:9100/地址,页面显示正常,es连接正常即ok
  5. kibana
    wget https://artifacts.elastic.co/downloads/kibana/kibana-5.4.1-x86_64.rpm
    yum localinstall kibana-5.4.1-x86_64.rpm
    修改配置文件
    vim /etc/kibana/kibana.yml 
    修改elasticsearch.url localhost 为当前服务器ip地址,用户名及密码
    elasticsearch.url: http://localhost:9200
    elasticsearch.username: "elastic"
    elasticsearch.password: "changeme"
    测试:
    curl -u elastic:changeme http://localhost
    http://localhost/status
  6. nginx配置
    安装软件
    yum install nginx httpd-tools
    为 Kibana 创建一个配置文件
    vi /etc/nginx/conf.d/kibana.conf
    加入以下这一段内容:
    server {
        listen 80;
        server_name server_ip;
        location / {
            proxy_pass http://localhost:5601;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade; 
        }
    }

    注意修改配置文件,server_name ip
    启动Nginx服务
    systemctl start nginx
    systemctl enable nginx
    验证http://localhost

  7. 5.x以上版本的Elasticsearch,Marvel 更换成了X-Pack (收费插件,免费的只有监控功能)
    cd /usr/share/elasticsearch/bin
    ./elasticsearch-plugin install x-pack
    cd /usr/share/kibana/bin
    ./kibana-plugin install x-pack
    systemctl restart elasticsearch
    systemctl restart kibana
  8. elasticsearch-analysis-ik 分词插件 (此步安装巨慢)
    对应免安装版本下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
    git clone https://github.com/medcl/elasticsearch-analysis-ik
    cd elasticsearch-analysis-ik
    mvn clean
    mvn compile
    mvn package
    拷贝和解压 release 下的文件: #{project_path}/elasticsearch-analysis-ik/target/releases/elasticsearch-analysis-ik-*.zip 到你的 elasticsearch 插件目录, 如: plugins/ik 重启 elasticsearch
    分词插件测试脚本
    创建一个index
    curl -u elastic:changeme -XPUT http://localhost:9200/index
    创建一个mapping
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/_mapping -d'
    {
        "fulltext": {
                 "_all": {
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "term_vector": "no",
                "store": "false"
            },
            "properties": {
                "content": {
                    "type": "text",
                    "analyzer": "ik_max_word",
                    "search_analyzer": "ik_max_word",
                    "include_in_all": "true",
                    "boost": 8
                }
            }
        }
    }'
    创建index
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/1 -d'
    {"content":"世界如此之大"}
    '
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/2 -d'
    {"content":"世界如此美好"}
    '
    查询
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/_search  -d'
    {
        "query" : { "match" : { "content" : "世界" }},
        "highlight" : {
            "pre_tags" : ["<tag1>", "<tag2>"],
            "post_tags" : ["</tag1>", "</tag2>"],
            "fields" : {
                "content" : {}
            }
        }
    }
    '
    ik-test
posted @ 2017-06-12 17:33  Mr黄瑞  阅读(485)  评论(0编辑  收藏  举报