ElasticSearch7.3.2-集群搭建指南

1、环境准备

我们选择基于7.3.2版本安装部署,基于cluster部署,假设我们有三台虚拟机node1-192.168.1.1node2-192.168.1.2node3-192.168.1.3

1.1、下载解压

基于root用户下

su root
mkdir /opt/elastic
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz
tar zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
mv elasticsearch-7.3.2 elastic

1.2、创建elastic用户,并授权目录权限

基于root用户下,创建用户组elastic,并添加用户elastic及及设置密码elastic。

groupadd elastic
useradd elastic -g elastic
passwd elastic
chown -R elastic:elastic  /opt/elastic
chown -R elastic:elastic  /var/elastic

2、参数配置

2.1、elasticsearch.yml配置

vim /opt/elastic/config/elasticsearch.yml

更多配置:https://www.elastic.co/guide/en/elasticsearch/reference/7.x/important-settings.html

进入其中一台虚拟机(192.168.1.1),参考配置如下:

cluster.name: my-elasticsearch                                                                                                                         
node.name: node1                                                                                                                                        
path.data: [/var/elastic/data]                                                                                                                          
path.logs: [/var/elastic/logs]                                                                                                                          
bootstrap.system_call_filter: false                                                                                                                     
bootstrap.memory_lock: false                                                                                                                            
network.host: 192.168.1.1                                                                                                                             
http.host: 192.168.1.1                                                                                                                                
transport.bind_host: 192.168.1.1                                                                                                                      
discovery.zen.ping.unicast.hosts: ["192.168.1.1:9300","192.168.1.2:9300","192.168.1.3:9300"]                                                     
discovery.zen.minimum_master_nodes: 2                                                                                                                   
cluster.initial_master_nodes: ["node1","node2","node3"]                                                                                                 
node.master: true                                                                                                                                       
node.data: true                                                                                                                                         
http.cors.enabled : true                                                                                                                                
http.cors.allow-origin : "*"                                                                                                                            
http.max_initial_line_length: 12kb                                                                                                                      
http.cors.allow-credentials: true                                                                                                                       
http.cors.allow-headers: WWW-Authenticate,X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization   

然后拷贝到其他虚拟机(192.168.1.2、192.168.1.3)

scp -P 22 ./elastic root@192.168.1.2:/opt/elastic
scp -P 22 ./elastic root@192.168.1.3:/opt/elastic

修改虚拟机(192.168.1.2)elasticsearch.yml配置如下

cluster.name: my-elasticsearch                                                                                                                         
node.name: node2                                                                                                                                        
path.data: [/var/elastic/data]                                                                                                                          
path.logs: [/var/elastic/logs]                                                                                                                          
bootstrap.system_call_filter: false                                                                                                                     
bootstrap.memory_lock: false                                                                                                                            
network.host: 192.168.1.2                                                                                                                            
http.host: 192.168.1.2                                                                                                                               
transport.bind_host: 192.168.1.2                                                                                                                      
discovery.zen.ping.unicast.hosts: ["192.168.1.1:9300","192.168.1.2:9300","192.168.1.3:9300"]                                                     
discovery.zen.minimum_master_nodes: 2                                                                                                                   
cluster.initial_master_nodes: ["node1","node2","node3"]                                                                                                 
node.master: true                                                                                                                                       
node.data: true                                                                                                                                         
http.cors.enabled : true                                                                                                                                
http.cors.allow-origin : "*"                                                                                                                            
http.max_initial_line_length: 12kb                                                                                                                      
http.cors.allow-credentials: true                                                                                                                       
http.cors.allow-headers: WWW-Authenticate,X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization  

修改虚拟机(192.168.1.3)elasticsearch.yml配置如下

cluster.name: my-elasticsearch                                                                                                                         
node.name: node3                                                                                                                                        
path.data: [/var/elastic/data]                                                                                                                          
path.logs: [/var/elastic/logs]                                                                                                                          
bootstrap.system_call_filter: false                                                                                                                     
bootstrap.memory_lock: false                                                                                                                            
network.host: 192.168.1.3                                                                                                                             
http.host: 192.168.1.3                                                                                                                                
transport.bind_host: 192.168.1.3                                                                                                                      
discovery.zen.ping.unicast.hosts: ["192.168.1.1:9300","192.168.1.2:9300","192.168.1.3:9300"]                                                     
discovery.zen.minimum_master_nodes: 2                                                                                                                   
cluster.initial_master_nodes: ["node1","node2","node3"]                                                                                                 
node.master: true                                                                                                                                       
node.data: true                                                                                                                                         
http.cors.enabled : true                                                                                                                                
http.cors.allow-origin : "*"                                                                                                                            
http.max_initial_line_length: 12kb                                                                                                                      
http.cors.allow-credentials: true                                                                                                                       
http.cors.allow-headers: WWW-Authenticate,X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization  

3、JVM配置

由于ElasticSearch自带虚拟机,需要设置堆大小,只需要

vim /opt/elastic/config/jvm.options

修改如下配置

-Xms4g                                                                                                                                                  
-Xmx4g    

4、启动

基于elastic用户,依次启动三个节点

su elastic
nohup /opt/elastic/bin/elasticsearch > /var/elastic/es.log >&1 &   

可以查看启动日志

tail -200f /var/elastic/es.log 

5、Kibana安装

kibana相当于mysql的navicat,就是个客户端,我们安装到其中一台虚拟机即可。

5.1、下载解压

下载到
tar zxvf kibana-7.3.2-linux-x86_64.tar.gz
mv kibana-7.3.2 kibana

5.2、参数配置

vim /opt/kibana/config/kibana.yml

配置如下:

server.port: 5601                                                                                                                                       
server.host: 192.168.1.1                                                                                                                     
elasticsearch.hosts: ["http://192.168.1.1:9200"]                                                                                                      
elasticsearch.username: "elastic"                                                                                                                       
elasticsearch.password: "elastic"   

5.3、启动

nohup /opt/kibana/bin/kibana &

6、遇到问题

vm.max_map_count

ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;

解决:
切换到root用户
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144

上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
/etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144

下面的是我的公众号二维码图片,欢迎关注。
秋夜无霜

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值