syslog-ng安装和使用

17 篇文章 0 订阅

概述

syslog-ng常用于接收交换机、LINUX SERVER等程序发出的log信息。

安装

yum install syslog-ng
本文安装的是syslog-ng-3.0.5

配置

/etc/syslog-ng/syslog-ng.conf
// 在最后加上:
#aliswich syslog
#定义一个source,表示哪里是log的源,下面的为不限IP,接收 514 端口报文。
source s_remote {
             tcp(ip( 0.0 . 0.0 ) port( 514 ));
             udp(ip( 0.0 . 0.0 ) port( 514 ));
};
 
# 定义一个存放log的目的位置
destination d_networkdevice { file( "/var/log/test_syslog.log" owner( "root" ) group( "root" ) perm( 0640 ) dir_perm( 0750 ) create_dirs(yes)); };
# 多个设备指定同一个server时,日志最好按IP分开存放。
destination d_separatedbyhosts {
        file( "/var/log/syslog-ng/$HOST/$MONTH$DAY.log" owner( "root" ) group( "root" ) perm( 0640 ) dir_perm( 0750 ) create_dirs(yes));};
 
# 也可以定义显示的内容
  destination d_separatedbyhosts {
        file( "/var/log/syslog-ng/$HOST/$MONTH$DAY.log" template("$FACILITY $LEVEL $PRIORITY $DATE $HOST $PROGRAM $MSGHDR$M
SG\n ") owner(" root ") group(" root") perm( 0640 ) dir_perm( 0750 ) create_dirs(yes));
};
#一个log存储规则的定义,还可以定义filter
log { source(s_remote); destination(d_networkdevice); };

重启syslog-ng

service syslog-ng restart

附录

变量名

#
#    Name               Description
#    ----------------  ----------------------------------------------
#    DATE               Date of the transaction.
#    DAY                The day of month the message was sent.
#    FACILITY           The name of the facility, the message is tagged 
#                       as coming from.
#    FULLDATE           Long form of the date of the transaction.
#    FULLHOST           Full hostname of the system that sent the log.
#    HOST               The name of the source host where the message 
#                       is originated from. If the message traverses 
#                       several hosts, and chain_hostnames() is on, 
#                       the first one is used.
#    HOUR               The hour of day the message was sent.
#    ISODATE            Date in ISO format.
#    MIN                The minute the message was sent.
#    MONTH              The month the message was sent.
#    MSG or MESSAGE     Message contents. 
#    PRIORITY or LEVEL  The priority of the message. 
#    PROGRAM            The name of the program the message was sent by.
#    SEC                The second the message was sent.
#    TAG                The priority and facility encoded as a 2 digit 
#                       hexadecimal number.
#    TZ                  The time zone or name or abbreviation. e.g. 'PDT'
#    TZOFFSET           The time-zone as hour offset from GMT. e.g. 
#                       '-0700'
#    WEEKDAY            The 3-letter name of the day of week the 
#                       message was sent, e.g. 'Thu'.
#    YEAR               The year the message was sent. Time expansion 
#                       macros can either use the time specified in 
#                       the log message, e.g. the time the log message 
#                       is sent, or the time the message was received 
#                       by the log server. This is controlled by the 
#                       use_time_recvd() option.#
#    Name               Description
#    ----------------  ----------------------------------------------
#    DATE               Date of the transaction.
#    DAY                The day of month the message was sent.
#    FACILITY           The name of the facility, the message is tagged 
#                       as coming from.
#    FULLDATE           Long form of the date of the transaction.
#    FULLHOST           Full hostname of the system that sent the log.
#    HOST               The name of the source host where the message 
#                       is originated from. If the message traverses 
#                       several hosts, and chain_hostnames() is on, 
#                       the first one is used.
#    HOUR               The hour of day the message was sent.
#    ISODATE            Date in ISO format.
#    MIN                The minute the message was sent.
#    MONTH              The month the message was sent.
#    MSG or MESSAGE     Message contents. 
#    PRIORITY or LEVEL  The priority of the message. 
#    PROGRAM            The name of the program the message was sent by.
#    SEC                The second the message was sent.
#    TAG                The priority and facility encoded as a 2 digit 
#                       hexadecimal number.
#    TZ                  The time zone or name or abbreviation. e.g. 'PDT'
#    TZOFFSET           The time-zone as hour offset from GMT. e.g. 
#                       '-0700'
#    WEEKDAY            The 3-letter name of the day of week the 
#                       message was sent, e.g. 'Thu'.
#    YEAR               The year the message was sent. Time expansion 
#                       macros can either use the time specified in 
#                       the log message, e.g. the time the log message 
#                       is sent, or the time the message was received 
#                       by the log server. This is controlled by the 
#                       use_time_recvd() option.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值