0


linux centos7安装部署安装Elasticsearch并后台启动

centos7安装部署安装Elasticsearch

文章目录


前言

为什么要使用“Elastic Stack”   
 它到底是什么?它是一组快速且高度可扩展的组件(Elasticsearch、Kibana、Beats、Logstash 等),
 它们共同使您能够安全地从任何来源以任何格式获取数据,
 然后对其进行搜索、分析和可视化。
    官网地址:
    https://www.elastic.co/cn/
    tar包地址
    https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-17-3

一、安装环境?

jdk1.8、elasticsearch-7.17.3-linux-x86_64

二、安装及启动步骤

1、解压 elasticsearch-7.17.3-linux-x86_64.tar

1:切换到/opt/software 目录
    cd /opt/software
2:创建es目录
    mkdir es
3:将elasticsearch-7.17.3-linux-x86_64.tar上传至 /opt/software/es
4:解压缩es安装包
    tar -zxvf elasticsearch-7.17.3-linux-x86_64.tar    
5、修改配置文件
    cd /opt/software/es/elasticsearch-7.17.3 /config
    vim elasticsearch.yml                                --编辑es配置文件
    单机如下图配置所示                                      --##EDIT下为修改部分
# ======================== 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:##EDIT
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: /path/to/data## Path to log files:##path.logs: /path/to/logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:#关闭自检程序##EDIT
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 -----------------------------------#网络配置# By default Elasticsearch is only accessible on localhost. Set a different# address here to expose this node on the network:##EDIT
network.host: 本机ip
## By default Elasticsearch listens for HTTP traffic on the first free port it# finds starting at 9200. Set a specific HTTP port here:##EDIT
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:##EDIT
cluster.initial_master_nodes: ["node-1"]## For more information, consult the discovery and cluster formation module documentation.## ---------------------------------- Various -----------------------------------## Require explicit names when deleting indices:##action.destructive_requires_name: true## ---------------------------------- Security ----------------------------------##                                 *** WARNING ***## Elasticsearch security features are not enabled by default.# These features are free, but require configuration changes to enable them.# This means that users don’t have to provide credentials and can get full access# to the cluster. Network connections are also not encrypted.## To protect your data, we strongly encourage you to enable the Elasticsearch security features. # Refer to the following documentation for instructions.## https://www.elastic.co/guide/en/elasticsearch/reference/7.16/configuring-stack-security.html#增加跨域配置##EDIT
http.cors.enabled: true
http.cors.allow-origin: "*"

6、修改jvm.options配置文件

#################################################################### JVM configuration###################################################################### WARNING: DO NOT EDIT THIS FILE. If you want to override the## JVM options in this file, or set any additional options, you## should create one or more files in the jvm.options.d## directory containing your adjustments.#### See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/jvm-options.html## for more information.#################################################################################################################################### IMPORTANT: JVM heap size#################################################################### The heap size is automatically configured by Elasticsearch## based on the available memory in your system and the roles## each node is configured to fulfill. If specifying heap is## required, it should be done through a file in jvm.options.d,## and the min and max should be set to the same value. For## example, to set the heap to 4 GB, create a new file in the## jvm.options.d directory containing these lines:##EDIT
-Xms512m
-Xmx512m
#### See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/heap-size.html## for more information#################################################################################################################################### Expert settings#################################################################### All settings below here are considered expert settings. Do## not adjust them unless you understand what you are doing. Do## not edit them in this file; instead, create a new file in the## jvm.options.d directory containing your adjustments.#################################################################### GC configuration8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=758-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:-UseCMSInitiatingOccupancyOnly14-:-XX:+UseG1GC

## 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 unless an alternative path is# specified
-XX:+HeapDumpOnOutOfMemoryError

# exit right after heap dump on out of memory error. Recommended to also use# on java 8 for supported versions (8u92+).9-:-XX:+ExitOnOutOfMemoryError

# 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 logging8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=328:-XX:GCLogFileSize=64m

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

7、创建用户并赋予权限,不能再root用户下启动
useradd 用户名
passwd 用户名 随后会提示输入密码
赋予权限
cd /opt/software/es
chown -R 用户名:用户名 ./ —chown将指定文件的拥有者改为指定的用户或组,
usermod -g root 用户 —将当前用户添加至root组
8、elasticsearch 启动的时候要求当前用户最大线程数至少为 4096 个线程,修改当前用户最大线程数
如下所示
显示 当前用户拥有线程数 ulimit -a

core file size          (blocks, -c)0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e)0file size               (blocks, -f) unlimited
pending signals                 (-i)3834                  -----此处为当前用户线程数
max locked memory       (kbytes, -l)64
max memory size         (kbytes, -m) unlimited
open files                      (-n)1024
pipe size            (512 bytes, -p)8
POSIX message queues     (bytes, -q)819200
real-time priority              (-r)0
stack size              (kbytes, -s)8192
cpu time(seconds, -t) unlimited
max user processes              (-u)3834
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

修改线程数
vim /etc/security/limits.conf
文件末尾加入 如下三行

用户名 soft nofile 65536
用户名 hard nofile 65536
用户名  -  nproc  65535

2、 前台启动elasticsearch

cd /opt/software/es/elasticsearch-7.17.3/bin
./elasticsearch                                            --前台启动es
http://ip:9200                                               --访问es网址
如下
{"name":"node-1",
  "cluster_name":"elasticsearch",
  "cluster_uuid":"933ymxObQnKVmo3j6jXp0g",
  "version":{"number":"7.17.3",
    "build_flavor":"default",
    "build_type":"tar",
    "build_hash":"5ad023604c8d7416c9eb6c0eadb62b14e766caff",
    "build_date":"2022-04-19T08:11:19.070913226Z",
    "build_snapshot": false,
    "lucene_version":"8.11.1",
    "minimum_wire_compatibility_version":"6.8.0",
    "minimum_index_compatibility_version":"6.0.0-beta1"},
  "tagline":"You Know, for Search"}
前台启动成功

3、 后台启动elasticsearch

后台启动

./bin/elasticsearch -d                                    

本文转载自: https://blog.csdn.net/fm521521/article/details/131135243
版权归原作者 @小白— 所有, 如有侵权,请联系我们删除。

“linux centos7安装部署安装Elasticsearch并后台启动”的评论:

还没有评论