ELK日志分析学习记录

ELK日志分析学习记录

在这里插入图片描述

1. 下载安装包

官网下载地址:https://www.elastic.co/cn/downloads/

但是下载速度很慢,可以寻找国内镜像通过wget命令下载:

https://elasticsearch.thans.cn/downloads/elasticsearch/elasticsearch-7.3.2-no-jdk-linux-x86_64.tar.gz

https://mirrors.huaweicloud.com/logstash/7.3.2/logstash-7.3.2.tar.gz

https://mirrors.huaweicloud.com/kibana/7.3.2/kibana-7.3.2-linux-x86_64.tar.gz

2. elasticsearch安装和使用

elasticsearch的安装需要oracle jdk1.8的支持,由于centOS自带的是openJDK,所以需要重装jdk。

解压安装包

tar -zxvf elasticsearch-7.3.2-no-jdk-linux-x86_64.tar.gz

进行配置

cd elasticsearch-7.3.2/config
vim elasticsearch.yml

加入如下配置

# 将绑定地址设置为特定的IP
network.host: 0.0.0.0
# 设置访问端口
http.port: 9200
# 跨域设置
http.cors.enabled: true
http.cors.allow-origin: "*"

由于root用户无法直接启动elasticsearch,所以需要新建用户去启动elasticsearch

#创建用户组和用户
groupadd elk
useradd elk -g elk -p xxxx
#切换用户
su elk
#临时启动
./bin/elasticsearch 
#后台启动
./bin/elasticsearch -d

浏览器访问 : 服务器ip+9200:

在这里插入图片描述

配置成功!

可能出现的问题:

  1. max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
#切换到root用户  修改/etc/security/limits.conf,在文件后添加如下配置

*  hard  nofile  65536
*  soft   nofile  65536
  1. max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
#提示虚拟内存太小,最大文件描述进程太小
#切换root用户 修改/etc/sysctl.conf 添加如下配置
vm.max_map_count=2621441
#保存后执行sudo sysctl -p /etc/sysctl.conf 使之生效
  1. JVM is using the client VM [Java HotSpot™ Client VM] but should be using a server VM for the best performance
#jvm HotSpot client VM 与 server VM
#修改文件 
#JAVA_HOME\jre\lib\i386\jvm.cfg
-server KNOWN      //原来在第二行
-client IF_SERVER_CLASS -server
-minimal KNOWN
  1. system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
#Centos不支持SecComp
#修改文件elasticsearch.yml

bootstrap.memory_lock: false 
bootstrap.system_call_filter: false
  1. the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts,discovery.seed_providers, cluster.initial_master_nodes] must be configured
#修改config目录下的 elasticsearch.yml文件
cluster.initial_master_nodes: ["node-1"]

2. logstash的安装使用

解压安装包

tar -zxvf logstash-7.3.2.tar.gz

进入文件目录

cd logstash-7.3.2.tar.gz

测试

 ./bin/logstash -e 'input { stdin { } } output { stdout { } }'

启动后直接命令行输入,可获得同样的输出

在这里插入图片描述

日志读取配置

新建一个conf文件名字随意,编辑以下内容:

input {

    file {

        path => "/usr/tomcat/apache-tomcat-9.0.31/logs/localhost_access_loh*.log"

        type => "systemlog"

        start_position => "beginning"

        stat_interval => "3"

    }

}


output {

    if [type] == "systemlog" { 

        elasticsearch {

            hosts => ["服务器ip:9200"]

            index => "system-log-%{+YYYY.MM.dd}"

        }

    }

    if [type] == "securelog" { 

        elasticsearch {

            hosts => ["服务器ip:9200"]

            index => "secure-log-%{+YYYY.MM.dd}"

        }

    }

}

这里配置的是读取tomcat日志,修改tomcat/conf/server.xml里的pattern参数

 pattern="%h %l %u %t "%r" %s %b" 

启动logstash

./bin/logstash -f logstash.conf

可能会遇到的问题:

  1. 找不到logstash-input-log4j插件

安装:

 ./logstash-plugin install logstash-input-log4j
  1. 内存不足

修改conf/jvm.options 参数到合适的值

vim conf/jvm.options 
-Xms200m
-Xms200m

3. kibana的安装和使用

解压:

tar -zxvf kibana-7.3.2-linux-x86_64.tar.gz

修改配置

vim kibana-7.3.2-linux-x86_64/config/kibana.yml
server.port: "5601"
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://服务器ip:9200"]
#kibana中文设置
i18n.locale: "zh-CN"

启动kibana

./bin/kibana

在这里插入图片描述

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值