1.rsyslog介绍
收集日志的系统
2.安装rsyslog
[root@logstash ~]# yum install -y rsyslog
3.配置rsyslog (logstash 调用rsyslog去搜集日志)
[root@logstash ~]# vim /etc/rsyslog.conf
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
#添加一行
local6.* @@10.0.0.54:2222 # 这个端口用于接收上面tcp 和udp传输过来的内容 6代表级别
4.安装haproxy
[root@logstash ~]# yum install -y haproxy
5.配置haproxy
[root@logstash ~]# cat /etc/haproxy/haproxy.cfg
global
maxconn 100000 #最大连接数(并发)
chroot /var/lib/haproxy #安装目录
uid 99 #用户,还可以写 user www
gid 99 #用户组,还可以写 group www
daemon #后台运行
nbproc 1 #工作进程
pidfile /var/run/haproxy.pid #pid文件
log 127.0.0.1 local6 info #收集的日志的信息
defaults #默认的配置
option http-keep-alive #长链接
option forwardfor #获取用户真实IP
maxconn 100000 #最大连接数(并发)
mode http #支持http协议
timeout connect 300000ms #连接的超时时间
timeout client 300000ms #客户端发送消息的超时时间
timeout server 300000ms #服务端返回消息的超时时间
listen stats #监听页面
mode http #支持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 #haproxy服务监听的地址和端口
mode http #支持http协议
option httplog #http的日志
log global #全局的日志
option forwardfor #获取用户真实IP
###################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 web1 10.0.0.54:8081 check inter 2000 rise 3 fall 2 weight 1
backend tomcat_host
mode http
option httplog
balance source
server web1 10.0.0.54:8080 check inter 2000 rise 3 fall 2 weight 1
6.修改nginx端口
[root@logstash ~]# vim /etc/nginx/conf.d/default.conf
server {
listen 8081;
server_name www.nginx.com;
...
}
[root@logstash ~]# nginx -s reload
7.启动haproxy和rsyslog
[root@logstash ~]# systemctl start haproxy.service
[root@logstash ~]# systemctl start rsyslog
8.修改tomcat站点目录
#修改tomcat配置文件,将默认站点目录改成/webapps/webdir
[root@elkstack03 ~]# vim /usr/local/tomcat/conf/server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/usr/local/tomcat/webapps/webdir" debug="0" reloadable="false"
crossContext="true"/>
9.访问页面查看
http://10.0.0.54:9999/haproxy-status
http://www.nginx.com/
http://www.tomcat.com/
10.配置收集haproxy的日志
[root@logstash ~]# vim /etc/logstash/conf.d/haproxy_output.conf
input{
syslog {
type => "rsyslog_haproxy"
port => "2222"
}
}
output{
stdout{
codec => rubydebug
}
}
[root@logstash ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/haproxy_output.conf