ELK + Redis 日志收集 & HAProxy
参考博文:http://www.ttlsa.com/linux/haproxy-log-configuration-syslog/
引入 Redis 消息队列
Log-file 收集数据到 Redis
| 主机 | IP | 部署服务 |
|---|---|---|
| web01 | 172.16.1.7 | Nginx,Tomcat,Logstash |
| dbtest01 | 172.16.1.121 | ElasticSearch,Kibana,Redis |
| dbtest02 | 172.16.1.122 | ElasticSearch |
| dbtest03 | 172.16.1.123 | ElasticSearch |
收集 Nginx & Tomcat 日志
# 日志文件到 Redis
[root@web01 ~]# vim /etc/logstash/conf.d/file_to_redis.conf
input {
file {
type => "nginx_log"
path => "/var/log/nginx/access.log"
start_position => "beginning"
codec => "json"
}
file {
type => "tomcat_log"
path => "/usr/local/tomcat/logs/localhost_access_log.*.log"
start_position => "beginning"
codec => "json"
}
}
output {
if [type] == "nginx_log" {
redis {
host => "172.16.1.121"
port => "6379"
data_type => "list"
db => "0"
key => "nginx_log"
}
}
if [type] == "tomcat_log" {
redis {
host => "172.16.1.121"
port => "6379"
data_type => "list"
db => "0"
key => "tomcat_log"
}
}
}
#=============== 或者(简写)================#
# 日志文件到 Redis
[root@web01 conf.d]# cat file_to_redis.conf
input {
file {
type => "nginx_log"
path => "/var/log/nginx/access.log"
start_position => "beginning"
codec => "json"
}
file {
type => "tomcat_log"
path => "/usr/local/tomcat/logs/localhost_access_log.*.log"
start_position => "beginning"
codec => "json"
}
}
output {
redis {
host => ["172.16.1.121"]
port => "6379"
data_type => "list"
db => "0"
key => "%{type}"
}
}
# 验证:访问 Nginx 和 Tomcat 页面,查看 Redis 里面有没有 Key
127.0.0.1:6379> LLEN nginx_log
(integer) 1
127.0.0.1:6379> LLEN nginx_log
(integer) 888
127.0.0.1:6379> LRANGE nginx_log 0 -1
Redis 收集数据到 ElasticSearch
# Redis 到 es
[root@web01 conf.d]# cat redis_to_es.conf
input {
redis {
host => "172.16.1.121"
port => "6379"
db => "0"
data_type => "list"
key => "nginx_log"
}
redis {
host => "172.16.1.121"
port => "6379"
db => "0"
data_type => "list"
key => "tomcat_log"
}
}
output {
if [type] == "nginx_log" {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "nginx_log_%{+YYYY-MM-dd}"
}
}
if [type] == "tomcat_log" {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "tomcat_log_%{+YYYY-MM-dd}"
}
}
}
启动 Logstash 多实例
[root@web01 conf.d]# mkdir /data/logstash/file_to_redis
[root@web01 conf.d]# mkdir /data/logstash/redis_to_es
[root@web01 conf.d]# chown logstash.logstash /data -R
[root@web01 conf.d]# logstash -f /etc/logstash/conf.d/file_to_redis.conf --path.data=/data/logstash/file_to_redis &
[root@web01 conf.d]# logstash -f /etc/logstash/conf.d/redis_to_es.conf --path.data=/data/logstash/redis_to_es &
TCP / UDP 模块
TCP 模块初识
[root@web01 ~]# vim /etc/logstash/conf.d/tcp.conf
input {
tcp {
port => "1234"
mode => "server"
}
}
output {
stdout {}
}
使用 telnet 工具测试
[root@db02 ~]# telnet 172.16.1.7 1234
Trying 172.16.1.7...
Connected to 172.16.1.7.
Escape character is '^]'.
123
345
# 输出内容
{
"@timestamp" => 2020-08-17T02:23:05.833Z,
"host" => "172.16.1.52",
"port" => 33002,
"message" => "\r",
"@version" => "1"
}
{
"@timestamp" => 2020-08-17T02:23:32.562Z,
"host" => "172.16.1.52",
"port" => 33002,
"message" => "123\r",
"@version" => "1"
}
{
"@timestamp" => 2020-08-17T02:23:38.300Z,
"host" => "172.16.1.52",
"port" => 33002,
"message" => "345\r",
"@version" => "1"
}
使用 nc 工具测试
# 安装
[root@db02 ~]# yum install -y nc
# 使用 nc 工具
[root@db02 ~]# nc 172.16.1.7 1234
123
456
# 使用 nc 工具收集日志到 logstash 的服务器
[root@web01 ~]# tail -f /var/log/nginx/access.log | nc 10.0.0.7 1234 &
[1] 29595
# 发送伪设备数据
[root@web01 ~]# echo "伪设备测试" > /dev/tcp/10.0.0.7/1234
收集日志到 ElasticSearch
[root@web01 ~]# vim /etc/logstash/conf.d/tcp.conf
input {
tcp {
port => "1234"
mode => "server"
}
}
output {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "tcp_log_%{+YYYY-MM-dd}"
}
}
Rsyslog + Logstash 收集日志
Rsyslog 介绍
Rsyslog 是一个快速处理收集系统日志的程序,提供了高性能、安全功能和模块化设计,Rsyslog 是 Syslog 的升级版,它将多种来源输入输出转换结果到目的地,据官网介绍,现在可以处理 100 万条信息
Rsyslog 安装
[root@web01 ~]# yum isntall -y rsyslog
Rsyslog 配置
[root@web01 ~]# vim /etc/rsyslog.conf
# 打开注释
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
# 添加日志收集级别
local6.* @@172.16.1.7:2222
安装 HAProxy
[root@web01 ~]# yum install -y haproxy
配置 HAProxy
[root@web01 ~]# cat /etc/haproxy/haproxy.cfg
# 全局配置
global
# 最大并发
maxconn 100000
# 安全机制
chroot /var/lib/haproxy
# 指定启动的用户和组
uid 99
gid 99
daemon
# haproxy 的进程数
nbproc 1
pidfile /var/run/haproxy.pid
# 指定日志级别
log 127.0.0.1 local6 info
# 默认配置
defaults
# 开启长连接
option http-keep-alive
# 获取用户真实 IP
option forwardfor
# 最大连接数
maxconn 100000
# 支持 http 协议
mode http
# 设置连接超时时间
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
# 监控状态
listen stats
# 支持 http
mode http
# 监听端口
bind 0.0.0.0:9999
# 启动
stats enable
# 日志级别
log global
# 访问 uri 地址
stats uri /haproxy-status
# 状态页用户名和密码
stats auth haadmin:123456
#frontend web_port
frontend web_port
bind 0.0.0.0:80
mode http
option httplog
log global
option forwardfor
###################ACL Setting##########################
acl nginx hdr_dom(host) -i www.nginx.com
acl tomcat hdr_dom(host) -i www.tomcat.com
###################USE ACL##############################
use_backend nginx_host if nginx
use_backend tomcat_host if tomcat
########################################################
backend nginx_host
mode http
option httplog
balance source
server web01 10.0.0.7:8081 check inter 2000 rise 3 fall 2 weight 1
backend tomcat_host
mode http
option httplog
balance source
server web01 10.0.0.7:8080 check inter 2000 rise 3 fall 2 weight 1
修改 Nginx 启动端口
[root@web01 ~]# vim /etc/nginx/nginx.conf
server {
listen 8081 default_server;
...
启动 HAProxy
# 启动 haproxy
[root@web01 ~]# systemctl start haproxy.service
# 启动 rsyslog,用来收集 haproxy 日志,转发到 172.16.1.7:2222 端口
[root@web01 ~]# systemctl start rsyslog
# 验证,rsyslog 开启 514 端口, haproxy 开启 80 端口(frontend)& 9999 端口(stats)
[root@web01 ~]# netstat -lntp
访问 Status 页面
# 访问 http://10.0.0.7:9999/haproxy-status
# 用户:haadmin
# 密码:123456
访问 Nginx 和 Tomcat
# 配置本地 hosts
10.0.0.7 www.nginx.com
10.0.0.7 www.tomcat.com
# 访问页面
http://www.nginx.com/
http://www.tomcat.com/
Logstash 收集 HAProxy 日志到 Stdout
[root@web01 ~]# cat /etc/logstash/conf.d/haproxy.conf
input {
syslog {
port => "2222"
}
}
output {
stdout {}
}
# 访问 haproxy 的页面,查看有无输出
Logstash 收集 HAProxy 日志到 ElasticSearch
[root@web01 ~]# cat /etc/logstash/conf.d/haproxy.conf
input {
syslog {
port => "2222"
}
}
output {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "haproxy_%{+YYYY-MM-dd}"
}
}
ELK + Redis 日志收集 & HAProxy的更多相关文章
- [原创]ubuntu14.04部署ELK+redis日志分析系统
ubuntu14.04部署ELK+redis日志分析系统 [环境] host1:172.17.0.4 搭建ELK+redis服务 host2:172.17.0.3 搭建logstash+nginx服务 ...
- ELK分布式日志收集搭建和使用
大型系统分布式日志采集系统ELK全框架 SpringBootSecurity1.传统系统日志收集的问题2.Logstash操作工作原理3.分布式日志收集ELK原理4.Elasticsearch+Log ...
- StringBoot整合ELK实现日志收集和搜索自动补全功能(详细图文教程)
@ 目录 StringBoot整合ELK实现日志收集和搜索自动补全功能(详细图文教程) 一.下载ELK的安装包上传并解压 1.Elasticsearch下载 2.Logstash下载 3.Kibana ...
- 05 . ELK Stack+Redis日志收集平台
环境清单 IP hostname 软件 配置要求 网络 备注 192.168.43.176 ES/数据存储 elasticsearch-7.2 内存2GB/硬盘40GB Nat,内网 192.168. ...
- SpringBoot+kafka+ELK分布式日志收集
一.背景 随着业务复杂度的提升以及微服务的兴起,传统单一项目会被按照业务规则进行垂直拆分,另外为了防止单点故障我们也会将重要的服务模块进行集群部署,通过负载均衡进行服务的调用.那么随着节点的增多,各个 ...
- Centos7下ELK+Redis日志分析平台的集群环境部署记录
之前的文档介绍了ELK架构的基础知识,日志集中分析系统的实施方案:- ELK+Redis- ELK+Filebeat - ELK+Filebeat+Redis- ELK+Filebeat+Kafka+ ...
- 传统ELK分布式日志收集的缺点?
传统ELK图示: 单纯使用ElK实现分布式日志收集缺点? 1.logstash太多了,扩展不好. 如上图这种形式就是一个 tomcat 对应一个 logstash,新增一个节点就得同样的拥有 logs ...
- ELK:日志收集分析平台
简介 ELK是一个日志收集分析的平台,它能收集海量的日志,并将其根据字段切割.一来方便供开发查看日志,定位问题:二来可以根据日志进行统计分析,通过其强大的呈现能力,挖掘数据的潜在价值,分析重要指标的趋 ...
- 日志分析平台ELK之日志收集器logstash
前文我们聊解了什么是elk,elk中的elasticsearch集群相关组件和集群搭建以及es集群常用接口的说明和使用,回顾请查看考https://www.cnblogs.com/qiuhom-187 ...
随机推荐
- SAP 修改表和表中数据
平时修改表中数据的方式有一下几种: 1.一般就是通过SE11或者是SE16进去,找到那条记录,然后将模式变成EDIT,然后修改保存. 2.通过SQL语句在程序中实现数据库表的修改操作 3.通过SE16 ...
- spring boot项目问题汇总
spring遇到的问题汇总 有关日志的打印和日志如何使用 在实际项目中,我们的程序都是运行在linux上,有错误时也不能在本地的控制台上直观看到,所有合理打印日志对于程序员迅速定位到错误. 打印日志时 ...
- python_mmdt:从0到1--实现简单恶意代码分类器(二)
概述 上篇文章python_mmdt:一种基于敏感哈希生成特征向量的python库(一)我们介绍了一种叫mmdt_hash(敏感哈希)生成方法,并对其中的概念做了基本介绍.本篇,我们重点谈谈mmdt_ ...
- 浅析Asp.Net Core框架IConfiguration配置
目录 一.建造者模式(Builder Pattern) 二.核心接口与配置存储本质 三.简易QueryString配置源实现 四.宿主配置与应用配置 一.建造者模式 为什么提建造者模式?在阅读.NET ...
- 全栈性能测试修炼宝典-JMeter实战笔记(二)
性能测试初体验 性能测试实质:利用工具去模拟大量用户操作来验证系统能够承受的负载情况,找出潜在的性能问题,分析并解决:找出系统性能变化趋势,为后续的扩展提供参考 测试分类 测试内容中,负载测试.压力测 ...
- 阿里云服务器centos7,docker部署mysql+Redis+vue+springboot+Nginx+fastdfs,亲测可用
一.购买云服务器 我是今年双十一期间在阿里云购买的服务器, 简单配置2核_4G_40G_3M,三年用了不到800块,不过当时我记得腾讯云更便宜,个人感觉,阿里的云服务器更加的稳定, 毕竟身经百战, 经 ...
- 慕课网金职位 Java工程师2020 百度网盘下载
百度网盘链接:https://pan.baidu.com/s/1xshLRO3ru0LAsQQ0pE67Qg 提取码:bh9f 如果失效加我微信:610060008[视频不加密,资料代码齐全,超清一手 ...
- 小w、小j和小z
n个月没更了,现在学的东西很难,掌握不好,不敢更! 这个题目既不超范围又足够难想,反正我没想出来,很好的题目! 我发现noi.ac上的题目很不错!!! ------------------------ ...
- Excel常见后缀名
1.格式.xlsx:excel2007-2016版默认的文件格式,不能有宏: 2.格式.xls:excel97-2003版,可以有宏: 3.格式.csv:以逗号分隔的文本文件,便于兼容其他程序,只保存 ...
- 通过Portainer统一管理不同服务器的Docker
通过Portainer统一管理不同服务器的Docker 一.可视化管理工具Portainer的安装 二.跨服务器管理Docker 2.1开启2375监听端口 2.2Portainer配置远程管理 一. ...