ELK集群部署(史上超详细)

1.ELKStack官方网址

https://www.elastic.co/

2.ELKStack全版本下载地址:

https://elasticsearch.cn/download/

ELKStacks安装版本号需要一致
3.集群部署机器

服务器ip软件名称
linux1192.168.8.185elasticsearch+elasticsearch-head
linux2192.168.8.186elasticsearch
linux3192.168.8.187elasticsearch
linux4192.168.8.188logstash、kibana、filebeat

确认时区

date

如果时区是EST,要修改为CST(中国时区)

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

tips:这里时间一定与机器采集日志的时间一致
一、安装elasticsearch
1.下载

#下载elasticsearch rpm安装包
[root@node-1 ~]# 
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-x86_64.rpm

2.安装

# 对elasticsearch rpm包进行安装
[root@node-1 ~]# rpm -ivh elasticsearch-7.8.0-x86_64.rpm
# -i<套件档>或--install<套件档>  安装指定的套件档
# -v显示指令执行过程。
# -h或--hash  套件安装时列出标记

3.更新防火墙

[root@node-1 ~]# firewall-cmd --permanent --add-port=9200/tcp
[root@node-1 ~]# firewall-cmd --permanent --add-port=9200/udp
[root@node-1 ~]# firewall-cmd --reload

ELK报错问题解决

ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [es] 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] 和 [2] 的解决方法:修改 /etc/security/limits.conf 文件

[root@node-1 ~]# vim /etc/security/limits.conf #增加以下内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

[3] 的解决方法:修改 /etc/sysctl.conf 文件

[root@node-1 ~]# vim /etc/sysctl.conf
 vm.max_map_count=655360 #添加下面这一行
[root@node-1 ~]# sysctl -p  #执行命令

调整java内存大小

通过路径访问追踪错误,如果是“空间不足”
请修改
[root@node-1 ~]# sudo vim /etc/elasticsearch/jvm.options 配置文件

# 设置 JVM 初始内存为 1G。此值可以设置与-Xmx 相同,以避免每次垃圾回收完成后 JVM 重新分配内存

# Xms represents the initial size of total heap space
# 设置 JVM 最大可用内存为 512mb
# Xmx represents the maximum size of total heap space
-Xms 512mb
-Xmx 512mb

(1)安装elasticsearch-head插件
1.下载node安装包


#下载node安装包
[root@node-1 ~]# wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz 
# 创建elk文件
[root@node-1 ~]# mkdir /usr/share/elk 
# 解压node包
tar -xf node-v8.11.3-linux-x64.tar.xz -C /usr/share/elk/

2.更新防火墙

[root@node-1 ~]# firewall-cmd --permanent --add-port=9100/tcp

[root@node-1 ~]# firewall-cmd --permanent --add-port=9100/udp

[root@node-1 ~]# firewall-cmd --reload

3.配置node环境变量

[root@node-1 ~]#
# 编辑/etc/profile文件
vim /etc/profile  
# 配置NODE环境变量
export NODE_HOME=/usr/share/elk/node-v8.11.3-linux-x64  # 
export  PATH=$PATH:$NODE_HOME/bin 
# 使环境变量生效
[root@node-1 ~]# source /etc/profile 
# 查看node版本
[root@node-1 ~] #node -v

4.安装grunt

#安装grunt
[root@node-1 ~]# npm install grunt --save-dev

5.安装 grunt-cli

#安装 grunt-cli
[root@node-1 ~]# npm install -g grunt-cli

6.下载elasticsearch-head包

[root@node-1 ~]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip  
[root@node-1 ~]# unzip master.zip #解压
[root@node-1 ~]# cd elasticsearch-head-master#切换路径
[root@node-1 ~]# npm install  #安装

npm install遇到报错问题

npm ERR! phantomjs-prebuilt@2.1.16 install: node install.js

报什么错就执行如下命令

[root@node-1 ~]# npm install phantomjs-prebuilt@2.1.16 --ignore-scripts

7.修改elasticsearch-head插件配置文件
修改elasticsearch-head安装目录下的配置文件Gruntfile.js,一般97行左右增加hostname属性,设置为:“*”,注意冒号后面要空一格!

