• Elasticsearch安装


    Elasticsearch安装

    1.ElasticSearch

    Elasticsearch,基于lucene,隐藏复杂性,提供简单易用的restful api接口、java api接口(还有其他语言的api接口)。

    关于elasticsearch的一个传说,有一个程序员失业了,陪着自己老婆去英国伦敦学习厨师课程。程序员在失业期间想给老婆写一个菜谱搜索引擎,觉得lucene实在太复杂了,就开发了一个封装了lucene的开源项目,compass。后来程序员找到了工作,是做分布式的高性能项目的,觉得compass不够,就写了elasticsearch,让lucene变成分布式的系统。

    Elasticsearch是一个实时分布式搜索和分析引擎。它用于全文搜索、结构化搜索、分析。

    全文检索:将非结构化数据中的一部分信息提取出来,重新组织,使其变得有一定结构,然后对此有一定结构的数据进行搜索,从而达到搜索相对较快的目的。

    结构化检索:我想搜索商品分类为日化用品的商品都有哪些,select * from products where category_id='日化用品'。

    数据分析:电商网站,最近7天牙膏这种商品销量排名前10的商家有哪些;新闻网站,最近1个月访问量排名前3的新闻版块是哪些。

    1.1 安装包下载

    1Elasticsearch官网: https://www.elastic.co/products/elasticsearch 

    1.2 安装Elasticsearch(单节点Linux环境)

    1解压elasticsearch-5.6.1.tar.gz到/opt/module目录

    [root@master software]# tar -zxvf elasticsearch-5.6.1.tar.gz -C /opt/module/

    2)/opt/module/elasticsearch-5.6.1路径下创建datalogs文件夹

    [root@master elasticsearch-5.6.1]# mkdir data

    [root@master elasticsearch-5.6.1]# mkdir logs

    3)修改配置文件/opt/module/elasticsearch-5.2.2/config/elasticsearch.yml

    [root@master config]# pwd

    /opt/module/elasticsearch-5.6.1/config

    [root@master config]# vi elasticsearch.yml

    # ---------------------------------- Cluster -------------------------------------

    cluster.name: es-cluster

    # ------------------------------------ Node --------------------------------------

    node.name: node1

    # ----------------------------------- Paths ---------------------------------------

    path.data: /opt/module/elasticsearch-5.6.1/data

    path.logs: /opt/module/elasticsearch-5.6.1/logs

    # ----------------------------------- Memory -----------------------------------

    bootstrap.memory_lock: false

    bootstrap.system_call_filter: false

    # ---------------------------------- Network ------------------------------------

    network.host: 192.168.96.11

    # --------------------------------- Discovery ------------------------------------

    discovery.zen.ping.unicast.hosts: ["master"]

    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true
    node.data: true

    1cluster.name

    如果要配置集群需要两个节点上的elasticsearch配置的cluster.name相同,都启动可以自动组成集群,这里如果不改cluster.name则默认是cluster.name=es-cluster,

    2nodename随意取但是集群内的各节点不能相同

    3)修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格

    4)配置linux系统环境

    1编辑limits.conf 添加类似如下内容

    [root@master elasticsearch-5.6.1]# vi /etc/security/limits.conf

    添加如下内容:

    * soft nofile 65536

    * hard nofile 131072

    * soft nproc 4096

    * hard nproc 4096

    2进入limits.d目录下修改配置文件。

    [root@master elasticsearch-5.6.1]# vi /etc/security/limits.d/20-nproc.conf

    修改如下内容:

    * soft nproc 1024

    #修改为

    * soft nproc 4096

    3修改配置sysctl.conf

    [root@master elasticsearch-5.6.1]# vi /etc/sysctl.conf 

    添加下面配置:

    vm.max_map_count=655360

    并执行命令:

    [root@master elasticsearch-5.6.1]# sysctl -p

    然后,重新启动elasticsearch,即可启动成功。

    5)Linux中新建用户

    (1)使用root用户操作如下命令:

    useradd elsearch -----------创建用户

    passwd elsearch -----------为用户设置密码

    vim /etc/sudoers  -----------为用户赋予sudo权限

    添加   elsearch    ALL=(ALL)       ALL

     (2) 修改文件夹及其子文件夹属主命令

     chown -R elsearch:elsearch elasticsearch-6.1.1/

     修改后即可以使用elsearch操作此文件夹内容

    6)启动elasticsearch

    [elsearch@master elasticsearch-5.6.1]$ bin/elasticsearch

    7)测试elasticsearch

    [elsearch@master elasticsearch-5.6.1]$ curl http://master:9200

    curl -XGET 'localhost:9200/_cat/health?v&pretty'

    {
    "name" : "node1",
    "cluster_name" : "es-cluster",
    "cluster_uuid" : "kG_Tgq4sQdu2OmfuIng7bg",
    "version" : {
    "number" : "6.5.4",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "d2ef93d",
    "build_date" : "2018-12-17T21:17:40.758843Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
    },
    "tagline" : "You Know, for Search"
    }

        

    8)安装elasticsearch-head.crx插件

    第一种安装方法:

    1Google浏览器:打开浏览器,进入“更多工具”——>“扩展程序”,将插件拖入即可完成安装

    2360浏览器:打开浏览器,双击elasticsearch-head.crx插件即可完成安装

    (3)使用插件查看节点状态

    第二种安装方法:

    下载插件:https://github.com/mobz/elasticsearch-head

    nodejs官网下载安装包:https://nodejs.org/dist/

    node-v6.9.2-linux-x64.tar.xz

    拷贝

    安装nodejs:

    解压

    配置环境变量:

    export NODE_HOME=/usr/local/node-v6.9.2-linux-x64 export PATH=$PATH:$NODE_HOME/bin

    查看node和npm版本:

    node -v

    npm -v

    解压head插件到/opt/module目录下:

    unzip elasticsearch-head-master.zip

    查看当前head插件目录下有无node_modules/grunt目录:

    没有:执行命令创建:npm install grunt --save --registry=https://registry.npm.taobao.org

    安装head插件:

    npm install -g cnpm --registry=https://registry.npm.taobao.org

    安装grunt:

    npm install -g grunt-cli --registry=https://registry.npm.taobao.org

    编辑Gruntfile.js

    vim Gruntfile.js

    文件93行添加

    hostname:'0.0.0.0'

    检查head根目录下是否存在base文件夹

    没有:将 _site下的base文件夹及其内容复制到head根目录下

    mkdir base

    cp base/* ../base/

    启动grunt server:

    grunt server -d

    如果提示grunt的模块没有安装:

    Local Npm module “grunt-contrib-clean” not found. Is it installed?

    Local Npm module “grunt-contrib-concat” not found. Is it installed?

    Local Npm module “grunt-contrib-watch” not found. Is it installed?

    Local Npm module “grunt-contrib-connect” not found. Is it installed?

    Local Npm module “grunt-contrib-copy” not found. Is it installed?

    Local Npm module “grunt-contrib-jasmine” not found. Is it installed?

    执行以下命令:

    npm install grunt-contrib-clean -registry=https://registry.npm.taobao.org

    npm install grunt-contrib-concat -registry=https://registry.npm.taobao.org

    npm install grunt-contrib-watch -registry=https://registry.npm.taobao.org 

    npm install grunt-contrib-connect -registry=https://registry.npm.taobao.org

    npm install grunt-contrib-copy -registry=https://registry.npm.taobao.org 

    npm install grunt-contrib-jasmine -registry=https://registry.npm.taobao.org

    最后一个模块可能安装不成功,但是不影响使用。

    浏览器访问head插件:

    http://192.168.96.11:9100

    9)停止集群

    kill -9 进程

    2.3 安装Elasticsearch(多节点集群Linux环境)

    1)分发Elasticsearch安装包至slave1和slave2

    [elsearch@master module]$ xsync elasticsearch-5.6.1/

    2)修改master配置信息

    [elsearch@master config]$ vi elasticsearch.yml

    添加如下信息:

    node.master: true

    node.data: true

    3)修改slave1配置信息

    1)修改Elasticsearch配置信息

    [elsearch@master config]$ vi elasticsearch.yml

    node.name: node2

    node.master: false

    node.data: true

    network.host: 192.168.96.12

    (2)修改Linux相关配置信息(同master

    4)修改slave2配置信息

    1)修改Elasticsearch配置信息

    [elsearch@slave1 config]$ vi elasticsearch.yml

    node.name: node3

    node.master: false

    node.data: true

    network.host: 192.168.96.13

    2)修改Linux相关配置信息(同master

    5)分别启动三台节点的Elasticsearch

    6)使用插件查看集群状态

  • 相关阅读:
    ArcGIS for Android示例解析之高亮要素-----HighlightFeatures
    ArcGIS Runtime for Android开发教程V2.0(8)基础篇-----地图事件
    ArcGIS for Android示例解析之空间查询-----QueryTask
    ArcGIS for Android地图控件的5大常见操作
    ArcGIS Runtime for Android开发教程V2.0(4)基础篇---MapView
    ArcGIS for Android 中MapView的地图背景设置
    使用Arcglobe 10与3dmax建立三维城市
    使用PowerDesigner建立数据库模型
    一步一步学Remoting系列文章
    App集成支付宝
  • 原文地址:https://www.cnblogs.com/zhangchenchuan/p/12068528.html
Copyright © 2020-2023  润新知