CentOS7安装Elasticsearch7

下载地址:https://www.elastic.co/cn/dow...

使用YUM安装

# 下载并安装公共签名密钥rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 配置RPM仓库vim /etc/yum.repos.d/elasticsearch.repo[elasticsearch-7.x]name=Elasticsearch repository for 7.x packagesbaseurl=https://artifacts.elastic.co/packages/7.x/yum# Apache 2.0 license#baseurl=https://artifacts.elastic.co/packages/oss-7.x/yumgpgcheck=1gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearchenabled=1autorefresh=1type=rpm-md
yum install -y elasticsearch

配置服务

启动服务之前一定要先配置/etc/elasticsearch/elasticsearch.ymlnetwork.hosthttp.portcluster.initial_master_nodes

firewall-cmd --zone=public --add-port=9200/tcp --permanentfirewall-cmd --reloadsudo /bin/systemctl daemon-reloadsudo /bin/systemctl enable elasticsearch.service# 启动停止服务sudo systemctl start elasticsearchsudo systemctl stop elasticsearch

测试服务

[root@localhost ~]# curl "http://127.0.0.1:9200/"{  "name" : "localhost.localdomain",  "cluster_name" : "elasticsearch",  "cluster_uuid" : "Pxdp0Z24SJ-MIBH_2oMe2A",  "version" : {    "number" : "7.1.1",    "build_flavor" : "default",    "build_type" : "rpm",    "build_hash" : "7a013de",    "build_date" : "2019-05-23T14:04:00.380842Z",    "build_snapshot" : false,    "lucene_version" : "8.0.0",    "minimum_wire_compatibility_version" : "6.8.0",    "minimum_index_compatibility_version" : "6.0.0-beta1"  },  "tagline" : "You Know, for Search"}

常用文件

# 配置文件vim /etc/elasticsearch/elasticsearch.yml# JVM配置vim /etc/elasticsearch/jvm.options# 启动日志tail -n 10 -f /var/log/elasticsearch/elasticsearch.log

问题处理

绑定IP和跨域

vim /etc/elasshellticsearch/elasticsearch.yml# 允许任意IP访问network.host: 0.0.0.0# 修改开放的端口http.port: 9200# 最后添加跨域http.cors.enabled: truehttp.cors.allow-origin: "*"

启动失败

启动报错信息如下:the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
vim /etc/elasticsearch/elasticsearch.yml# 修改【#cluster.initial_master_nodes: ["node-1", "node-2"] 】cluster.initial_master_nodes: ["node-1"]

进程虚拟内存不足

vim /etc/sysctl.conf# 添加vm.max_map_count=262144# 保存后执行sysctl -p

RPM目录

类型描述默认位置设置
homeElasticsearch主目录或 $ES_HOME/usr/share/elasticsearch
bin二进制脚本,包括elasticsearch启动节点和elasticsearch-plugin安装插件/usr/share/elasticsearch/bin
conf配置文件elasticsearch.yml/etc/elasticsearchES_PATH_CONF
conf环境变量,包括堆大小,文件描述符/etc/sysconfig/elasticsearc
data节点上分配的每个索引、分片的数据文件的位置。可以容纳多个位置。/var/lib/elasticsearchpath.data
logs日志文件位置/var/log/elasticsearchpath.logs
plugins插件文件位置。每个插件都将包含在一个子目录中。/usr/share/elasticsearch/plugins
repo共享文件系统存储库位置。可以容纳多个位置。文件系统存储库可以放在此处指定的任何目录的任何子目录中。Not configuredpath.repo

配置Elasticsearch

Elasticsearch默认使用/etc/elasticsearch运行时配置。此目录的所有权以及此目录中的所有文件在安装时都设置为root:elasticsearch,并且目录设置了setgid标志,以便在/etc/elasticsearch下创建的所有文件和子目录,例如使用密钥库创建密钥库工具等。

Elasticsearch默认读取配置文件/etc/elasticsearch/elasticsearch.yml,详细说明。

RPM还有一个系统配置文件(/etc/sysconfig/elasticsearch),允许设置以下参数。

参数说明
JAVA_HOME设置要使用的自定义Java路径。
MAX_OPEN_FILES最大打开文件数,默认为65535。
MAX_LOCKED_MEMORY最大锁定内存大小。如果需要通过elasticsearch.yml中的选项bootstrap.memory_lock来控制,就设置为unlimited
MAX_MAP_COUNT进程可能具有的最大内存映射区域数。如果您使用mmapfs 索引存储类型,请确保将其设置为较高的值。默认为262144。
ES_PATH_CONF配置文件目录(其中必须包括elasticsearch.ymljvm.optionslog4j2.properties); 默认目录 /etc/elasticsearch
ES_JAVA_OPTS其他JVM系统属性
RESTART_ON_UPGRADE在程序包升级时配置重新启动,默认为false。这意味着您必须在手动安装软件包后重新启动Elasticsearch实例。这样做的原因是为了确保群集中的升级不会导致连续的分片重新分配,从而导致高网络流量并缩短群集的响应时间。

附录:完整的elasticsearch.yml文件

vim /etc/elasticsearch/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/lib/elasticsearch## Path to log files:#path.logs: /var/log/elasticsearch## ----------------------------------- 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: 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: truehttp.cors.enabled: truehttp.cors.allow-origin: "*"

附录:完整的elasticsearch.service文件

vim /lib/systemd/system/elasticsearch.service[Unit]Description=ElasticsearchDocumentation=http://www.elastic.coWants=network-online.targetAfter=network-online.target[Service]RuntimeDirectory=elasticsearchPrivateTmp=trueEnvironment=ES_HOME=/usr/share/elasticsearchEnvironment=ES_PATH_CONF=/etc/elasticsearchEnvironment=PID_DIR=/var/run/elasticsearchEnvironmentFile=-/etc/sysconfig/elasticsearchWorkingDirectory=/usr/share/elasticsearchUser=elasticsearchGroup=elasticsearchExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet# StandardOutput is configured to redirect to journalctl since# some error messages may be logged in standard output before# elasticsearch logging system is initialized. Elasticsearch# stores its logs in /var/log/elasticsearch and does not use# journalctl by default. If you also want to enable journalctl# logging, you can simply remove the "quiet" option from ExecStart.StandardOutput=journalStandardError=inherit# Specifies the maximum file descriptor number that can be opened by this processLimitNOFILE=65535# Specifies the maximum number of processesLimitNPROC=4096# Specifies the maximum size of virtual memoryLimitAS=infinity# Specifies the maximum file sizeLimitFSIZE=infinity# Disable timeout logic and wait until process is stoppedTimeoutStopSec=0# SIGTERM signal is used to stop the Java processKillSignal=SIGTERM# Send the signal only to the JVM rather than its control groupKillMode=process# Java process is never killedSendSIGKILL=no# When a JVM receives a SIGTERM signal it exits with code 143SuccessExitStatus=143[Install]WantedBy=multi-user.target# Built for packages-7.1.1 (packages)