connect:{
  server:{
    options:{
      hostname: '*',  #注意冒号: 后面的空格
      port: 9100,
      base: ','
      keepalive: true

    }
  }
}

8.更新防火墙


firewall-cmd --permanent --add-port=9100/tcp

firewall-cmd --permanent --add-port=9100/udp

firewall-cmd --reload

(2)Elasticsearch配置文件
在/etc/elasticsearch/elasticsearch.yml分别修改节点名称,上传到另外两台(node-2、node-3)主机

[root@node-2 ~]# /etc/elasticsearch/elasticsearch.yml
vim node.name: node-2
cluster.initial_master_nodes: ["node-2"]
discovery.seed_hosts: ["192.168.8.186:9300"]

[root@node-3 ~]# /etc/elasticsearch/elasticsearch.yml
vim node.name: node-3
cluster.initial_master_nodes: ["node-3"]
discovery.seed_hosts: ["192.168.8.186:9300"]

elasticsearch.yml配置文件如下

[root@node-1 ~]# vim /etc/elasticsearch/elasticsearch.yml

# 加入如下配置
#集群名称
cluster.name: cluster-es
#节点名称,每个节点的名称不能重复
node.name: node-1
#ip 地址,每个节点的地址不能重复
network.host: 0.0.0.0
network.bind_host: 0.0.0.0
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9200
path.data: /var/lib/elasticsearch
path.logs: /var/lib/elasticsearch
#head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
#内部节点之间沟通端口
transport.tcp.port: 9300
#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.8.185:9300","192.168.8.186:9300","192.168.8.187:9300"]
gateway.recover_after_nodes: 3
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
node.max_local_storage_nodes: 3
#集群内同时启动的数据任务个数,默认是 2 个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
#添加或删除节点及负载均衡时并发恢复的线程个数,默认 4 个

修改配置文件完成后记得重启elasticsearch

二、安装kibana

1.安装

# 安装logstash
[root@node-1 ~]# 
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.8.0-x86_64.rpm
#安装
[root@node-1 ~]# rpm -ivh kibana-7.8.0-x86_64.rpm
# 启动
[root@node-1 ~]# systemctl enable kibana  ##设置开机自启动
[root@node-1 ~]# systemctl start  kibana  ##启动kibana

2.配置

  1. kibana配置文件在/etc/kibana/kibana.yml文件进行配置这三行文件
[root@localhost ~]# vim /etc/kibana/kibana.yml 
server.port:5601 
server.host:"0.0.0.0"  
elasticsearch.host:["192.168.8.188:9200"]

2.修改配置文件完成后记得重启

[root@localhost ~]# systemctl restart kibana

3.更新防火墙

[root@localhost ~]# firewall-cmd --permanent --add-port=5601/tcp

[root@localhost ~]# firewall-cmd --permanent --add-port=5601/udp

[root@localhost ~]# firewall-cmd --reload

三、安装logstash
1.安装

#下载
[root@localhost ~]# wget https://artifacts.elastic.co/downloads/logstash/logstash-7.8.0.rpm
#安装
[root@localhost ~]# rpm -ivh logstash-7.8.0.rpm
# 启动
[root@localhost ~]# systemctl enable logstash  #设置开机自启动

[root@localhost ~]# systemctl start  logstash  #启动logstas

四、安装filebeat
1.安装

# 下载
[root@localhost ~]# 
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.8.0-x86_64.rpm
#安装
[root@localhost ~]# 
rpm -ivh filebeat-7.8.0-x86_64.rpm
# 启动
[root@localhost ~]#
systemctl enable filebeat  ##设置开机自启动
[root@localhost ~]#
systemctl start  filebeat  ##启动logstash

2.更新防火墙

[root@localhost ~]#firewall-cmd --permanent --add-port=5044/tcp

[root@localhost ~]#firewall-cmd --permanent --add-port=5044/udp

[root@localhost ~]#firewall-cmd --reload

到这里ELKStack集群就部署完成了。

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值