ELK实现nginx mysqld httpd的日志收集

通过配置收集日志文件,发送到可视化页面

API接口:

软件内部代码之间通信的接口,代码的连接,代码之间调用的接口

端口是对外提供访问的接口

filebeat:

1、可以在本机收集日志

2、也可以远程收集日志

3、轻量级的日志系统,可以在非java环境运行

logstash实际在java环境中运行,资源消耗低,启动一个logstash要小号500M左右的内存

filebeat只消耗10M左右的内存

mysql nginx httpd

开一个MySQL在里面安装nginx httpd

复制代码
[root@MySQL ~]# systemctl stop firewalld
[root@MySQL ~]# setenforce 0
[root@MySQL ~]# yum -y install nginx httpd
​
[root@MySQL opt]# vim /etc/my.cnf   #开启MySQL日志文件
general_log=ON
general_log_file=/usr/local/mysql/data/mysql_general.log
#重启
[root@MySQL opt]# systemctl restart mysqld
​
​
[root@MySQL opt]# vim /etc/nginx/nginx.conf
  server {
        listen       82;
        #listen       [::]:80;
[root@MySQL ~]# systemctl restart nginx
[root@MySQL ~]# systemctl restart httpd
​
[root@MySQL filebeat]# vim filebeat.yml 
- type: log
  enabled: true
  paths:
    - /var/log/nginx/access.log
    - /var/log/nginx/error.log
  tags: ["nginx"]
  fields:
    servuce_name: 192.168.65.13_nginx
    log_type: nginx
    from: 192.168.65.13
​
- type: log
  enabled: true
  paths:
    - /var/log/httpd/access_log
    - /var/log/httpd/error_log
  tags: ["httpd"]
  fields:
    servuce_name: 192.168.65.13_httpd
    log_type: httpd
    from: 192.168.65.13
​
- type: log
  enabled: true
  paths:
    - /usr/local/mysql/data/mysql_general.log
  tags: ["mysqld"]
  fields:
    servuce_name: 192.168.65.13_myqld
    log_type: mysqld
    from: 192.168.65.13
output.logstash:
  # The Logstash hosts
  hosts: ["192.168.65.43:5046"]
​
​
[root@MySQL filebeat]# nohup ./filebeat -e -c filebeat.yml > filebeat.out &
[1] 23086
[root@MySQL filebeat]# nohup: 忽略输入重定向错误到标准输出端
​
​
复制代码
[root@test43 conf.d]# vim nmh.conf
​
input {
     beats { port => "5046"}
}
output {
​
    if "nginx" in [tags] {
      elasticsearch  {
           hosts => ["192.168.65.44:9200","192.168.65.45:9200"]
           index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
                  }
          }
      if "httpd" in [tags] {
      elasticsearch  {
           hosts => ["192.168.65.44:9200","192.168.65.45:9200"]
           index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
                  }
          }
       if "mysqld" in [tags] {
      elasticsearch  {
           hosts => ["192.168.65.44:9200","192.168.65.45:9200"]
           index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
                  }
          }
}
~        
​
[root@test43 conf.d]# logstash -f nmh.conf --path.data /opt/test1 &
[1] 54366
​
​
在浏览器访问:192.168.65.13:82
192.168.65.13
在xshell进数据库
​
​
然后在可视化页面刷新
相关推荐
Whisper_Sy1 天前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 应用列表实现
android·开发语言·javascript·flutter·php
北海屿鹿1 天前
【MySQL】内置函数
android·数据库·mysql
臻一1 天前
rk3576+安卓14 ---上电时序调整
android
踢球的打工仔1 天前
typescript-接口的基本使用(一)
android·javascript·typescript
2501_915918411 天前
如何在iPad上找到并打开文件夹的完整指南
android·ios·小程序·uni-app·iphone·webview·ipad
臻一1 天前
rk3576+安卓14---uboot
android
2501_944521591 天前
Flutter for OpenHarmony 微动漫App实战:主题配置实现
android·开发语言·前端·javascript·flutter·ecmascript
2501_944521591 天前
Flutter for OpenHarmony 微动漫App实战:动漫卡片组件实现
android·开发语言·javascript·flutter·ecmascript
知1而N1 天前
电脑上运行APK文件(Android应用程序包),需要借助特定的软件或功能,因为Windows/macOS/Linux系统无法原生直接运行安卓应用
android·macos·电脑
代码的奴隶(艾伦·耶格尔)1 天前
cdc实时监听数据库
adb