三台ubuntuServer 的 ip: 192.168.0.4,192.168.0.5,192.168.0.6
从官网下载elasticsearch 版本2.2.1
解压到/opt/目录下
sudo tar -zxvf elasticsearch-2.2.1.tar.gz -C /opt
对ip为192.168.0.4的主机
进入/opt/elasticsearch-2.2.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 see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: qiaqia
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: dngel
#
# Add custom attributes to the node:
#
# node.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:
#
bootstrap.mlockall: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable 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: 192.168.0.4
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- 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.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["192.168.0.5", "192.168.0.6"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 2
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true
安装head插件
angel@192.168.0.4:/opt/elasticsearch-2.2.1/bin# sudo ./plugin install mobz/elasticsearch-head
其他插件安装可参照官网插件安装
配置另外两台主机
将elasticsearch-2.2.1复制到192.168.0.5和192.168.0.6
修改elasticsearch.yml
对192.168.0.5, 找到并修改下面配置
node.name: engel
network.host: 192.168.0.5
discovery.zen.ping.unicast.hosts: ["192.168.0.4", "192.168.0.6"]
对192.168.0.6, 找到并修改下面配置
node.name: fngel
network.host: 192.168.0.6
discovery.zen.ping.unicast.hosts: ["192.168.0.4", "192.168.0.5"]
调优
修改Es占用内存:vim /opt/elasticsearch-2..2.1/bin/elasticsearch.in.sh
找到 ES_MIN_MEM和ES_MAX_MEM,修改es最大和最小占用内存值, 这里我设置为1g,视机器具体情况而定
修改/etc/security/limits.conf
加上
angel soft memlock unlimited
angel hard memlock unlimited
angel soft nofile 65536
angel hard nofile 65536
重启电脑使配置生效angel
elasticsearch 的启动和关闭
分别在每个节点的/opt/elasticsearch-2.2.1/bin输入./elasticsearch
启动完毕后,可以输入curl '192.168.0.4:9200/_cluster/health?pretty'
查看集群健康状态
显示为green
{
"cluster_name": "qiaqia",
"status": "green",
"timed_out": false,
"number_of_nodes": 3,
"number_of_data_nodes": 3,
"active_primary_shards": 29,
"active_shards": 58,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 100
}
在浏览器输入http://192.168.0.4:9200/_plugin/head/
,可观察到集群状态