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进数据库
​
​
然后在可视化页面刷新
相关推荐
深海呐1 小时前
Android AlertDialog圆角背景不生效的问题
android
ljl_jiaLiang1 小时前
android10 系统定制:增加应用使用数据埋点,应用使用时长统计
android·系统定制
花花鱼1 小时前
android 删除系统原有的debug.keystore,系统运行的时候,重新生成新的debug.keystore,来完成App的运行。
android
落落落sss2 小时前
sharding-jdbc分库分表
android·java·开发语言·数据库·servlet·oracle
消失的旧时光-19434 小时前
kotlin的密封类
android·开发语言·kotlin
cheri--5 小时前
adb install失败: INSTALL_PARSE_FAILED_NO_CERTIFICATES
adb
服装学院的IT男6 小时前
【Android 13源码分析】WindowContainer窗口层级-4-Layer树
android
CCTV果冻爽7 小时前
Android 源码集成可卸载 APP
android
码农明明7 小时前
Android源码分析:从源头分析View事件的传递
android·操作系统·源码阅读
秋月霜风8 小时前
mariadb主从配置步骤
android·adb·mariadb