docker centos7离线安装ElasticSearch单机版

目录

本文以 elasticsearch-7.8.1为例。

1.下载ES并解压

shell 复制代码
cd /root/install
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-linux-x86_64.tar.gz
tar -zxvf elasticsearch-7.8.1-linux-x86_64.tar.gz

2.新建elasticsearch用户

使用root用户登录,新建elasticsearch用户。

shell 复制代码
useradd elasticsearch
passwd elasticsearch
chown -R elasticsearch:elasticsearch /root/install/elasticsearch-7.8.1

3.修改ES配置文件

shell 复制代码
vi /opt/elasticsearch-7.8.1/config/elasticsearch.yml
###############################################################
cluster.name: elasticsearch    #集群名
node.name: node-1    #节点名称
path.data: /opt/data/es/data    #数据存储路径
path.logs: /opt/data/es/logs    #日志存储路径
network.host: 0.0.0.0    #本机IP,可以写0.0.0.0
http.port: 9200    #访问端口
discovery.seed_hosts: ["127.0.0.1"]    #通信地址
cluster.initial_master_nodes: ["node-1"]    #master节点名称
http.cors.enabled: true #是否支持跨域,默认为false
http.cors.allow-origin: "*"    #当设置允许跨域,默认为*,表示支持所有域名
###############################################################

4.启动ES服务

shell 复制代码
# 切换用户 
su - elasticsearch
# 启动ES
sh /root/install/elasticsearch-7.8.1/bin/elasticsearch

5.设置开机启动

shell 复制代码
vi /etc/init.d/elasticsearch
#!/bin/bash
#
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-7.8.1

ES_HOME=/root/install/elasticsearch-7.8.1

case $1 in
  start)
    su - elasticsearch -c "$ES_HOME/bin/elasticsearch -d -p pid"
    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 - es -c "$ES_HOME/bin/elasticsearch -d -p pid"
    echo "elasticsearch is started"
    ;;
  *)
    echo "start|stop|restart"
    ;;  
esac
exit 0
shell 复制代码
chmod 777 /etc/init.d/elasticsearch
chkconfig --add elasticsearch #设置开机启动
chkconfig --del elasticsearch #删除开机启动

chkconfig elasticsearch on    #打开开机启动
chkconfig elasticsearch off   #关闭开机启动