1.下载
下载地址: elasticsearch7.11.1
2.安装
解压到/software/elasticsearch
创建 data和log文件
mkdir var/elasticsearch/data
mkdir var/elasticsearch/log
转到 cd /software/elasticsearch/config
修改elasticsearch config下的 jvm.options内存
在修改config下的elasticsearch.yml文件
# ======================== Elasticsearch Configuration =========================#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------#
# Use a descriptive name for your cluster:
# 集群名称 可以通过不同的集群名称区分不同的集群#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------#
# Use a descriptive name for the node:
# 节点名称node.name: node-1
#
# Add custom attributes to the node:##node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 数据地址
path.data: /var/elasticsearch/data
#
# Path to log files:# 日志地址
path.logs: /var/elasticsearch/log
#
# ----------------------------------- Memory -----------------------------------#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 访问限制,一旦自定义了该参数值,ES就假设你正从开发模式过渡到生产模式,会将系统启动检查警告升级为异常。
#在投入生产环境之前,发现和形成集群需要配置两个重要的参数:discovery.seed_hosts及cluster.initial_master_nodes,以便集群中的节点能发现彼此并选出一个主节点。
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
# 访问端口
http.port: 9200
#
# For more information, consult the network module documentation.#
# --------------------------------- Discovery ----------------------------------#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#discovery.seed_hosts: ["127.0.0.1", "[::1]"]
# 主机发现,这里配置其他的节点主机名称或者IP
# 这个项目中不需要配置自己这台主机的IP,只需要提供其他节点的IP或主机名
# Bootstrap the cluster using an initial set of master-eligible nodes:
# 可选选举为主节点的节点主机名
# 这里需要填入所有主机名称,这里填入了所有的节点
# 表示集群中任何一个节点都可以选举称为主节点
#cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
3.启动
在 elasticsearch/bin目录下启动
正常启动 ./elasticsearch
后台运行 ./elasticsearch -d
3.1 不能使用root用户启动
添加组:groupadd elasticsearch
添加用户: useradd eluser -g elasticsearch -p eluser
root用户下赋权 :chown eluser:elasticsearch /software/elasticsearch -R
切换用户启动 :su eluser
3.2 启动异常
1.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
vim /etc/sysctl.conf
添加
vm.max_map_count = 655360
fs.file-max = 655360
保存然后运行
sysctl -p
4.设置开启启动
1、在/etc/init.d/目录创建es文件
vim /etc/init.d/es
2.添加脚本
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
#processname: elasticsearch-7.1.1
export JAVA_HOME=/software/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export ES_HOME=/software/elasticsearch/bin
export PATH=$ES_HOME/bin:$PATH
case $1 in
start)
su eluser<<!
cd $ES_HOME
cd bin
./elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
stop)
pid=`ps -ef | grep "Elasticsearch" |grep -v "grep" | awk '{print $2}'`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`ps -ef | grep "Elasticsearch" |grep -v "grep" | awk '{print $2}'`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su eluser<<!
cd $ES_HOME
cd bin
./elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
3.赋权
chmod 755 /etc/init.d/es
4.添加启动服务
chkconfig --add es
5.操作服务
启动 service es start
停止 service es stop
重启 service es restart
5.集群部署elasticsearch
1.复制三份
2.设置jvm.options配置,elasticsearch.yml中的data、log地址。
elasticsearch-00: elasticsearch.yml
elasticsearch-01: elasticsearch.yml
elasticsearch-02: elasticsearch.yml
增加多个/etc/init.d/下多个配置
逐个启动。
3.使用elasticsearch-head 验证