rsyslog日志收集配置

rsyslog服务器收集各服务器的日志,并汇总,再由logstash处理

请查看上一篇文章  http://bbotte.blog.51cto.com/6205307/1613571

客户端/发送端 web服务器

# yum install rsyslog -y
# vim /etc/rsyslog.conf
*.* @192.168.10.1:514
# vim /etc/bashrc #收集其他服务器的操作命令
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
# . /etc/bashrc
# crontab -e
*/1 * * * * /bin/echo `date`
# service rsyslog restart

服务器/收集端 rsyslog收集,logstash服务器

# yum install rsyslog -y
# vim /etc/rsyslog.conf
$ModLoad imudp #启用udp,514端口收集日志
$UDPServerRun 514
$template logformat,"%FROMHOST-IP% %structured-data% %timegenerated% %msg%\n" #定义日志模板
$template DynFile,"/var/log/%$year%%$month%%$day%.log" #定义日志路径
:rawmsg, contains, "CROND" ?DynFile;logformat #含有"CROND"日志,输出为/var/log/%$year%%$month%%$day%.log
:rawmsg, contains, "CROND" ~
# service rsyslog restart
# tail -f /var/log/20150212.log #查看crontab的log
# tail -f /var/log/messages #查看客户端输入的命令

#rsyslog测试log传送完毕,下面是用rsyslog收集其他服务器日志:

# vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-c 5 -Q -x"
# vim /etc/rsyslog.conf                         #把下面几行注释
#$template logformat,"%FROMHOST-IP% %structured-data% %timegenerated% %msg%\n"
#$template DynFile,"/var/log/%$year%%$month%%$day%.log"
#:rawmsg, contains, "CROND" ?DynFile;logformat
# service rsyslog restart
#现在服务端收集客户端日志,并保存在/var/log各日志文件中,tail -f 查看

rsyslog其他配置 选项 :

日志级别:

―――――――――――――――――――――――-

debug       �有调式信息的,日志信息最多

info        �一般信息的日志,最常用

notice      �最具有重要性的普通条件的信息

warning     �警告级别

err         �错误级别,阻止某个功能或者模块不能正常工作的信息

crit        �严重级别,阻止整个系统或者整个软件不能正常工作的信息

alert       �需要立刻修改的信息

emerg       �内核崩溃等严重信息

none        �什么都不记录

从上到下,级别从低到高,记录的信息越来越少

#过滤日志, 由:号开头

:msg, contains, “error” /var/log/error.log

:msg, contains, “error” ~         # 忽略包含error的日志

#如果要把不同服务器发送过来的日志保存到不同的文件, 可以这样操作:

:fromhost-ip, isequal, “192.168.10.2″ /var/log/host1002.log

:FROMHOST-IP, isequal, “192.168.10.3″ /var/log/host1003.log

#现在是要把web服务器的nginx日志收集到logstash服务器上,nginx原生不支持syslog,所以要打补丁

# 为nginx打syslog补丁

# tar -xzf nginx-1.4.7.tar.gz
# cd nginx-1.4.7
# ./configure --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module \
--with-pcre=/root/pcre-8.35 --with-http_realip_module --with-http_image_filter_module
# make
# make install
#以上是安装nginx的步骤,下面打补丁
# git clone https://github.com/splitice/nginx_syslog_patch
# patch -p1 < /root/nginx-1.4.7/nginx_syslog_patch/syslog-1.5.6.patch
patching file src/core/ngx_cycle.c
patching file src/core/ngx_log.c
patching file src/core/ngx_log.h
patching file src/http/modules/ngx_http_log_module.c
patching file src/http/ngx_http_core_module.c
Hunk #2 succeeded at 4895 (offset 2 lines).
Hunk #3 succeeded at 4913 (offset 2 lines).
Hunk #4 succeeded at 4952 (offset 2 lines).
patching file src/http/ngx_http_request.c
Hunk #1 succeeded at 517 (offset -14 lines).
Hunk #2 succeeded at 798 (offset -23 lines).
Hunk #3 succeeded at 2002 (offset -23 lines).
# ./configure --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module \
--with-pcre=/root/pcre-8.35 --with-http_realip_module --with-http_image_filter_module \
--add-module=/root/nginx-1.4.7/nginx_syslog_patch/
# make
# make install
# /usr/local/nginx/sbin/nginx -V #查看编译的配置参数
nginx version: nginx/1.4.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module \
--with-pcre=/root/pcre-8.35 --with-http_realip_module --with-http_image_filter_module \
--add-module=/root/nginx-1.4.7/nginx_syslog_patch/
# grep -v ^.*# /usr/local/nginx/conf/nginx.conf|sed '/^$/d' #nginx配置
worker_processes 1;
syslog local6 nginx;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
index index.html;
root /var/www;
access_log syslog:notice|logs/host1.access.log main;
error_log syslog:notice|logs/host1.error.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

#现在的话,nginx日志有3份,一份位于/usr/local/nginx/logs,一份在/var/log/messages里面,刷新nginx首页,查看日志

#当然,在syslog收集端也有一份nginx的访问日志

# tail -f /var/log/messages

#刷新下面页面,

http://192.168.10.1/index.html#/dashboard/file/logstash.json

