Centos8.2安装Elasticsearch-7.11.1

1. 下载elasticsearch

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.11.1-linux-x86_64.tar.gz
cd elasticsearch-7.11.1
./bin/elasticsearch

2.下载kibana(配套UI)

curl -L -O https://artifacts.elastic.co/downloads/kibana/kibana-7.11.1-linux-x86_64.tar.gz
tar xzvf kibana-7.11.1-linux-x86_64.tar.gz
cd kibana-7.11.1-linux-x86_64/
./bin/kibana

都是开箱即用,建议手动移动目录到/usr/local/下

3.启动elasticsearch

   3.1 创建专用用户组和用户,root无法启动

groupadd es
useradd esuser -g es
passwd esuser

  3.2更改文件夹及内部文件的所属用户及组

chown -R esuser:es /usr/local/elasticsearch-7.11.1

  3.3 切换用户 到esuser

su esuser

  3.4 elasticsearch 配置

vim /usr/local/elasticsearch-7.11.1/config/elasticsearch.yml

添加两行,注意:冒号后面要带一个空格

network.host: 0.0.0.0

cluster.initial_master_nodes: ["node-1"]

 

  3.5 设置elasticsearch用户拥有的内存权限,至少需要262144

su root
vim /etc/sysctl.conf

 末尾添加一行:
 vm.max_map_count=262144

#立即生效
/sbin/sysctl -p

 3.6 jvm内存调小一些

vim /usr/local/elasticsearch-7.11.1/config/jvm.options

新增两行,将内存调整至512m

  -Xms512m
  -Xmx512m

3.7 自定义管理脚本

 

#!/bin/bash
#chkconfig: 2345 80 90
#description:elasticsearch
export ES_HOME=/usr/local/elasticsearch-7.11.1
case $1 in
        start)
                su esuser<<!        
                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 esuser<<!    
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
        ;;
    *)
        echo "start|stop|restart"
        ;;  
esac
exit 0
#赋予执行权限
chmod +x elasticsearch

 

 命令:

#启动
/etc/init.d/elasticsearch start
#停止
/etc/init.d/elasticsearch stop
#重启
/etc/init.d/elasticsearch restart

 4.安装ik分词器

cd /usr/local/elasticsearch-7.11.1/plugins

  4.1 新建一个ik目录

  4.2 下载与ES版本对于的分词器压缩包,下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

  4.3 解压压缩包到ik目录

  4.4 重启ES

 5.ElasticSearch设置用户名密码访问

vim /usr/local/elasticsearch-7.11.1/config/elasticsearch.yml

 添加如下:

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

 

 

posted @ 2021-02-20 09:58  b̶i̶n̶g̶.̶  阅读(171)  评论(0编辑  收藏  举报