elasticsearch linux 上安装

发布时间 2024-01-10 16:33:05作者: leolzi

1、下载安装包,放到服务器指定目录下:

 2、解压,到指定文件夹 命令 tar  -xzf  elasticsearch-8.11.3-linux-x86_64.tar.gz

3、创建用户并授权:

sudo useradd es

sudo passwd es

用户授权指定目录权限: chown -R es:es /opt/module/es-7.8.0

 给新创建的普通用户设置sudo权限  vim /etc/sudoers

在root ALL(ALL) ALL下面新增
es ALL(ALL) ALL

或:

# 使用root用户执行
visudo
# 在 root ALL(ALL) ALL下面新增
es ALL(ALL) ALL

 

4、  前置准备

每个进程可以打开的文件数的限制    vim /etc/security/limits.conf  末尾新增:

es soft nofile 65536

es hard nofile 65536

每个进程可以打开的文件数的限制;操作系统级别对每个用户创建的进程数的限制

vim /etc/security/limits.d/20-nproc.conf

es soft nofile 65536

es hard nofile 65536

* hard nproc 4096     注:* 带表 Linux 所有用户名称

sudo vim /etc/sysctl.conf

一个进程可以拥有的 VMA(虚拟内存区域)的数量,默认值为 65536

vm.max_map_count=655360

保存后执以下命令使配置生效  

sudo sysctl -p

5、修改JVM配置 根据实际情况修改

##

-Xms1g -

Xmx1g

##

主要修改以下参数值

cluster.name: my-application

node.name: node-1

path.data: ./data

path.logs: ./logs

network.host: 0.0.0.0

http.port: 9200

cluster.initial_master_nodes: ["node-1"]

Note:cluster.initial_master_nodes必须配置(即使名字跟默认的一样,也要放开注释),否则启动失败,失败日志「elasticsearch.log」说如下:

6、启动es--在es用户下面执行

bin/elasticsearch -d

jps

ps -ef | grep es

 

命令行验证:

curl 127.0.0.1:9200

 

7、重启: 

ps -ef|gerp elastic 

kill -9  xxxx

 

8、重启脚本

#!/bin/bash
#chkconfig: 2345 54 26
#description: elasticsearch
#processname: elasticsearch

ES_HOME=/var/local/elasticsearch

start(){                           
        su - elastic -c "$ES_HOME/bin/elasticsearch -d -p pid"
        echo "es is started"
}
stop(){                                
        pid=`cat $ES_HOME/pid`
        kill -9 $pid
        echo "es is stopped"
}
status(){
        ps aux | grep $ES_HOME
}
restart(){              
        stop
        sleep 1
        start
}
case "$1" in        
"start")
        start      
        ;;
"stop")            
        stop
        ;;
"status")
        status
        ;;
"restart")            
        restart
        ;;
*)      
        echo "支持指令:$0 start|stop|restart|status"
        ;;
esac

/etc/init.d目录下创建启动、关闭服务的脚本,脚本中要设置运行级别、启动优先级、关闭优先级

chmod +x /etc/init.d/xxx

 # 添加开机自启 chkconfig --add xxx

# 状态设置为启动 chkconfig xxx on

service elastic status

service elastic start

service elastics stop

 

参考博客:https://blog.csdn.net/m0_52735414/article/details/128847505