目录
一、下载
国内镜像(支持 5.0-7.3):https://thans.cn/mirror/elasticsearch.html
Elasticsearch 官网 Download Elasticsearch | Elastic
官方下载安装教程:Install Elasticsearch from archive on Linux or MacOS | Elasticsearch Guide [7.14] | Elastic
二、安装
将安装文件解压到 /usr/local 目录下,然后进行一系列配置:
1、配置 limits.conf
文件描述符数量
vim /etc/security/limits.conf
文件尾部添加
* soft nofile 65536
* hard nofile 65536
2、配置 sysctl.conf
防止进程虚拟内存不足。
vim /etc/sysctl.conf
文件尾部设置
vm.max_map_count=262144
推出后执行,使配置生效。
sysctl -p
3、配置 elasticsearch.yml
配置主要参数。
日志路径:/home/es/logs
数据路径:/home/es/data
vim usr/local/elasticsearch-7.8.0/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: /home/es/data
#
# Path to log files:
#
path.logs: /home/es/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
#
# 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):
#
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: ["host1", "host2"]
#
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
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
#
# ---------------------------------- 自己添加 ----------------------------------
#设置为true锁住内存,当服务混合部署了多个组件及服务时,应开启此操作,允许es占用足够多的内存。
bootstrap.system_call_filter: false
4、配置 jvm.options
设置 heap 大小,设置小了会一直报错。
vim usr/local/elasticsearch-7.8.0/config/jvm.options
#-Xmx512m
#-Xmx512m
-Xms1g
-Xmx1g
5、添加新用户
es 不允许 root 用户启动,因此需要添加一个 es 用户,并且将 es 文件所属分配给该用户。
添加用户
useradd es
passwd es
chown -R es elasticsearch-7.8.0
或者 添加用户组和用户
groupadd es
usradd es
passwd es
chown -R es:es elasticsearch-7.8.0
6、启动 es
./bin/elasticsearch
./bin/elasticsearch -d # 后台运行
三、访问
1、命令行访问
curl(client url)可以在命令行模拟 http 请求。
curl http://localhost:9200
2、浏览器访问
http://localhost:9200
3、外部访问
开放防火墙端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload
systemctl daemon-reload
访问返回结果
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "A79OwZBtSnG85Z0LwBgo-A",
"version" : {
"number" : "7.8.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
"build_date" : "2020-06-14T19:35:50.234439Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}