ES 集群搭建

2,637 阅读2分钟

[TOC]

一、简介

二、集群节点规划

节点名称 节点IP 部署内容
ES01 10.18.33.204 ES/kibana/logStash
ES02 10.18.33.158 ES
ES03 10.18.33.159 ES

2.1 部署版本说明

ES 版本:7.1.0 Kibana: 7.1.0 Logstash: 7.1.0

部署流程

1.上传并解压包

tar -zxvf elasticsearch-7.1.0-linux-x86_64.tar.gz

2. 创建ES用户和密码

useradd esuser
passwd  esuser

3. 授权文件夹所属组和权限

chown -R esuser:esuser  elasticsearch-7.1.0/
chowd -R +x elasticsearch-7.1.0/bin

4.修改ES配置文件

cd  elasticsearch-7.1.0/config
vim elasticsearch.yml

编辑内容如下:

cluster.name: fjzl-application
node.name: node-3   # 每个节点名称都唯一,不可重复
network.host: 10.18.33.159  # 根据每个节点更改IP
http.port: 9200
discovery.seed_hosts: ["10.18.33.204", "10.18.33.158","10.18.33.159"]
cluster.initial_master_nodes: ["node-1", "node-2"]

同样的方式编辑节点2,节点3 完成用户的创建和配置文件的更改

5.启动ES集群

使用ES用户依次启动ES01,ES02 、ES03节点

[root@localhost bin]# pwd
/home/apps/es/elasticsearch-7.1.0/bin
[esuser@localhost bin]$ ./elasticsearch -d      # 以后台方式启动

三、 Kibana安装和使用

1. 解压文件

tar -zxvf logstash-7.1.0.tar.gz

2.配置yml 文件

修改 配置config目录下的kibana.yml 文件,配置elasticsearch地址和kibana地址信息

server.host: "10.18.33.204"  # kibana 服务器地址
elasticsearch.url: "http://10.18.33.204:9200"    # ES 地址

3.启动命令

./kibana &  或 nohup ./kibana &

四、LogStash 安装

下载logStash

https://artifacts.elastic.co/downloads/logstash/logstash-7.0.1.tar.gz

下载完成解压后,config目录下配置日志收集日志配置文件 logstash.conf

# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input {
  tcp {
    mode => "server"
    host => "192.168.92.50"
    port => 4560
    codec => json_lines
  }
}
output {
  elasticsearch {
    hosts => "192.168.92.50:9200"
    index => "springboot-logstash-%{+YYYY.MM.dd}"
  }
}

配置成功后启动logstatsh

[root@localhost bin]# ./logstash -f ../config/logstash.conf 

五、常见问题

出现问题1:

max file descriptors [4096] for elasticsearch process is too low, increase t

每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量

ulimit -Hn
ulimit -Sn

修改/etc/security/limits.conf文件,增加配置,用户退出后重新登录生效

esuser               soft    nofile          65536
esuser              hard    nofile          65536

将esuer替换为你启动es的用户

出现问题2:

max number of threads [3818] for user [es] is too low, increase to at least [4096]

问题同上,最大线程个数太低。修改配置文件/etc/security/limits.conf,增加配置

esuser              soft    nproc           4096
esuer               hard    nproc           4096

出现问题3:

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

修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144

vi /etc/sysctl.conf
sysctl -p

问题4:

Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch/elasticsearch-6.2.2-1/config/jvm.options

 elasticsearch用户没有该文件夹的权限,执行命令  

chown -R es:es /usr/local/elasticsearch/