• CentOS7 安装 ElasticSearch7


    一.安装ES

    1.

    curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz

    2.

    tar -xvf elasticsearch-7.6.2-linux-x86_64.tar.gz

    3.创建运行ES的用户

    # 1、创建新的用户
    adduser elasticsearch
    # 2、设置用户密码
    passwd elasticsearch
    # 3、授权给新建用户es文件夹的权限
    chown -R elasticsearch /usr/local/software/elasticsearch-7.10.1
    # 4、切换用户
    su elasticsearch

    4.修改配置

    cd /usr/local/software/elasticsearch-7.6.2/config
    vi elasticsearch.yml
    
    a、集群名称,需确保不同的环境中集群的名称不重复,否则节点可能会连接到错误的集群上
    
    cluster.name: test-es-1
    
    b、节点名称,默认情况下当节点启动时Elasticsearch将随机在一份3000个名字的列表中随机指定一个。如果机器上只允许运行一个集群Elasticsearch节点,可以用${HOSTNAME}设置节点的名称为主机节点。节点默认名称为机器的主机名。
    
    node.name: node-1
    
    c、网络设置,绑定服务到指定IP(提供服务的网口)
    
    network.host: 0.0.0.0
    
    http.port: 9200
    
    d、集群主节点信息
    
    cluster.initial_master_nodes: [“node-1”]

    5.系统设置

    1设置内核参数。
    Elasticsearch mmapfs默认使用目录来存储其索引。默认的操作系统对mmap计数的限制可能太低,这可能会导致内存不足异常。
        vi /etc/sysctl.conf
    
        vm.max_map_count=262144
    
        sysctl -p
    
    2 配置当前用户每个进程最大同时打开文件数
        su root
        #查看硬限制
        ulimit -Hn
        ulimit -Sn
    
        通常情况下如果值是4096启动ES时会报如下错误
        max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    
        修改配置文件
    
        vi /etc/security/limits.conf
    
        es_starter hard nofile 65537
        es_starter soft nofile 65536
    
        sysctl -p
    
        上面两行语句表示,elasticsearch用户的软限制为65536,硬限制为65536,即表示elasticsearch用户不管它开启多少个shell能打开的最大文件数量为65536。
    
       其中 elasticsearch表示启动ElasticSearch的用户。
    
       在设定上,通常soft会比hard小,举例来说,sofr可以设定为80,而hard设定为100,那么你可以使用到90(因为没有超过100),但介于80~100之间时,系统会有警告信息。
     
       修改了limits.conf,不需要重启,重新登录即生效。

    6.启动ElasticSearch
    注意:启动需要使用专门用户,本例启动es的用户为 “elasticsearch”,如果使用root启动会报错,会生成一些只有root用户才能操作的文件,这会导致即使正确启动仍然会报错。

    解决方法是将这些root用户才能操作的文件改为elasticsearch可操作。

    1.启动 es, -d 命令是让es服务在后台运行
      #使用elasticsearch用户
      su elasticsearch
      #进入ES启动脚本目录
      cd /usr/local/software/elasticsearch-7.10.1/bin
      #启动ES, -d参数是为了让ES服务在后台运行
      ./elasticsearch -d
    2.curl http://localhost:9200

     7.关闭

    #查询ES的进程信息,获取进程ID
    ps -ef | grep elasticsearch
    
    #杀掉ES进程
    kill -9 1234  #1234为ES的进程ID

    8.开机自启动

      8.1先查看当前的开机启动服务; 

    chkconfig --list

      8.2创建es 的系统启动服务文件

    cd /etc/init.d      【进入到目录】
    vim elasticsearch    【创建es系统启动服务文件】

      8.3编写启动脚本;

    #!/bin/bash
    #chkconfig: 345 63 37
    #description: elasticsearch
    #processname: elasticsearch-7.6.2
    
    export ES_HOME=/usr/local/software/elasticsearch-7.6.2
    
    case $1 in
            start)
                    su elasticsearch<<!
                    expect "password"
                    cd $ES_HOME
                    ./bin/elasticsearch -d -p pid
                    exit
    !
                    echo "elasticsearch is started"
                    ;;
            stop)
                    pid=`cat $ES_HOME/pid`
                    kill -9 $pid
                    echo "elasticsearch is stopped"
                    ;;
            restart)
                    pid=`cat $ES_HOME/pid`
                    kill -9 $pid
                    echo "elasticsearch is stopped"
                    sleep 1
                    su elasticsearch<<!
                    expect "password"
                    cd $ES_HOME
                    ./bin/elasticsearch -d -p pid
                    exit
    !
                    echo "elasticsearch is started"
            ;;
        *)
            echo "start|stop|restart"
            ;;
    esac
    exit 0

      8.4修改文件权限;

    chmod 777 elasticsearch

      8.5添加和删除服务并设置启动方式;

    chkconfig --add elasticsearch    【添加系统服务】
    chkconfig --del elasticsearch    【删除系统服务】

      8.6关闭和启动服务

    service elasticsearch start     【启动】
    service elasticsearch stop      【停止】
    service elasticsearch restart     【重启】

      8.7设置服务是否开机启动;

    chkconfig elasticsearch on      【开启】
    chkconfig elasticsearch off       【关闭】

      8.8验证是否已启动命令:

    ps -ef | grep elasticsearch    【查看是否有es的进程】
    结束进程命令用kill -9  进程ID
     

    二.安装可视化页面插件elasticsearch-head

    1.下载地址:GitHub - mobz/elasticsearch-head: A web front end for an elastic search cluster

     2.安装

    3.由于ES进程和客户端进程端口号不同,存在跨域问题,所以需要在ES的配置文件中配置下解决跨域问题:

    vim /usr/local/software/elasticsearch-7.6.2/config/elasticsearch.yml
    加上
    http.cors.enabled:true
    http.cors.allow-origin:"*"

    4.如果es安装不是本机的话,还需要修改

    修改es-head目录下的/Gruntfile.js,增加hostname属性,也可以自行更改监听地址

    在es-head的安装目录下_site/app.js,将这一行的localhost改成你的主机名或公网IP
    
    this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://localhost:9200“;
    
    把localhost修改成你es的服务器地址,如:
    
    this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://192.168.19.105:9200“;

    5.设置开机自启动,脚本如下:

    #!/bin/sh
    #chkconfig: 2345 80 05
    #description: elasticsearch-head
     
    # nodejs 安装的路径
    export NODE_PATH=/usr/local/software/node-v16.13.2-linux-x64
    export PATH=$PATH:$NODE_PATH/bin
     
    # elasticsearch-head 的路径
    
    ESHEAD_HOME=/usr/local/software/elasticsearch-head-master/
    
    case $1 in
      start)
        cd $ESHEAD_HOME
            nohup npm run start >/usr/local/software/elasticsearch-head-master/nohup.out 2>&1 &
        echo "eshead is started"
        ;;
      stop)
        pid=`lsof -t -i:9100`
            kill -9 $pid
        echo "eshead is stop"
        ;;
      restart)
        pid=`lsof -t -i:9100`
            kill -9 $pid
            echo "eshead is stopped"
        sleep 1
            cd $ESHEAD_HOME
            nohup npm run start >/usr/local/software/elasticsearch-head-master/nohup.out 2>&1 &
        echo "eshead is started"
        ;;
      *)
        echo "start|stop|restart"
        ;;
    esac
    exit 0

    三.安装ik分词器

      1.下载地址: Releases · medcl/elasticsearch-analysis-ik · GitHub

      2. 将插件存放于plugins文件夹

    cd /usr/local/software/elasticsearch-7.6.2/plugins
    unzip elasticsearch-analysis-ik-7.6.2.zip

      3.重启es

  • 相关阅读:
    简单使用Git和Github来管理自己的代码和读书笔记
    js中的事件委托
    join和split的区别
    浮动的清除方式
    图片代替多选(单选)按钮
    js和jquery实现简单的选项卡
    闭包——之初理解
    Django REST framework+Vue 打造生鲜超市(七)
    Django REST framework+Vue 打造生鲜超市(六)
    Django REST framework+Vue 打造生鲜超市(五)
  • 原文地址:https://www.cnblogs.com/yangfei123/p/15827406.html
Copyright © 2020-2023  润新知