工作流程:
通过Filebeat读取日志文件中的内容,并且将内容发送给Logstash,原因是需要对内容做处理
Logstash接收到内容后,进行处理,如分割操作,然后将内容发送到Elasticsearch中
Kibana会读取Elasticsearch中的数据,并且在Kibana中进行设计Dashboard,最后进行展示
ELK6.3.2版本安装
一.es安装
1.下载安装包并解压(6.3.2版本)
下载地址:https://www.elastic.co/cn/downloads/
注意:es,filebeat,kibana等安装包均上传到opt目录下
cd /opt/
tar -zxvf elasticsearch-6.3.2.tar.gz
mv elasticsearch-6.3.2/ elsearch
2.es在root用户下运行会报错,所以需要创建新用户
useradd elsearch
chown elsearch:elsearch /opt/ -R
3.修改相应配置文件
vim /etc/security/limits.conf
##底部添加(重启让配置生效)
* soft nproc 5000
* hard nproc 5000
root soft nproc 5000
root hard nproc 5000
vim /opt/elsearch/config/elasticsearch.yml
##底部添加
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,Content-Type
vim /opt/elsearch/conf/jvm.options
-Xms128m
-Xmx128m
vim /etc/sysctl.conf
vm.max_map_count=655360
# 让配置生效
sysctl -p
4.启动并访问web端
su - elsearch
cd /opt/elsearch/bin
./elasticsearch
5.浏览器查看
6.es 可视化界面安装
#拉取镜像(执行之前先安装docker)
docker pull mobz/elasticsearch-head:5
#创建容器
docker create --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5
#启动容器
docker start elasticsearch-head
7.访问9100端口
二.Filebeat安装
1.官网下载压缩包(版本和es一致)
https://www.elastic.co/cn/downloads/beats/filebeat
mkdir -p /opt/beats
tar -xvf filebeat-6.3.2-linux-x86_64.tar
mv filebeat-6.3.2-linux-x86_64/ filebeat
# 进入文件夹
cd filebeats
2.创建配置文件并添加如下内容
vim mogublog.yml
filebeat.inputs: # filebeat input输入
- type: stdin # 标准输入
enabled: true # 启用标准输入
setup.template.settings:
index.number_of_shards: 3 # 指定下载数
output.console: # 控制台输出
pretty: true # 启用美化功能
enable: true
3.启动
./filebeat -e -c mogublog.yml
4.测试
创建日志文件
vim mogublog-log.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /opt/beats/logs/*.log
setup.template.settings:
index.number_of_shards: 3
output.console:
pretty: true
enable: true
mkdir -p /opt/beats/logs
cd /opt/beats/logs
echo "hello" >> a.log
##再次启动filebeat
./filebeat -e -c mogublog-log.yml
5.能够发现,它已经成功加载到了我们的日志文件 a.log
6.使用filebeat连接es
修改配置文件
vim mogublog-log.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /opt/beats/logs/*.log
tags: ["web", "test"]
fields:
from: test-web
fields_under_root: false
setup.template.settings:
index.number_of_shards: 1
output.elasticsearch:
hosts: ["127.0.0.1:9200"]
7.再次启动之后发现可以连接成功
8.web界面查看
三.Kibana安装
1.下载对应的版本(6.3.2)
https://www.elastic.co/cn/downloads/kibana
2.解压并重命名
tar -xvf kibana-6.3.2-linux-x86_64.tar
mv kibana-6.3.2-linux-x86_64 kibana
3.修改配置文件
vim /opt/kibana/config/kibana.yml
#对外暴露服务的地址
server.host: "0.0.0.0"
#配置Elasticsearch,在20行附近
elasticsearch.url: "http://127.0.0.1:9200"
4.切换用户并启动
su elsearch
cd /opt/kibana/
./bin/kibana
5.访问浏览器(注意端口号为5601)