ElasticSearch6.1.1集群搭建

时间:2023-03-09 05:01:33
ElasticSearch6.1.1集群搭建

其实早就想研究ES了,因为之前用solr,资料较少(这倒不是问题,有问题去官网读文档),貌似用的人比较少?(别打我)前几天去京东面试,我觉得有必要了解一下es,昨天晚上简单了解了官方文档,今天居然鼓捣了一上午,等工作了我一定换一个1个T内存的机器(手动滑稽)

正题

先去官网下载压缩包,自行解决。我的虚拟机【CentOS7:192.168.127.129、130、131】

环境要求,最少Java8,推荐131以后的

ElasticSearch6.1.1集群搭建

解压到/usr/local

tar -zxvf elasticsearch-6.1..tar.gz -C /usr/local

进入主目录

cd /usr/local/elasticsearch-6.1./

创建两个文件夹data和logs,分别存放索引和日志

[root@localhost elasticsearch-6.1.]# mkdir data logs

存放索引的目录:/usr/local/elasticsearch-6.1.1/data

存放日志的目录:/usr/local/elasticsearch-6.1.1/logs

进入config目录

[root@localhost logs]# cd ../config/
[root@localhost config]# ll
total
-rw-rw----. root root Dec : elasticsearch.yml
-rw-rw----. root root Dec : jvm.options
-rw-rw----. root root Dec : log4j2.properties

修改elasticsearch.yml文件

[root@localhost config]# vim elasticsearch.yml

ElasticSearch6.1.1集群搭建

修改jvm

[root@localhost config]# vim jvm.options

ElasticSearch6.1.1集群搭建

这里大家自定义的大小,我每个虚拟机分配1g内存,给jvm一半,资源比较稀缺,你们可以根据自身条件调整。

启动ES

[root@localhost elasticsearch-6.1.]# ./bin/elasticsearch

ElasticSearch6.1.1集群搭建

ElasticSearch6.1.1集群搭建

更改elasticsearch为普通用户权限,然后切换普通用户启动

[root@localhost elasticsearch-6.1.]# chown -R admin /usr/local/elasticsearch-6.1./
[root@localhost elasticsearch-6.1.]# su admin
[admin@localhost elasticsearch-6.1.]$ ./bin/elasticsearch

当你认为ok的时候,其实并不ok

报错:

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: max number of threads [3798] for user [admin] is too low, increase to at least [4096]

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

官方文档解释:

[1]

ElasticSearch6.1.1集群搭建

[2]

ElasticSearch6.1.1集群搭建

[3]

ElasticSearch6.1.1集群搭建

ElasticSearch6.1.1集群搭建

查看系统虚拟内存:sysctl -a | grep "vm.max_map_count"

除了上面的注意,生产环境要Disable swapping,不过这个对我们当前影响不大

ElasticSearch6.1.1集群搭建

ElasticSearch6.1.1集群搭建

设置虚拟内存

[root@localhost elasticsearch-6.1.]# sysctl -w vm.max_map_count=
vm.max_map_count = [root@localhost elasticsearch-6.1.]# vim /etc/security/limits.conf

修改limits.conf文件,添加如下内容:

ElasticSearch6.1.1集群搭建

<用户名><类型><属性><值>
admin soft nofile
admin hard nofile admin soft nproc
admin hard nproc

打开防火墙:9200是http访问端口,9300是集群通信端口

打开防火墙端口:
firewall-cmd --zone=public --add-port=/tcp --permanent
firewall-cmd --zone=public --add-port=/tcp --permanent
重启防火墙:systemctl restart firewalld

切换普通用户,启动集群,可能很慢,一个一个启动,反正我的是卡死了。

启动集群:
[admin@localhost elasticsearch-6.1.]$ ./bin/elasticsearch

三个都启动成功,简单来看根据是否抛异常

查看集群状态:执行linux命令~
curl -XGET '192.168.127.129:9200/_cat/health?v&pretty'
curl -XGET '192.168.127.129:9200/_cat/nodes?v&pretty'
或者通过浏览器访问:
http://192.168.127.129:9200/
http://192.168.127.129:9200/_cat/nodes?v&pretty
http://192.168.127.129:9200/_cat/health?v&pretty

ElasticSearch6.1.1集群搭建

ElasticSearch6.1.1集群搭建

ElasticSearch6.1.1集群搭建