如果感觉这篇文章比较乱,那么请了解一些关于rsyslog的配置,以便更灵活的操控日志的收集,上面需要改动的是不同web服务器的nginx日志存储到不同的文件或目录,在logstash配置文件中稍微修改即可

https://github.com/yaoweibin/nginx_syslog_patch

http://www.rsyslog.com/doc/property_replacer.html

http://www.logstashbook.com/TheLogstashBook_sample.pdf

http://blog.chinaunix.net/uid-21807675-id-1814878.html

http://my.oschina.net/duxuefeng/blog/317570

http://www.cnblogs.com/blueswu/p/3564763.html

http://blog.clanzx.net/2013/12/31/rsyslog.html

rsyslog收集nginx日志配置的更多相关文章

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

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

  2. ELK Stack (2) —— ELK + Redis收集Nginx日志

    ELK Stack (2) -- ELK + Redis收集Nginx日志 摘要 使用Elasticsearch.Logstash.Kibana与Redis(作为缓冲区)对Nginx日志进行收集 版本 ...

  3. ELK filter过滤器来收集Nginx日志

    前面已经有ELK-Redis的安装,此处只讲在不改变日志格式的情况下收集Nginx日志. 1.Nginx端的日志格式设置如下: log_format access '$remote_addr - $r ...

  4. 安装logstash5.4.1,并使用grok表达式收集nginx日志

    关于收集日志的方式,最简单性能最好的应该是修改nginx的日志存储格式为json,然后直接采集就可以了. 但是实际上会有一个问题,就是如果你之前有很多旧的日志需要全部导入elk上查看,这时就有两个问题 ...

  5. Nginx https加密以及nginx日志配置与管理

    Nginx https加密以及nginx日志配置与管理 使用Nginx的优点Nginx作为WEB服务器,Nginx处理静态文件.索引文件.自动索引的效率非常高.Nginx作为代理服务器,Nginx可以 ...

  6. ELK 二进制安装并收集nginx日志

    对于日志来说,最常见的需求就是收集.存储.查询.展示,开源社区正好有相对应的开源项目:logstash(收集).elasticsearch(存储+搜索).kibana(展示),我们将这三个组合起来的技 ...

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

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

  8. nginx日志配置

    nginx日志配置 http://www.ttlsa.com/linux/the-nginx-log-configuration/ 日志对于统计排错来说非常有利的.本文总结了nginx日志相关的配置如 ...

  9. (转)nginx日志配置指令详解

    这篇文章主要介绍了nginx日志配置指令详解,nginx有一个非常灵活的日志记录模式,每个级别的配置可以有各自独立的访问日志,需要的朋友可以参考下日志对于统计排错来说非常有利的.本文总结了nginx日 ...

随机推荐

  1. 使用php生成数字、字母组合验证码(一)

    项目中经常会遇到一些登陆验证,支付验证等等一系列安全验证的策略.实现方法多种多样,下面就来讲解下如何用php生成简单的文字+数字组合的验证码: 所用语言php,gd库 原理解释: a>实质上是在 ...

  2. python2.7 + ubuntu14.4 + dlib19.7

    0.首先需要Cmake以及编译C++成python程序的工具 sudo apt-get install libboost-python-dev cmake 1.download dlib19.7 fr ...

  3. appium+python自动化41-切换webview时候报chromedriver版本问题

    前言 用appium切换webview的时候报chrome和chromedriver版本的问题:session not created exception: Chrome version must b ...

  4. mysql索引之五:多列索引

    索引的三星原则 1.索引将相关的记录放到一起,则获得一星 2.如果索引中的数据顺序和查找中的排列顺序一致则获得二星 3.如果索引中的列包含了查询中的需要的全部列则获得三星 多列索引 1.1.多个单列索 ...

  5. Tomcat常用设置

    远程Dbug调试: TOMCAT配置(只需设置一次): 1.在服务器的$TOMCAT_HOME/bin/catalina.sh中增加: CATALINA_OPTS="-server -Xde ...

  6. tomcat:A docBase * inside the host appBase has been specifi, and will be ignored

    警告: A docBase  D:\apache-tomcat-8.5.12\webapps\webapps\projectname inside the host appBase has been ...

  7. 快速安装laravel和依赖

    http://pkg.phpcomposer.com CMD敲命令: composer config -g repositories.packagist composer http://packagi ...

  8. 移动端安装包(APP)的测试用例

    安装 安装手册是否规范,是否简洁,是否通俗易懂. 安装手册是否齐全,正确,有改动时,文档是否同步更新 直接复制安装程序到电脑上,能否正常安装 按安装手册给出的步骤进行安装,安装是否正确 查看在安装过程 ...

  9. JAVASCRIPT数据类型(值类型-引用类型-类型总览)

    值类型:也称为原始数据或原始值(primitive value). 这类值存储在栈(stack)中,栈是内存中一种特殊的数据结构,也称为线性表,栈按照后进先出的原则存储数据,先进入的数据被压入栈底,最 ...

  10. Putty连接虚拟机Centos出现:Network error:Connection refused的解决方法

    转自:http://www.bcoder.cn/17251.html 我和很多人一样都是linux菜鸟,但是呢又对此很是感兴趣,不折腾就是不爽: 我下载了centos 6.4安装好在VMware 虚拟 ...