文章目录
一、配置前的准备工作
从官网下载Linux版Elasticsearch
官网:https://www.elastic.co/cn/downloads/past-releases#elasticsearch
解压:
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz
拷贝三份 elasticsearch-7.8.0用于集成
为了方便,此步骤也可以在配置完成一份之后再进行拷贝
cp -r elasticsearch-7.8.0 elasticsearch-7.8.0B
创建运行Elasticsearch的用户
因为安全问题,Elasticsearch 不允许 root 用户直接运行,所以要创建新用户,在 root 用户中创建新用户。
#新增用于运行Elasticsearch的用户
useradd es
#为es用户设置密码
passwd es
#给es用户赋予权限(后面的路径为Elasticsearch的存放路径)
chown -R es:es /soft/es/
#若添加用户错误,可以删除重新添加
userdel -r es
二、修改配置文件
修改其中一份的配置文件作为演示,不同文件只需要注意,节点名称和端口号不同即可。
修改/soft/es/elasticsearch-7.8.0/config/elasticsearch.yml 文件
vim elasticsearch-7.8.0/config/elasticsearch.yml
#集群名称
cluster.name: my-application
#节点名称,每个节点的名称不能重复
node.name: node-1
#ip 地址,每个节点的地址不能重复(0.0.0.0即代表所有的都可用,所以每个配置文件都写成0.0.0.0即可)
network.host: 0.0.0.0
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9201 #端口在每个配置文件都需要不一样(我写的是9201,9202,9203)
# 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: ["localhost:9300","localhost:9400","localhost:9500"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
#集群内同时启动的数据任务个数,默认是 2 个
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
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
vm.max_map_count=655360
重新加载
sysctl -p
三、测试
配置文件修改成功,开始测试
cd /soft/es/elasticsearch-7.8.0
# 启动
bin/elasticsearch
#后台启动
bin/elasticsearch -d
三个要同时启动,然后进行测试
在浏览器访问http://xx:xx:xx:xx:9201/_cat/nodes
此处为虚拟机或者云服务器的ip地址
四、部署时遇到的问题
1.There is insufficient memory for the Java Runtime Environment to continue.
问题原因:JVM所需的内存空间不足
解决方法:修改es/elasticsearch-7.8.0/config/jvm.options中所需的最大内存
vim es/elasticsearch-7.8.0/config/jvm.options
将这里原有的-Xms4g调小为-Xms256m即可
2.当三个elasticsearch同时启动后无法集成
问题原因:三个elasticsearch中的某一个之前提前启动过,所以生成了其他elasticsearch没有的data和logs,造成的无法同步
解决方法:为了以防万一可以把三个elasticsearch的data和logs都同时删除掉,再重新同时启动,进行测试即可
#删除某个文件
rm -rf xxx 文件名
#删除文件夹中的所有文件
rm *