目录
3.1.1 单机&集群
单台Elasticsearch服务器提供服务,往往都有最大的负载能力,超过这个阈值,服务器性能就会大大的降低,甚至不可用,所以生产环境中,一般都是运行在指定服务器集群中。
除了负载能力,单点服务器也存在其他问题:
1.单台机器存储容量有限
2.单服务器容易出现故障,无法实现高可用
3.单服务的并发处理能力有限
配置服务器集群时,集群中节点数量没有限制,大于等于两个节点就可以看做一个集群了,一般出于高性能及高可用方面来考虑及集群中节点数量都是2个以上
3.1.2 集群Cluster
一个集群就是由一个或多个服务器节点组织在一起,共同持有整个的数据,并一起提供索引和搜索功能,一个Elasticsearch集群有一个唯一的名字标识,这个名字默认就是elasticsearch,这个名字是非常重要的,因为一个节点只能ton过指定某个集群的名字,来加入这个集群
3.1.3 节点Node
集群中包含很多服务器,一个节点就是其中的一个服务器。作为集群的一部分,它存储数据,参与集群的索引和搜索功能。
一个节点也是由一个名字来标识的,默认情况下,这个名字是一个随机的漫威漫画角色的名字,这个名字会在启动的时候赋予节点。这个名字对于管理工作来说至关重要,因为在这个管理过程中,你会去确定网络中的哪些服务器对应于Elasticsearch集群中的哪些节点。
一个节点可以通过配置集群名称的方式来加入一个指定的集群,默认情况下,每个节点都会被安排加入到一个叫elasticsearch的集群中,这就意味着,如果你在你的网络中启动了若干个节点,并假定他们能够互相发现彼此,它们将会自动地形成并加入到一个叫做elasticsearch的集群中
3.2 Windos集群
3.2.1 部署集群
(1)创建elasticsearch-cluster文件夹,在内部复制三个elasticsearch服务,删除每个文件夹中的data文件夹,进入logs文件夹,删除所有文件.
(2)修改集群文件目录中每一个节点的config/elasticsearch.yml文件配置
node-1001节点
#集群名称
cluster.name: my-application
#节点名称
node.name: node-1001
node.master: true
node.data: true
#主机名称
network.host: localhost
http.port: 1001
transport.tcp.port: 9301
#跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"
配置完成后去bin目录启动es,使用postman工具发送如下请求
http://localhost:1001/_cluster/health 查看集群状态
node-1002节点
#集群名称
cluster.name: my-application
#节点名称
node.name: node-1002
node.master: true
node.data: true
#主机名称
network.host: localhost
http.port: 1002
transport.tcp.port: 9302
#查找es节点的模块(第一个1001节点和第二个1002节点如何通信呢,就是如下三个配置)
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"
配置完成后启动1002节点,查看集群的健康状态
node-1003节点
#集群名称
cluster.name: my-application
#节点名称
node.name: node-1003
node.master: true
node.data: true
#主机名称
network.host: localhost
http.port: 1003
transport.tcp.port: 9303
#查找es节点的模块(寻找第一个节点和第二个节点)
discovery.seed_hosts: ["localhost:9301","localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
http.cors.enabled: true
http.cors.allow-origin: "*"
配置完成后启动 1003节点,查看集群健康状态,最终结果为
至此,ES集群部署成功。
3.3 Linux 单机
3.3.1 软件下载
软件下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-3-2
3.3.2 软件安装
将下载好的linux版本es上传,我这里上传到了/home/es/
先关闭防火墙!!!重要的事情说三遍
systemctl stop firewalld #暂时性关闭防火墙(我用的这个)
systemctl disable firewalld #永久性关闭防火墙
(1)解压软件
#进入/home
cd /home
#解压软件
tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz -C ./
#软件解压到了home文件夹下。
#改名
mv elasticsearch-7.3.2 es
(2)创建用户
因为安全问题,Elasticsearch不允许root用户直接运行,所以要创建个新用户,在root中用户中创建新用户
useradd es #新增es用户 第一步
passwd es #为es用户设置密码 第二步
userdel -r es #如果错了,可以删除再加
chown -R es:es /home/es #文件夹持有者 第三步
(3)修改配置文件
修改/home/es/config/elasticsearch.yml
#加入如下配置
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
在最后面加上就行
修改 /etc/security/limits.conf 命令: vim /etc/security/limits.conf
#在文件末尾家增加下面内容
#每个进程可以打开的文件数限制
es soft nofile 65536
es hard nofile 65536
修改 /etc/security/limits.d/20-nproc.conf 命令:vim /etc/security/limits.d/20-nproc.conf
#在文件末尾添加如下配置
es soft nofile 65536
es hard nofile 65536
* hard nproc 4096 #操作系统级别对每个用户创建的进程数限制
#注意: * 代表Linux所有用户名称
修改/etc/sysctl.conf 命令:vim /etc/sysctl.conf
#在文件中增加下面内容
#一个进程可以拥有VMA(虚拟内存区域)的数量,默认值是65536
vm.max_map_count=655360
#重新加载
sysctl -p
3.3.3 启动软件
使用ES用户启动
cd /home/es
#启动
bin/elasticsearch
#后台启动
bin/elasticsearch -d
报错,不能用用户root启动es.切换一下
su es 切换es用户
bin/elasticsearch
这个报错是由于es在启动过程中动态生成一些启动目录,里面的内容跟es的权限没有关系
#再次设定一下用户
chown -R es:es /home/es
#这块有点麻烦,还要再次切换为root
su root
#centos7这块可能会报鉴定故障(有可能是密码错误,我一直以为是我设置的那个es的密码,我的es密码是es,结果不是,是内个root的密码,我的密码是root)
切换回root用户后,再次输入
chown -R es:es /home/es #更改完成后,再切回去.这块繁琐
su es
bin/elasticsearch
启动完成
最后使用postman访问
3.3.2 Linux集群部署
(1)先关闭防火墙(上面有命令)
(2)创建用户(如上-单机部署)
(3)修改配置文件
在config下修改elasticsearch.yml文件
部署192.168.18.129
#集群名称 cluster.name: cluster-es #节点名称,每个节点名称不能重复 node.name: node-1 #ip地址,每个节点的地址不能重复 network.host: 192.168.18.129 node.master: true node.data: true http.port: 9200 #head插件都会打开这两个配置 http.cors.allow-origin: "*" http.cors.enabled: true http.max_content_length: 200mb #es7.x之后新增的配置,用来选举一个新的master cluster.initial_master_nodes: ["node-1"] #es7.x之后新增的配置,节点发现 discovery.seed_hosts: ["192.168.18.129:9300","192.168.18.130:9300"] gateway.recover_after_nodes: 2 network.tcp.keep_alive: true network.tcp.no_delay: true transport.tcp.compress: true #集群内同时启动任务个数,默认是两个 cluster.routing.allocation.cluster_concurrent_rebalance: 16 #添加或删除节点及负载均衡时并恢复的线程个数,默认4个 cluster.routing.allocation.node_concurrent_recoveries: 16 #初始化数据恢复时,并发恢复线程的个数,默认4个 cluster.routing.allocation.node_initial_primaries_recoveries: 16
#修改 /etc/security/limits.conf #在文件末尾家增加下面内容 #每个进程可以打开的文件数限制 es soft nofile 65536 es hard nofile 65536 ------------------------------------------------------------------------------------------- #修改 /etc/security/limits.d/20-nproc.conf #在文件末尾添加如下配置 es soft nofile 65536 es hard nofile 65536 * hard nproc 4096 #操作系统级别对每个用户创建的进程数限制 #注意: * 代表Linux所有用户名称 ------------------------------------------------------------------------------------------- #修改 /etc/security/limits.d/20-nproc.conf #在文件末尾添加如下配置 es soft nofile 65536 es hard nofile 65536 * hard nproc 4096 #操作系统级别对每个用户创建的进程数限制 #注意: * 代表Linux所有用户名称 ------------------------------------------------------------------------------------------- # 修改/etc/sysctl.conf #在文件中增加下面内容 #一个进程可以拥有VMA(虚拟内存区域)的数量,默认值是65536 vm.max_map_count=655360 #重新加载 sysctl -p -----------------------------------------------------------------------------------------#最后切换 su es chown -R es:es /home/es #启动 这块除了elasticsearch.yml有点改动,其他的和单机部署一样
部署192.168.18.130
#除了elasticsearch.yml不一样,其他操作步骤都一样。记住关掉防火墙!!! #集群名称 cluster.name: cluster-es #节点名称,每个节点名称不能重复 node.name: node-2 #ip地址,每个节点的地址不能重复 network.host: 192.168.18.130 node.master: true node.data: true http.port: 9200 #head插件都会打开这两个配置 http.cors.allow-origin: "*" http.cors.enabled: true http.max_content_length: 200mb #es7.x之后新增的配置,用来选举一个新的master cluster.initial_master_nodes: ["node-1"] #es7.x之后新增的配置,节点发现 discovery.seed_hosts: ["192.168.18.129:9300","192.168.18.130:9300"] gateway.recover_after_nodes: 2 network.tcp.keep_alive: true network.tcp.no_delay: true transport.tcp.compress: true #集群内同时启动任务个数,默认是两个 cluster.routing.allocation.cluster_concurrent_rebalance: 16 #添加或删除节点及负载均衡时并恢复的线程个数,默认4个 cluster.routing.allocation.node_concurrent_recoveries: 16 #初始化数据恢复时,并发恢复线程的个数,默认4个 cluster.routing.allocation.node_initial_primaries_recoveries: 16
我的129和130的es文件夹名都叫es-cluster
最后用postman测试一下
http://192.168.18.129:9200/_cat/nodes
我就部署了两个,第三个没写。第三个也是同样,大家别着急,一步一步慢慢部署就行!加油!
如果哪块有问题留言