Linux 安裝和配置Elastiscsearch

1、上傳Elastiscsearch安裝壓縮包到服務器/opt目錄上

2、修改內核參數max_map_count
max_map_count包含限制一個進程可以擁有的VMA(虛擬內存區域)的數量

vim /etc/sysctl.conf

在最後添加下面一行

vm.max_map_count = 262144

加載配置生效

sysctl -p

查看當前值

sysctl -a|grep vm.max_map_count

3、解壓Elastiscsearch安裝包、重命名

cd /opt
tar -zxvf elasticsearch-5.6.9.tar.gz
mv elasticsearch-5.6.9 elasticsearch

4、創建Elasticsearch用戶組、用戶、創建日誌和數據目錄、授權

groupadd elasticsearch
useradd elasticsearch -g elasticsearch
mkdir {elasticsearch/logs,elasticsearch/data}
chown -R elasticsearch:elasticsearch elasticsearch

5、修改配置

vim /opt/elasticsearch/config/elasticsearch.yml

在最後面加上(下面network.host的內網IP地址根據實際填寫):

cluster.name: my-application 
node.name: node-1 
network.host: 內網IP地址

6、配置系統配置文件

vim /etc/sysconfig/elasticsearch

添加如下內容,其中路徑根據實際情況填寫:

################################
# Elasticsearch
################################

# Elasticsearch home directory
ES_HOME=/opt/elasticsearch

# Elasticsearch Java path
JAVA_HOME=/usr/local/jdk   

# Elasticsearch configuration directory
CONF_DIR=/opt/elasticsearch/config

# Elasticsearch data directory
DATA_DIR=/opt/elasticsearch/data

# Elasticsearch logs directory
LOG_DIR=/opt/elasticsearch/logs

# Elasticsearch PID directory
PID_DIR=/opt/elasticsearch

# Additional Java OPTS
#ES_JAVA_OPTS=

# Configure restart on package upgrade (true, every other setting will lead to not restarting)
#RESTART_ON_UPGRADE=true

################################
# Elasticsearch service
################################

# SysV init.d
#
# When executing the init script, this user will be used to run the elasticsearch service.
# The default value is 'elasticsearch' and is declared in the init.d file.
# Note that this setting is only used by the init script. If changed, make sure that
# the configured user can read and write into the data, work, plugins and log directories.
# For systemd service, the user is usually configured in file /usr/lib/systemd/system/elasticsearch.service
ES_USER=elasticsearch
ES_GROUP=elasticsearch

# The number of seconds to wait before checking if Elasticsearch started successfully as a daemon process
ES_STARTUP_SLEEP_TIME=5

################################
# System properties
################################

# Specifies the maximum file descriptor number that can be opened by this process
# When using Systemd, this setting is ignored and the LimitNOFILE defined in
# /usr/lib/systemd/system/elasticsearch.service takes precedence
MAX_OPEN_FILES=65536

# The maximum number of bytes of memory that may be locked into RAM
# Set to "unlimited" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml.
# When using systemd, LimitMEMLOCK must be set in a unit file such as
# /etc/systemd/system/elasticsearch.service.d/override.conf.
MAX_LOCKED_MEMORY=unlimited

# Maximum number of VMA (Virtual Memory Areas) a process can own
# When using Systemd, this setting is ignored and the 'vm.max_map_count'
# property is set at boot time in /usr/lib/sysctl.d/elasticsearch.conf
MAX_MAP_COUNT=262144

7、配置Elastiscsearch系統服務啓動

vim /usr/lib/systemd/system/elasticsearch.service

添加如下內容,其中路徑根據實際情況填寫:

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

[Service]
Environment=ES_HOME=/opt/elasticsearch
Environment=CONF_DIR=/opt/elasticsearch/config
Environment=DATA_DIR=/opt/elasticsearch/data
Environment=LOG_DIR=/opt/elasticsearch/logs
Environment=PID_DIR=/opt/elasticsearch
EnvironmentFile=-/etc/sysconfig/elasticsearch

WorkingDirectory=/opt/elasticsearch

User=elasticsearch
Group=elasticsearch

ExecStartPre=/opt/elasticsearch/bin/elasticsearch-systemd-pre-exec

ExecStart=/opt/elasticsearch/bin/elasticsearch \
                                                -p ${PID_DIR}/elasticsearch.pid \
                                                --quiet \
                                                -Edefault.path.logs=${LOG_DIR} \
                                                -Edefault.path.data=${DATA_DIR} \
                                                -Edefault.path.conf=${CONF_DIR}

# 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=65536

# Specifies the maximum number of processes
LimitNPROC=2048

# 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 distribution-5.6.9 (distribution)

8、重新加載新的服務、設置開機自啓、啓動服務、關閉服務、查看啓動狀態

systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch
systemctl stop elasticsearch
systemctl status elasticsearch

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章