CentOS7安裝Elasticsearch7

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 packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
# Apache 2.0 license
#baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
yum install -y elasticsearch

配置服務

啓動服務以前必定要先配置/etc/elasticsearch/elasticsearch.ymlnetwork.hosthttp.portcluster.initial_master_nodeshtml

firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

# 啓動中止服務
sudo systemctl start elasticsearch
sudo 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: true
http.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目錄

類型 描述 默認位置 設置
home Elasticsearch主目錄或 $ES_HOME /usr/share/elasticsearch
bin 二進制腳本,包括elasticsearch啓動節點和elasticsearch-plugin安裝插件 /usr/share/elasticsearch/bin
conf 配置文件elasticsearch.yml /etc/elasticsearch ES_PATH_CONF
conf 環境變量,包括堆大小,文件描述符 /etc/sysconfig/elasticsearc
data 節點上分配的每一個索引、分片的數據文件的位置。能夠容納多個位置。 /var/lib/elasticsearch path.data
logs 日誌文件位置 /var/log/elasticsearch path.logs
plugins 插件文件位置。每一個插件都將包含在一個子目錄中。 /usr/share/elasticsearch/plugins
repo 共享文件系統存儲庫位置。能夠容納多個位置。文件系統存儲庫能夠放在此處指定的任何目錄的任何子目錄中。 Not configured path.repo

配置Elasticsearch

Elasticsearch默認使用/etc/elasticsearch運行時配置。此目錄的全部權以及此目錄中的全部文件在安裝時都設置爲root:elasticsearch,而且目錄設置了setgid標誌,以便在/etc/elasticsearch下建立的全部文件和子目錄,例如使用密鑰庫建立密鑰庫工具等。node

Elasticsearch默認讀取配置文件/etc/elasticsearch/elasticsearch.yml詳細說明shell

RPM還有一個系統配置文件(/etc/sysconfig/elasticsearch),容許設置如下參數。bootstrap

參數 說明
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: true

http.cors.enabled: true
http.cors.allow-origin: "*"

附錄:完整的elasticsearch.service文件

vim /lib/systemd/system/elasticsearch.service

[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
RuntimeDirectory=elasticsearch
PrivateTmp=true
Environment=ES_HOME=/usr/share/elasticsearch
Environment=ES_PATH_CONF=/etc/elasticsearch
Environment=PID_DIR=/var/run/elasticsearch
EnvironmentFile=-/etc/sysconfig/elasticsearch

WorkingDirectory=/usr/share/elasticsearch

User=elasticsearch
Group=elasticsearch

ExecStart=/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=journal
StandardError=inherit

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65535

# Specifies the maximum number of processes
LimitNPROC=4096

# Specifies the maximum size of virtual memory
LimitAS=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

# Built for packages-7.1.1 (packages)
相關文章
相關標籤/搜索