环境介绍:CentOS七、jdk11.0.五、Elasticsearch7.5.1html
准备三台Linux系统,本教程使用的是CentOS7以下IP地址:node
192.168.28.129 192.168.28.130 192.168.29.131
注意:
以上三台Linux系统都要安装jdklinux
Linux: elasticsearch-7.5.1-linux-x86_64.tar.gzbootstrap
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
Elasticsearch不能在 root
用户下启动,咱们须要在三台机器上分别建立一个普通用户:vim
# 建立elastic用户 useradd elastic # 设置用户密码 passwd elastic # 切换到elastic用户 su elastic
分别在三台机器上的 /home/elastic/
目录下建立elasticsearch文件夹,而后在elasticsearch文件夹下分别建立data、logs文件夹:服务器
cd /home/elastic/ mkdir -p elasticsearch/data mkdir -p elasticsearch/logs
在生产环境下咱们要把Elasticsearch生成的索引文件数据存放到自定义的目录下
data:存储Elasticsearch索引文件数据
logs:存储日志文件app
咱们只须要简单的配置一下Elasticsearch就能够使用了curl
首先咱们将下载好的 elasticsearch-7.5.1-linux-x86_64.tar.gz
压缩包上传到 192.168.28.129
这台机器上的 /home/elastic/elasticsearch/
目录下,随便那一台机器均可以没有顺序区分。elasticsearch
解压 elasticsearch-7.5.1-linux-x86_64.tar.gz
ide
tar -xvf elasticsearch-7.5.1-linux-x86_64.tar.gz
解压完成后在 /home/elastic/elasticsearch/
目录下输入 ll
命令查看当前目录下的全部文件和文件夹以下:
输入以下命令修改 elasticsearch.yml
配置文件:
vi elasticsearch-7.5.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: /home/elastic/elasticsearch/data # # Path to log files: # path.logs: /home/elastic/elasticsearch/logs # # ----------------------------------- 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: 192.168.28.129 # # 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: ["192.168.28.129", "192.168.28.130", "192.168.28.131"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["node-1", "node-2", "node-3"] # # 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 # # ---------------------------------- xpack ------------------------------------- # xpack.monitoring.collection.enabled: true
主要修改以下几处配置:
cluster.name
的值必需要相同。0.0.0.0
(任何地址都能访问到)。9200
便可,固然你也能够修改咱们已经配置好一台Elasticsearch节点了接下来咱们只须要把这台配置好的Elasticsearch复制到另外两台机器中在作一些简单的修改就就能够了。
咱们使用 scp
命令复制当前配置好的Elasticsearch到另外两台机器中:
scp -r /home/elastic/elasticsearch/elasticsearch-7.5.1 elastic@192.168.28.130:/home/elastic/elasticsearch/elasticsearch-7.5.1 scp -r /home/elastic/elasticsearch/elasticsearch-7.5.1 elastic@192.168.28.131:/home/elastic/elasticsearch/elasticsearch-7.5.1
分别在两台机器中修改几处配置:192.168.28.130
这台机器修改elasticsearch.yml配置文件以下:
node.name: node-2 network.host: 192.168.28.130
192.168.28.131
这台机器修改elasticsearch.yml配置文件以下:
node.name: node-3 network.host: 192.168.28.131
Elasticsearch能够从命令行启动,以下所示:
./bin/elasticsearch
做为后台启动
要将Elasticsearch做为后台程序运行,请在命令中指定-d
,而后使用-p
将进程ID记录在文件中:
./bin/elasticsearch -d -p pid
分别在三台机器上启动Elasticsearch,启动过程当中建议单个机器启动成功后在启动另外一台。
注意:
在启动过程当中若是出现错误请看下面章节
下面的全部修改在生产环境下均可能不会出现,若是出现了就作相应的修改便可
修改系统配置文件须要切换到 root
用户下:
su root
会提示你输入 root
用户密码,输入正确的密码便可
将虚拟内存设置大一些,不然在启动elasticsearch时会出错致使启动失败:
ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
输入 vi /etc/sysctl.conf
命令在 sysctl.conf
中配置以下内容:
vm.max_map_count=655360
接着输入以下命令让配置生效:
sysctl -p
在启动Elasticsearch有可能会出现以下错误:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
错误说明:elasticsearch过程的最大文件描述符 [4096]
过低,增长到
最少 [65536]
接下来咱们修改最大文件描述符,输入 vi /etc/security/limits.conf
命令在 limits.conf
中配置以下内容:
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
在启动Elasticsearch有可能会出现以下错误:
[2]: max number of threads [1024] for user [elsearch] is too low, increase to at least[4096]
错误说明:线程[1024]
用户[elsearch]
的最大数量过低,增长至少[4096]
接下来咱们修改线程数,输入 vi /etc/security/limits.d/20-nproc.conf
命令在 20-nproc.conf
中配置以下内容:
* soft nproc 4096
在启动Elasticsearch有可能会出现以下错误:
[3]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
错误说明:系统调用过滤器安装失败;检查日志和修复配置或禁用系统调用过滤器须要您自担风险
这是在由于 Centos7
不支持 SecComp
,而ES5.2.0以后默认 bootstrap.system_call_filter
为true
进行检测,因此致使检测失败,失败后直接致使ES不能启动。
接下来咱们修改配置文件,输入 vim config/elasticsearch.yml
命令,在 elasticsearch.yml
中配置以下内容:
# ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # 设置为false不进行检测 bootstrap.system_call_filter: 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. #
上面咱们已经搭建好了三个节点的集群,而且已经启动了。
接下来咱们来检查一下集群是否已经造成,给三台服务器中的任意一台发送http请求:
http://192.168.28.129:9200/_cat/health?v
应该会反馈以下内容:
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1579067395 05:49:55 my-application green 3 3 22 11 0 0 0 0 - 100.0%
cluster:显示的是当前集群的名称
status:显示的是 green
表示当前集群是健康的状态
node.total:显示 3
表示当前集群有三个节点
最后咱们的Elasticsearch集群已经搭建好了,本教程主要参考Elastic官方文档。