这篇我们主要介绍elasticsearch的集群安装,但是有个条件,就是目前演示环境里面机器只有两台,所以我这里安装2个节点即可。真实的环境中我们一般还是安装奇数个会好一点。直接开始。
一、操作系统设置
1)在每一台服务器上创建一个es的用户
useradd es passwd es 输入密码即可
两台机器都做同样的操作
2)禁用服务器的swap
sed -i '/swap/s/^/#/' /etc/fstab swapoff -a
3)添加权重
vim /etc/sysctl.conf
添加如下内容
# 优化文件描述符 vm.max_map_count = 655300 # 优化脏内存页,es写入削峰 vm.dirty_ratio=10 vm.dirty_background_ratio=5 vm.dirty_writeback_centisecs=200 # 优化系统回收inode cache权重 vm.vfs_cache_pressure=200 vm.dirty_expire_centisecs=6000 vm.max_map_count=262144
再执行
sysctl -p
4)添加文件句柄
vim /etc/security/limits.conf
添加如下内容
* soft nofile 65536 * hard nofile 65536
以上就完成了对操作系统的配置,所有需要部署elasticsearch的服务器都需要操作上诉4个步骤。
二、部署elasticsearch
1)下载elasticsearch,这里我们以7.7为准。
下载地址是:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-x86_64.tar.gz
2)下载后解压放到/mnt目录下
3)为解压后的elasticsearch文件夹授权
chown -R es.es /mnt/elasticsearch7.7.0
4)修改JVM配置
vim /mnt/elasticsearch7.7.0/configjvm.options
把
-Xms1g -Xmx1g
这两个数值修改一下,建议修改为当前服务器的一半内存。如果这台服务器有其他应用在运行,则再适当修改小一点,但是xms和xmx的数值一定要配置成一样的。
4)修改elasticsearch.yml
/mnt/elasticsearch-7.7.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: es-cluster # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # # 节点名, 每个节点名应该不同 node.name: node-1 # 跨域相关配置 http.cors.enabled: true http.cors.allow-origin: "*" # # 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: /mnt/elasticsearch-7.7.0/data # # Path to log files: # path.logs: /mnt/elasticsearch-7.7.0/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.31.20 # # 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]"] #所有节点 hosts discovery.seed_hosts: ["192.168.31.20", "192.168.31.30"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["node-1","node-2"] # # 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 # 代表有资格竞争 master node.master: true # 代表为数据节点 node.data: true
5)启动es
cd /mnt/elasticsearch-7.7.0/bin/ ./elasticsearch -d
注意这里的elasticsearch需要的jdk版本是11的,因此如果系统里面有配置java_home为jdk8,那么需要修改下/mnt/elasticsearch-7.7.0/bin/elasticsearch 文件。
然后把当前的/mnt/elasticsearch7.7.0 scp到另外机器上,修改下 elasticsearch.yml里面的node.name和network.host,修改这两个值后,再启动elasticsearch即可。
到此我们两台机器上的es就都启动完了。这里主要是elasticsearch的集群安装完了,为了方便好看,大部分人都会再安装kinbana,用来查看es里面的信息。在这里我们推荐使用head插件。下面介绍下head插件安装。
1)从git上下载下来head插件。下载地址是:https://codeload.github.com/mobz/elasticsearch-head/zip/refs/heads/master
2)把下载的文件进行解压,然后进入到目录里面去
/mnt/elasticsearch-head-master
3)这个插件是单独使用nodejs启动的,所以这里我们需要安装nodejs,执行命令:
curl --silent --location https://rpm.nodesource.com/setup_10.x | bash - yum install -y nodejs
4)安装grunt
npm install -g grunt-cli npm install
5)修改Gruntfile.js
vim /mnt/elasticsearch-head-master/Gruntfile.js
在connect的地方添加hostname的值修改下:
connect: { server: { options: { hostname: '192.168.31.20', port: 9100, base: '.', keepalive: true } } }
6)然后把head插件启动起来
grunt server
7)打开浏览器访问下: http://192.168.31.20:9100
最后补充一下:
1、在elasticsearch集群的所有节点分为3种角色,分别是:master节点,数据节点,客户端节点。
2、在大型生产环境下,master节点和数据节点是分开的独立节点,所以在数据节点上,需要配置:node.data: false,在master节点需要配置:node.master: false。
3、客户端节点的意思是同时满足node.data: false和node.master: false。其目的是作为一个负载均衡器,可以帮助优化索引和搜索请求。在大型的集群里面,我们一般会配置这个客户端节点,然后所有的elasticsearch的客户端请求配置地址都是这种客户端节点,这样就不用数据节点去判断路由。减轻整个集群的压力。
还没有评论,来说两句吧...