zoukankan      html  css  js  c++  java
  • Elasticsearch安装配置

    Elasticsearch安装配置

    一、安装文件

    序号 名称 版本 下载地址
    1 jdk 1.8 openjdk
    2 elasticsearch 5.5.3 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.3.tar.gz
    3 elasticsearch-head 5.5.3 https://github.com/mobz/elasticsearch-head/archive/master.zip
    4 node 8.15 https://nodejs.org/dist/latest-v8.x/node-v8.15.0-linux-x64.tar.gz
    5 CentOS 7

    二、CentOS常用命令

    • 关闭系统:

      shutdown -h now
      
    • 重启系统:

      shutdown -r now
      
    • 查看目类中的文件

      ls
      
    • 创建文件夹

      mkdir dir1 dir2
      
    • 移动/重命名一个目类

      mv dir1 dir2
      
    • 删除文件

      rm -f file1
      
    • 删除文件夹及子目录内容

      rm -rf dir
      
    • 复制文件file1->file2

      cp file1 file2
      
    • 复制一个文件夹

      cp -a dir1 dir2
      
    • 查看ip地址

      ip addr show
      
    • vi编辑文件

      vi file
      # 退出ESC+:->q
      # 保存退出ESC+:->wq 
      # 开始输入-> i
      
    • 查看进程(grep获取名称中包含指定字符串的进程)

      ps -ef | grep elastic 
      
    • 杀死进程

      kill -9 {processId}
      
    • 重启防火墙

      firewall-cmd --reload
      

    三、CentOS上的安装配置

    1、jdk安装

    yum install java-1.8.0-openjdk
    

    查看版本

    java -version
    

    2、目录结构

    /home
    	/downloads
    	/elasticsearch
    		/node-v8.15.0-linux-x64
    		/elasticsearch-5.5.3
    		/elasticsearch-head
    		/phantomjs-2.1.1-linux-x86_64
    

    3、配置Elasticsearch

    在/home下创建downloads文件夹

    cd /home
    mkdir downloads elasticsearch
    

    wget命令安装

    yum install wget
    

    跳转到downloads文件夹下下载文件

    cd /downloads
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.3.tar.gz
    

    解压文件到/home/elasticsearch/

    tar -zxvf elasticsearch-5.5.3.tar.gz -C /home/elasticsearch/
    
    # 打开配置文件
    cd /home/elasticsearch/elasticsearch-5.5.3/config
    # 编辑
    vi elasticsearch.yml
    
    #
    network.host: 0.0.0.0
    #
    http.port: 9200
    #
    # For more information, consult the network module documentation.
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    

    3.1 集群配置

    配置elasticsearch.yml

    # 配置集群名称
    cluster.name: eccom
    # 配置节点名称
    node.name: node-01
    # 标记当前节点是否具有成为主节点的资格
    node.master: true
    # 192.168.96.39为当前节点所在服务器IP
    network.host: 192.168.96.39
    # RESTful访问端口
    http.port: 9200
    # 集群节点间通信端口
    transport.tcp.port: 9300
    # 通过这个ip列表进行集群间的节点自动发现,组建集群(可以不指定端口[默认9300])
    discovery.zen.ping.unicast.hosts: ["192.168.96.39:9300","192.168.96.40:9300","192.168.96.41:9300"]
    

    开放9300端口

    firewall-cmd --zone=public --add-port=9200/tcp --permanent
    firewall-cmd --reload
    

    3.2 ik分词配置

    cd /home/downloads
    # 下载文件
    wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.3/elasticsearch-analysis-ik-5.5.3.zip
    # 解压缩(解压后在当前文件夹下的elasticsearch下)
    unzip elasticsearch-analysis-ik-5.5.3.zip
    # 复制插件到elasticsearch服务程序所在的目录
    cp -a /home/downloads/elasticsearch/ /home/elasticsearch/elasticsearch-5.5.3/plugins/
    

    启动后,在命令行中会出现如下内容表示配置成功

    [2019-01-11T16:45:39,065][INFO ][o.e.p.PluginsService     ] [wIe5C1b] loaded plugin [analysis-ik]
    [2019-01-11T16:45:46,014][INFO ][o.e.d.DiscoveryModule    ] [wIe5C1b] using discovery type [zen]
    

    4、运行Elasticsearch

    Elasticsearch 要求不能使用超级用户root运行,所以我们建立一个es账号

    # 创建用户es
    adduser es
    # 设置密码
    passwd es
    

    然后,给es用户elasticsearch目录的授权

    chown -R es /home/elasticsearch/elasticsearch-5.5.3/
    

    切换至elasticsearch目录,并以es用户运行

    cd /home/elasticsearch/elasticsearch-5.5.3/
    su es
    

    运行elasticsearch,如果想后台运行后面加 -d

    ./bin/elasticsearch
    

    如果没有没有error,就表示运行成功。新开一个终端,用curl访问。

    curl 'http://localhost:9200/?pretty'
    

    结果

    {
      "name" : "wIe5C1b",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "FKD2-QolTlWb9iWHGN1eLw",
      "version" : {
        "number" : "5.5.3",
        "build_hash" : "9305a5e",
        "build_date" : "2017-09-07T15:56:59.599Z",
        "build_snapshot" : false,
        "lucene_version" : "6.6.0"
      },
      "tagline" : "You Know, for Search"
    }
    

    5、安装Elasticsearch head

    # 切换到下载文件目类
    cd /home/downloads/
    # 下载elasticsearch-head文件
    wget https://github.com/mobz/elasticsearch-head/archive/master.zip
    #安装zip/uzip
    yum install zip unzip
    # 解压文件(得到elasticsearch-head-master文件夹)
    unzip master.zip
    # 复制文件夹到/home/elasticsearch/
    cp -a /home/downloads/elasticsearch-head-master /home/elasticsearch/elasticsearch-head
    

    安装node

    # 切换到downloads目录
    cd /home/downloads
    # 下载node安装文件
    wget https://nodejs.org/dist/latest-v8.x/node-v8.15.0-linux-x64.tar.gz
    # 解压(得到node-v8.15.0-linux-x64)
    tar -zxvf node-v8.15.0-linux-x64.tar.gz -C /home/elasticsearch/
    

    配置node

    vi /etc/profile
    export NODE_HOME=/home/elasticsearch/node-v8.15.0-linux-x64
    export PATH=$PATH:$NODE_HOME/bin
    export NODE_PATH=$NODE_HOME/lib/node_modules
     
    # 执行
    source /etc/profile
    

    查看node版本

    node -v
    

    安装grunt

    npm install -g grunt-cli
    # 查看版本
    grunt -version
    

    安装phantomjs

    cd /home/downloads
    wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
    #安装解压缩工具
    yum -y install bzip2
    #解压
    tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
    

    复制文件夹到/home/elasticsearch/

    cp -a /home/downloads/phantomjs-2.1.1-linux-x86_64 /home/elasticsearch/phantomjs-2.1.1-linux-x86_64
    # 配置环境变量
    vi /etc/profile
    #文件末尾增加如下内容
    export PATH=$PATH:/home/elasticsearch/phantomjs-2.1.1-linux-x86_64/bin
    # 保存退出
    # 执行
    source /etc/profile
    

    安装heade依赖

    cd /home/elasticsearch/elasticsearch-head
    # 安装
    npm install
    

    修改head插件源码 修改服务器监听地址:Gruntfile.js

    connect: {
        server: {
            options: {
                port: 9100,
                base: '.',
                keepalive: true,
            	hostname: '*'
        	}
    	}
    }
    

    修改连接地址:_site/app.js

    #跳转到4354行
    vi +4354 _site/app.js
    #将http://localhost:9200修改为http://{ip}:9200
    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.96.39:9200";
    

    9100/9200端口开放

    firewall-cmd --zone=public --add-port=9200/tcp --permanent
    firewall-cmd --zone=public --add-port=9100/tcp --permanent
    firewall-cmd --reload
    

    启动

    #
    cd /home/elasticsearch/elasticsearch-head
    # 启动
    grunt server
    

    访问elasticsearch-head

    http://192.168.96.39:9100/

    四、问题解决

    1)、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

    vi /etc/security/limits.conf
    # 修改后重启服务器
    

    2)、 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    vi /etc/sysctl.conf
    增加vm.max_map_count=262144
    sysctl -p
    

    3)、org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

    因为安全问题elasticsearch不让用root用户直接运行,所以要创建新用户;
    参考前面的三.4中的“运行Elasticsearch”
    
  • 相关阅读:
    求和:1-2+3-4+……+m
    倒序输出字符串
    Lamdba表达式
    扩展方法 extension method
    命名参数 named parameter
    动态查找 dynamic
    Git命令与介绍
    Excel函数和公式(四)——Excel基础(4)
    Excel函数和公式(三)——Excel基础(3)
    Excel函数和公式(二)——Excel基础(2)
  • 原文地址:https://www.cnblogs.com/zhanqun/p/10298218.html
Copyright © 2011-2022 走看看