1.本实验在三台阿里云ECS服务器上安装elasticsearch,首先要实现三台机器内网互通,参考:https://blog.csdn.net/weixin_38875344/article/details/89146937。
实例名 |
内网IP |
外网IP |
||
node-1 |
master |
1.1.1.1 |
1.1.0.0 |
主节点 |
node-2 |
slave1 |
2.2.2.2 |
2.2.0.0 |
|
node-3 |
slave2 |
3.3.3.3 |
3.3.0.0 |
2.在 https://www.elastic.co/cn/downloads/past-releases/网站下载所需的版本。本实验所用的为7.1.0版本。
3.在三台服务器上分别安装jdk8。
4.elasticsearch不允许以root权限来运行。所以需要创建一个非root用户,以非root用户来起es。在三台机器上分别创建新用户。
#创建用户组
groupadd elastic
#创建新用户,设置用户组为,密码
useradd elasticsearch -g elastic -p elasticsearch
5.将elasticsearch解压到/opt目录。
tar -xzvf elasticsearch-7.1.0-linux-x86_64.tar.gz -C /opt
6.在三台机器上进行如下配置:
vim /etc/sysctl.conf
#在sysctl.conf中添加一行
vm.max_map_count = 655360
#执行此命令生效
sysctl -p
vim /etc/security/limits.conf
#添加如下内容:
* soft nofile 65536
* hard nofile 131072
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
7.修改/opt/elasticsearch-7.1.0/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: test
#
# ------------------------------------ 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/elasticsearch/data
#
# Path to log files:
#
path.logs: /var/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: false
#
# 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
network.publish_host: 1.1.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: ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
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
8.将elasticsearch-7.1.0重命名为elasticsearch,并分发到其他机器。
mv elasticsearch-7.1.0 elasticsearch
scp -r /opt/elasticsearch slave1:/opt
9.在另外两台机器上对elasticsearch.yml进行如下修改。
#slave1
node.name: node-2
network.publish_host: 2.2.0.0
#slave2
node.name: node-3
network.publish_host: 3.3.0.0
10.新建目录/var/elasticsearch/data与/var/elasticsearch/log并授权给elasticsearch用户。并将/opt/elasticsearch授权给新用户。
chown -R elasticsearch:elastic /var/elasticsearch/data
chown -R elasticsearch:elastic /var/elasticsearch/log
chown -R elasticsearch:elastic /opt/elasticsearch
11.在阿里云安全组中开放9200与9300端口。否则不能在浏览器中查看状态以及集群互通。
12.进入elasticsearch用户启动elasticsearch。
su elasticsearch
/opt/elasticsearch/bin/elasticsearch
13.安装kibana在其中一台机器上解压kibana-7.1.0。打开/opt/kibana/config/kibana.yml进行配置。配置信息如下:
server.host: 0.0.0.0
server.name: Kibana
elasticsearch.url: ["http://1.1.0.0:9200"]
i18n.locale: "zh-CN"
14.在安全组中添加5601端口,即可通过1.1.0.0:5601访问kibana。