下载安装Elasticsearch 6.3.1
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz
tar -xvzf elasticsearch-6.3.1.tar.gz
cd elasticsearch-6.3.1
# 添加用户 新es不允许使用root启动
adduser esuser
# 创建目录
mkdir -p esdata/data
mkdir -p esdata/log
chown -R esuser elasticsearch-6.3.1
chown -R esuser esdata
目录 elasticsearch-6.3.1/config/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: 你的路径/esdata/data
#
# Path to log files:
#
path.logs: 你的路径/esdata/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: 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 new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery 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:
#
# 允许远程访问
network.host: 0.0.0.0
action.destructive_requires_name: true
# 允许跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
配置系统
vim /etc/security/limits.conf(在文件最后添加)
配置完如下
* soft nproc 4096
* hard nproc 4096
root soft nproc 4096
root hard nproc 4096
# 以下配置解决如下错误
# max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
# memory locking requested for elasticsearch process but memory is not locked
esuser hard nofile 65536
esuser soft nofile 65536
esuser soft memlock unlimited
esuser hard memlock unlimited
继续配置
[root@localhost bin]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
[root@localhost bin]# more /proc/sys/vm/max_map_count
262144
以上配置解决这个问题
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
继续配置
vim /etc/sudoers
这里改成
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
esuser ALL=(ALL) ALL
以上配置解决某些情况下无法读写的问题
启动
su esuser
cd elasticsearch-6.3.1
./bin/elasticsearch
浏览器输入你的地址 xxx:9200,出现以下信息,成功
"name" : "9PmAp5Z",
"cluster_name" : "my-application",
"cluster_uuid" : "XI5DMSv2Q027pUH5fkWnIw",
"version" : {
"number" : "6.3.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "eb782d0",
"build_date" : "2018-06-29T21:59:26.107521Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}