ELK日志系统

ELK日志系统

ELK:是一套完整的日志集中处理方案。
E:elasticsearch ES 分布式索引型非关系数据库 存储logstash 输出的日志,全文检索引擎。保存的格式json格式
L:logstash 基于Java开发的,数据收集引擎,日志的收集,可以对数据进行过滤,分析,汇总,以标准格式输出
K:Kiabana 是ES的可视化工具。对es存储的数据进行可视化展示,分析,检索

ELK架构
在这里插入图片描述

ELK F K
F:
filebeat:轻量级的开源日志文件数据搜集器。logstash占用资源比较大,属于重量级。
有了flebeat可以节省资源,可以通过filebeat和logstash实现远程数据收集。
filereat不能对数据进行标准输出,不能输出为ES格式的数据,所以需要logstasg把filebeat数据做标准化处理。

在这里插入图片描述

K:
kafka 消息队列?

192.168.11.150 es1
192.168.11.151 es2
192.168.11.152 kibana

192.168.11.150 和192.168.11.151操作安装 E L

F:\学习笔记\EKL图形化界面安装\ELK实验步骤 按照文档步骤来

1、es取主从和数据模式 node.master: true
es数据库的主从类型 true false
node.data: true
数据节点,是否保存数据,logstash发送数据,节点是否接受以及保存。
es如何创建,修改,删除数据 数据管理
通过http的方式
post方式修改数据

创建数据

curl -X PUT 'localhost:9200/index-demo/test/1?pretty&pretty' -H 'content-Type: application/json' -d '{"user":"zhangsan","mesg":"hello world"}'

localhost:9200 对应的就是本地数据库的地址 ip+端口
index-demo 创建索引分片的名称
test 数据名称
1 数据的id字段
?pretty&pretty 参数设定为json格式
-d 数据的具体内容

修改数据

curl -X **POST** 'localhost:9200/index-demo/test/1/_update?pretty' -H 'Content-Type: application/json' -d '{  "doc": {    "user": "zhangsan",    "mesg": "hello1 world1"  } }'

删除数据

curl -X DELETE 'localhost:9200/index-demo/test/1?pretty&pretty' -H 'content-Type: application/json' -d '{"user":"zhangsan","mesg":"hello world"}'

192.168.11.152安装日志图形化部署

收集日志文件脚本
[root@apache-elk3 conf.d]# vim syetem.conf
input{

  file{
        path =>"/var/log/messages"
        type =>"system"
        start_position =>"beginning"
 }
}
output {
    elasticsearch {
              hosts=>["192.168.11.150:9200","192.168.11.151:9200"]
              index=>"system-%{+YYYY.MM.dd}"
 }
}
[root@apache-elk3 conf.d]# pwd
/etc/logstash/conf.d
[root@apache-elk3 conf.d]# logstash -f system.conf --path.data /opt/test2 &    #开始日志收集 
#输入之后等一会 会出现成功标志
[root@apache-elk3 opt]#cd /opt/
[root@apache-elk3 opt]#rpm -ivh kibana-6.7.2-x86_64.rpm
[root@apache-elk3 conf.d]# vim /etc/kibana/kibana.yml
 2 server.port: 5601
 7 server.host: "0.0.0.0"
 28 elasticsearch.hosts: ["http://192.168.11.150:9200","http://192.168.11.151:9200"]
 37 kibana.index: ".kibana"
 96 logging.dest: /var/log/kibana.log
 113 i18n.locale: "zh-CN"
[root@apache-elk3 opt]#  systemctl restart kibana.service 
[root@apache-elk3 opt]#  systemctl enable  kibana.service 
[root@apache-elk3 opt]#  netstat -antp | grep 5601
[root@apache-elk3 opt]# chmod 777 /var/log/messages

