rsyslog介绍
1 2 3 4 5 6 |
在centos 6及之前的版本叫做syslog,centos 7开始叫做rsyslog,根据官方的介绍,rsyslog(2013年版本)可以达到每秒转发百万条日志的级别,rsyslog是日志收集处理工具 它提供了高性能,出色的安全性和模块化设计。尽管rsyslog最初是常规的syslogd,但已发展成为一种瑞士军刀式的记录工具,能够接受来自各种来源的输入,并将其转换,然后输出到不同的目的地。 当应用有限的处理时,RSYSLOG每秒可以将超过一百万的消息传递到本地目的地。即使在远程目的地和更精细的处理下,性能通常也被认为是“惊人的”。 |
安装配置rsyslog
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#安装rsyslog [root@lb01 ~]# yum install -y rsyslog #编辑rsyslog配置文件 [root@lb01 ~]# vim /etc/rsyslog.conf #开启支持udp协议 $ModLoad imudp $UDPServerRun 514 #开启支持tcp协议 $ModLoad imtcp $InputTCPServerRun 514 #最后面一行添加,local6对应haproxy配置文件定义的local级别,端口为Logstash的端口 local6.* @@10.0.0.4:2222 #logstash部署在的主机ip |
安装并配置haproxy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
#安装haproxy [root@lb01 ~]# yum install -y haproxy #编辑haproxy配置文件 [root@lb01 ~]# vim /etc/haproxy/haproxy.cfg #全局配置 global #最大连接数 maxconn 100000 #库文件权限目录 chroot /var/lib/haproxy #用户和组 uid 99 gid 99 #后台启动 daemon #指定启动进程数量 nbproc 1 #pid文件 pidfile /var/run/haproxy.pid #定义日志,与rsyslog中的配置对应 log 127.0.0.1 local6 info #默认配置 defaults #开启长连接 option http-keep-alive #获取用户真实IP option forwardfor #最大连接数 maxconn 100000 #运行模式 mode http timeout connect 300000ms timeout client 300000ms timeout server 300000ms #监听状态 listen stats #运行模式 mode http #监听地址:监听端口 bind 0.0.0.0:9999 #状态 启动 stats enable #全局日志 log global #状态检查页面的地址 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 tomcat hdr_dom(host) -i linux.tomcat.com acl nginx hdr_dom(host) -i linux.nginx.com ###################USE ACL############################## use_backend tomcat_host if tomcat use_backend nginx_host if nginx ######################################################## backend tomcat_host mode http option httplog balance roundrobin server web1 10.0.0.7:8080 check inter 2000 rise 3 fall 2 weight 1 server web2 10.0.0.8:8080 check inter 2000 rise 3 fall 2 weight 1 backend nginx_host mode http option httplog balance roundrobin server web1 10.0.0.7:80 check inter 2000 rise 3 fall 2 weight 1 server web2 10.0.0.8:80 check inter 2000 rise 3 fall 2 weight 1 #注释: check:检查健康状态 inter:检查状态的间隔时间 rise:检查次数 fall:检查过程中错误次数 weight:权重 |
启动服务
1 2 3 |
[root@redis01 ~]# systemctl start haproxy.service [root@redis01 ~]# systemctl start rsyslog |
配置hosts测试
1 2 3 4 5 6 7 |
#分别访问 linux.tomcat.com linux.nginx.com #健康检查 haadmin:123456 linux.nginx.com:9999/haproxy-status |
配置logstash收集haproxy日志
1)配置收集到标准输出
1 2 3 4 5 6 7 8 9 10 11 |
[root@redis01 ~]# vim /etc/logstash/conf.d/haproxy_stdout.conf input { syslog { port => "2222" } } output { stdout {} } |
2)配置收集到ES
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@redis01 ~]# vim /etc/logstash/conf.d/haproxy_es.conf input { syslog { port => "2222" } } output { elasticsearch { hosts => ["10.0.0.71:9200"] index => "haproxy_es_%{+YYYY-MM-dd}" } } |