rsyslog介绍及安装配置

在centos 6及之前的版本叫做syslog,centos 7开始叫做rsyslog,根据官方的介绍,rsyslog(2013年版本)可以达到每秒转发百万条日志的级别,官方网址:http://www.rsyslog.com/


安装配置rsyslog
#安装rsyslog
[root@elkstack03 ~]# yum install -y rsyslog
#编辑rsyslog配置文件
[root@elkstack03 ~]# vim /etc/rsyslog.conf
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
#最后面一行添加,local6对应haproxy配置文件定义的local级别,端口为Logstash的端口
local6.* @@10.0.0.53:2222

安装配置haproxy
#安装haproxy
[root@elkstack03 ~]# yum install -y haproxy
#编辑haproxy配置文件
[root@elkstack03 ~]# vim /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /var/lib/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /var/run/haproxy.pid
log 127.0.0.1 local6 info defaults
option http-keep-alive
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 pc hdr_dom(host) -i www.elk.com
acl mobile hdr_dom(host) -i m.elk.com
###################USE ACL##############################
use_backend pc_host if pc
use_backend mobile_host if mobile
######################################################## backend pc_host
mode http
option httplog
balance source
server web1 10.0.0.53:8081 check inter 2000 rise 3 fall 2 weight 1 backend mobile_host
mode http
option httplog
balance source
server web1 10.0.0.53:8080 check inter 2000 rise 3 fall 2 weight 1 #启动haproxy
[root@elkstack03 ~]# /etc/init.d/haproxy start
正在启动 haproxy: [确定] #启动rsyslog
[root@elkstack03 ~]# /etc/init.d/rsyslog start
启动系统日志记录器: #验证端口
[root@elkstack03 ~]# netstat -lntup
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 9082/haproxy
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9631/haproxy #验证进程
[root@elkstack03 ~]# ps -ef|grep haproxy
nobody 9082 1 0 14:04 ? 00:00:00 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid #修改nginx配置文件,将端口改为8081
[root@elkstack03 ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; log_format access_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"status":"$status"}';
access_log logs/access_json.log access_json; server {
listen 8081;
server_name 10.0.0.53;
location / {
root /code/html;
index index.html index.htm;
}
}
} #修改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"/> #重启nginx
[root@elkstack03 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.3/conf/nginx.conf test is successful
[root@elkstack03 ~]# /usr/local/nginx/sbin/nginx -s reload #重启tomcat
[root@elkstack03 ~]# cd /usr/local/tomcat/bin/
[root@elkstack03 bin]# ./catalina.sh stop
[root@elkstack03 bin]# ./catalina.sh start #修改本地hosts文件
10.0.0.53 www.elk.com
10.0.0.53 m.elk.com

测试域名访问

测试haproxy,打开浏览器,访问:http://www.elk.com/

测试haproxy,打开浏览器,访问:http://m.elk.com/


配置Logstash
#编辑Logstash配置文件
[root@elkstack03 conf.d]# vim haproxy.cof
input{
syslog {
type => "rsyslog_haproxy"
port => "2222"
}} output{
stdout{
codec => rubydebug
}} #启动Logstash
[root@elkstack03 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/haproxy.conf #检查Logstash端口
[root@elkstack03 ~]# netstat -lntup|grep 2222
tcp 0 0 :::2222 :::* LISTEN 9867/java
udp 0 0 :::2222 :::* 9867/java

访问haproxy管理页面测试数据

打开浏览器,访问:http://10.0.0.53:9999/haproxy-status

输入haproxy配置文件中的用户名和密码
用户名:haadmin
密码:123456


将输出改成ES
#进入Logstash配置文件目录
[root@elkstack03 ~]# cd /etc/logstash/conf.d
#编辑配置文件
[root@elkstack03 conf.d]# vim haproxy.conf
input{
syslog {
type => "rsyslog_haproxy"
port => "2222"
}
} output{
elasticsearch {
hosts => ["10.0.0.51:9200"]
index => "logstash_rsyslog-%{+YYYY.MM.dd}"
}
} #启动Logstash
[root@elkstack03 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/haproxy.conf &

打开浏览器,访问:http://10.0.0.51:9100/


将ES索引添加到Kibana中

打开浏览器,访问:http://10.0.0.54:5601/

第九章·Logstash深入-Logstash配合rsyslog收集haproxy日志的更多相关文章

  1. ELK之收集haproxy日志

    由于HAProxy的运行信息不写入日志文件,但它依赖于标准的系统日志协议将日志发送到远程服务器(通常位于同一系统上),所以需要借助rsyslog来收集haproxy的日志.haproxy代理nginx ...

  2. filebeat+logstash+elasticsearch收集haproxy日志

    filebeat用于是日志收集,感觉和 flume相同,但是用go开发,性能比较好 在2.4版本中, 客户机部署logstash收集匹配日志,传输到 kafka,在用logstash 从消息队列中抓取 ...

  3. rsyslog收集nginx日志配置

    rsyslog日志收集配置 rsyslog服务器收集各服务器的日志,并汇总,再由logstash处理 请查看上一篇文章  http://bbotte.blog.51cto.com/6205307/16 ...

  4. Rsyslog收集应用日志

    收集系统其它服务日志,在客户端node1 上操作,示例以openstack-nova 服务的日志为例: 1.先修改配置文件 /etc/rsyslog.conf,完整内容如下: [root@node1 ...

  5. ELK日志系统之使用Rsyslog快速方便的收集Nginx日志

    常规的日志收集方案中Client端都需要额外安装一个Agent来收集日志,例如logstash.filebeat等,额外的程序也就意味着环境的复杂,资源的占用,有没有一种方式是不需要额外安装程序就能实 ...

  6. ELK + Redis 日志收集 & HAProxy

    参考博文:http://www.ttlsa.com/linux/haproxy-log-configuration-syslog/ 引入 Redis 消息队列 Log-file 收集数据到 Redis ...

  7. 第六章·Logstash深入-收集java日志

    1.通过Logstash收集java日志并输出到ES中 因为我们现在需要用Logstash收集tomcat日志,所以我们暂时将tomcat安装到Logstash所在机器,也就是db03:10.0.0. ...

  8. 第七章·Logstash深入-收集NGINX日志

    1.NGINX安装配置 源码安装nginx 因为资源问题,我们先将nginx安装在Logstash所在机器 #安装nginx依赖包 [root@elkstack03 ~]# yum install - ...

  9. logstash收集syslog日志

    logstash收集syslog日志注意:生产用syslog收集日志!!! 编写logstash配置文件 #首先我用rubydebug测试数据 [root@elk-node1 conf.d]# cat ...

随机推荐

  1. [Mac]安装pyspider的大坑

    1.切记这是一个大坑. 2.我在用mac电脑安装pyspider的时候,原以为pip install pyspider 就万事大吉,合家欢乐了,but the question 比较多. 第一个问题: ...

  2. MATLAB学习(七)求解优化问题:线性规划 非线性规划 拟合与插值 多目标规划

    Minf(x)=-5x1  -4x2  -6x3                x1   -x2    +x3  <=20              3x1  +2x2 +4x3 <=42 ...

  3. Linux (Ubuntu)上面安装maven

    1 首先检查linux上是否有maven mvn -v 或者mvn -version 如果没有安装,提示如下: ubuntu@ip----:~$ mvn -v The program 'mvn' ca ...

  4. MongoDB集群-主从复制(副本集)、failover

    1.概念 主从复制的目的:数据冗余.备份.读写分离 主从方式:一主一从(不推荐,只能实现复制,主节点挂掉且未重新启动的时候,无法提升从节点为master),一主一从一裁判,一主多从 复制方式:主节点记 ...

  5. lua学习笔记4--XLua

    下载XLua:   https://github.com/tencent/xlua 项目中使用XLua只需将Plugins和XLua两个文件夹拷贝到U3D中即可XLua只是核心,用于实现Lua和C#交 ...

  6. 【计算机视觉】TPAMI的Editors

    写了一篇文章准备试试TPAMI,没指望中,就当听听意见也好,让选两个Editors (2 preferred editors required),于是调研了一下这些人都是做什么的,有同行路过请评价补充 ...

  7. alertmanager + federate - Prometheus outside k8s cluster + 总体架构图 对接企业微信告警 + curl alertmanager to send alert

    1.实验的架构 2.k8s 集群外的Prometheus的配置文件 [root@do1cloud03 prometheus]# cat prometheus.yml |egrep -v '#' glo ...

  8. JavaSE基础(三)--Java基础语法

    Java 基础语法 一个 Java 程序可以认为是一系列对象的集合,而这些对象通过调用彼此的方法来协同工作.下面简要介绍下类.对象.方法和实例变量的概念. 对象:对象是类的一个实例,有状态和行为.例如 ...

  9. 2019牛客暑期多校训练营(第五场)- G subsequence 1

    题目链接:https://ac.nowcoder.com/acm/contest/885/G 题意:给定字符串s,t,求s中满足字典序大于t的子序列的个数. 思路:组合数学+dp.当子序列长度大于m时 ...

  10. 精通Java中的volatile关键字

    在一些开源的框架的源码当中时不时都可以看到volatile这个关键字,最近特意学习一下volatile关键字的使用方法. 很多资料中是这样介绍volatile关键字的: volatile是轻量级的sy ...