LinuxC/C++编程基础(29) syslog-ng配置实例

1.options选项的配置

options {

    chain_hostnames(0);
    time_reopen(10);
    time_reap(360);
    log_fifo_size(2048);
    create_dirs(yes);
    group(adm);
    perm(0644);
    dir_perm(0755);
    use_dns(no);
    stats_freq(0);
    bad_hostname("^gconfd$");

};

2.消息源的配置,如下:

source sall {
# message generated by Syslog-NG
internal();
# standard Linux log source (this is the default place for the syslog()
# function to send logs to)
unix-stream("/dev/log");
# messages from the kernel
file("/proc/kmsg" log
prefix("kernel: ")); # use the following line if you want to receive remote UDP logging messages
# (this is equivalent to the "-r" syslogd flag)
# udp();
}

3.destinations的配置,如下:

destination dfauth { file("/var/log/auth.log"); };
destination df
syslog { file("/var/log/syslog"); };
destination dfcron { file("/var/log/cron.log"); };
destination df
daemon { file("/var/log/daemon.log"); };
destination dfkern { file("/var/log/kern.log"); };
destination df
lpr { file("/var/log/lpr.log"); };
destination dfmail { file("/var/log/mail.log"); };
destination df
user { file("/var/log/user.log"); };
destination dfuucp { file("/var/log/uucp.log"); };
destination df
167 { tcp("127.0.0.1" port(2345)); };

4.filters的配置,如下:

filter fcron { facility(cron); };
filter f
daemon { facility(daemon); };
filter fkern { facility(kern); };
filter f
lpr { facility(lpr); };
filter fmail { facility(mail); };
filter f
news { facility(news); };
filter fuser { facility(user); };
filter f
uucp { facility(uucp); };

5.模板的配置,如下:

template linyanwenfmt{template("$DATE $PRIORITY $MSG\n");templateescape(no);};

6.进程的匹配,如下:

filter f_linyanwen{program("_5$");};

7.日志输出位置的配置,如下:

destination dlinyanwen{file("data/yy/log/$PROGRAM/$PROGRAM.log" template(linyanwenfmt));};

8.完整的log指令,如下:

log{source(sall);filter(flinyanwen);destination(d_linyanwen);flags(final);};

9.运行结果,如下:



10.停止syslog-ng:/etc/init.d/service syslog-ng stop


转载请注明出处:山水间博客

http://blog.csdn.net/linyanwen99/article/details/8456054



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值