浏览器访问:192.168.11.152:5601
http日志收集
[root@apache-elk3 conf.d]# pwd
/etc/logstash/conf.d
[root@apache-elk3 conf.d]# vim http.conf
input {

      file{
           path => "/etc/httpd/logs/access_log"
           type => "access"
           start_position => "beginning"
          }
      file{
           path => "/etc/httpd/logs/error_log"
           type => "error"
           start_position => "beginning"
          }
}
output {
        if [type] == "access" {

          elasticsearch{
                  hosts=>["192.168.11.150:9200","192.168.11.151:9200"]
                  index=> "apache_access-%{+YYYY.MM.dd}"
        }
   }
            if [type] == "error" {

          elasticsearch{
                  hosts=>["192.168.11.150:9200","192.168.11.151:9200"]
                  index=> "apache_error-%{+YYYY.MM.dd}"
                       }
   }
[root@apache-elk3 conf.d]# logstash -f http.conf --path.data /opt/test5 &
API接口:

软件内部代码之间通信的接口 代码的连接 代码之间调用的接口
端口是对外提供访问程序的内容结构

filebeat:
作用:1、可以在本机收集日志
2、远程收集日志
3、轻量级的日志收集系统,可以在非Java环境运行
logstash占用资源比较大,属于重量级,需要再jvm运行,消耗资源大启动-个logstash要消耗500M左右的内存

192.168.11.137 nginx

[root@test2 opt]# cd /usr/local/filebeat/
[root@test2 filebeat]# cp filebeat.yml filebeat.yml.bak
[root@test2 filebeat]# vim filebeat.yml   ##发
 21 - type: log
 22   enabled: true
 23   paths:
 24     - /usr/local/nginx/logs/access.log
 25     - /usr/local/nginx/logs/error.log
  26 #开启日志收集,以及确定日志文本路径,指定标签和发送到目标主机的logstash
 27   tags: ["nginx"]
 28   fields:
 29     service_name: 192.168.11.137_nginx
 30     log_type: nginx
 31     from: 192.168.11.137
 
150 #output.elasticsearch:
151   # Array of hosts to connect to.
152 #  hosts: ["localhost:9200"]
162 #----------------------------- Logstash output --------------------------------
163 output.logstash:
164   # The Logstash hosts
165   hosts: ["192.168.11.152:5045"]   #5044  logstash默认的端口,只要会死logstash主机上没有占用的端口可以使用。大于1024

[root@test2 filebeat]# nohup ./filebeat -e -c filebeat.yml > filebeat.out &
-e  输出到标准输出
-c  指定配置文件
nohup:在系统的后台运行,不会因为终端的关闭导致程序停止运行,可以把运行的日志保存到指定文件

192.168.11.152

nginx_137.conf
input {
   beats { port => "5045"}
}
output {
      if "nginx" in [tags] {
        elasticsearch  {
               hosts=>["192.168.11.150:9200","192.168.11.151:9200"]
               index=> "%{[fields][service_name]}-%{+YYYY.MM.dd}"
          }
   }
}

[root@apache-elk3 conf.d]# logstash -f nginx_137.conf --path.data /opt/test6 &
[2] 60608

修改nginx默认访问端口
nginx 8888
httpd:80
mysql:3306

mysql日志路径: general_log_file=/usr/local/mysql/data/mysql_general.log
nginx 日志路径:     - /usr/local/nginx/logs/access.log
                    - /usr/local/nginx/logs/error.log

httpd日志路径: /var/log/httpd/access_log
               /var/log/httpd/access_log

[root@myslq4 nginx]# vim /etc/nginx/nginx.conf
 38     server {
 39         listen       8888;
 40         listen       [::]:8888;
 41         server_name  _;
 42         root         /usr/share/nginx/html;
 [root@myslq4 nginx]# netstat -antp | grep nginx
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      30416/nginx: master 
tcp6       0      0 :::8888                 :::*                    LISTEN      30416/nginx: master 

tstat -antp | grep nginx
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 30416/nginx: master
tcp6 0 0 :::8888 ::😗 LISTEN 30416/nginx: master


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码要你命

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值