LINUX单机部署Elasticsearch详细教程

1.Elasticsearch安装包下载

 官网下载地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

2.安装Elasticsearch

2.1 这里安装的版本是7.8.0

2.2 在user/local下创建elasticsearch

mkdir elasticsearch

2.3 在elasticsearch下创建二个文件夹

#elasticsearch数据目录
mkdir data

#elasticsearch日志目录
mkdir log

2.4 将安装包上传到 elasticsearch 上解压

tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz

3.创建 Elasticsearch 用户

#创建用户名

sudo useradd es

#创建密码

sudo passwd es

4.修改Elasticsearch权限

chown -R es /usr/local/elasticsearch

chown -R es /usr/local/elasticsearch/elasticsearch-7.8.0/config/elasticsearch.keystore

5.配置elasticsearch

5.1修改elasticsearch.yml配置文件 

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

#设置参数
node.name: node-1
path.data: /usr/local/elasticsearch/data #数据存放路径
path.log: /usr/local/elasticsearch/log #日志存放路径
network.host: 0.0.0.0 #本机IP地址(设置可以访问的ip地址)
http.port: 9200 #es暴露对外的端口

http.cors.enabled: true #跨域配置

http.cors.allow-origin: "*" #跨域配置

完整配置文件 

# ======================== 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: /usr/local/elasticsearch/data
#
# Path to log files:
#
path.logs: /usr/local/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):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9035
#
# 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"]
#
# 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: "*"   #跨域配置

5.2 修改/etc/security/limits.conf配置文件

#在文件末尾插入
es soft nofile 65536
es hard nofile 65536

5.3 配置 Elasticsearch JVM内存

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

#修改配置
-Xms256m
-Xmx256m

## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

#-Xms1g
#-Xmx1g
-Xms256m
-Xmx256m

################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################

## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly

## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC
14-:-XX:G1ReservePercent=25
14-:-XX:InitiatingHeapOccupancyPercent=30

## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}

## heap dumps

# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log

## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m

6.启动Elasticsearch

#切换到es用户

su - es

#启动Elasticsearch

/usr/local/elasticsearch/elasticsearch-7.8.0/bin/elasticsearch -d

#查看是否启动成功

jps

当出现Elasticsearch说明启动成功!

 

7.异常处理 

7.1 若启动报错:

No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender

#切换到root用户

chown -R es /usr/local/elasticsearch/log/

7.2 若启动报错:

java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?

#kill掉es进程

 kill -9 进程

#重新启动es

/usr/local/elasticsearch/elasticsearch-7.8.0/bin/elasticsearch -d

下面是在 CentOS 上单机部署 Elasticsearch 和 X-Pack 的步骤: 1. 首先下载 Elasticsearch 和 X-Pack 的安装包。可以到官网下载最新版本,也可以使用 yum 安装。 2. 安装 Java 环境。Elasticsearch 需要 Java 环境的支持。可以使用以下命令安装 OpenJDK: ``` sudo yum install java-1.8.0-openjdk ``` 3. 解压 Elasticsearch 和 X-Pack 的安装包,并将其移动到 /usr/share 目录下: ``` sudo tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz sudo mv elasticsearch-7.6.2 /usr/share/elasticsearch sudo tar -zxvf x-pack-7.6.2-linux-x86_64.tar.gz sudo mv x-pack-7.6.2 /usr/share/x-pack ``` 4. 创建一个新用户来运行 Elasticsearch。可以使用以下命令创建一个名为 elasticsearch 的用户: ``` sudo useradd elasticsearch ``` 5. 给 Elasticsearch 和 X-Pack 相应的目录设置权限: ``` sudo chown -R elasticsearch:elasticsearch /usr/share/elasticsearch sudo chown -R elasticsearch:elasticsearch /usr/share/x-pack ``` 6. 修改 Elasticsearch 的配置文件。编辑 /usr/share/elasticsearch/config/elasticsearch.yml 文件,修改以下配置项: ``` cluster.name: my_cluster node.name: node1 network.host: 0.0.0.0 http.port: 9200 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/share/x-pack/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/share/x-pack/elastic-certificates.p12 xpack.security.http.ssl.enabled: true xpack.security.http.ssl.keystore.path: /usr/share/x-pack/http.p12 xpack.security.http.ssl.truststore.path: /usr/share/x-pack/http.p12 ``` 注意:xpack.security.enabled 设置为 true 是启用 X-Pack 的关键。xpack.security.transport.ssl.enabled 和 xpack.security.http.ssl.enabled 分别启用 Elasticsearch 和 HTTP 安全性。 7. 启动 Elasticsearch。使用以下命令启动 Elasticsearch: ``` sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch ``` 8. 验证 Elasticsearch 是否正常运行。在浏览器中访问 http://your_ip_address:9200,如果能够看到 Elasticsearch 的版本信息,则表示 Elasticsearch 已经成功运行。 至此,Elasticsearch 和 X-Pack 的单机部署就完成了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值