现在的位置: 首页 > 综合 > 正文

syslog-ng搭建集中日志服务器

2013年10月25日 ⁄ 综合 ⁄ 共 3404字 ⁄ 字号 评论关闭
syslog-ng的强大功能在此呈现

首先切换到/etc目录
cd /etc

vi log.profile
  1. #日志存放路径
  2. PT=/var/log/ipwall/
  3. #客户端白名单(以逗号分割)
  4. IP=192.168.2.1,192.168.2.30
  5. #磁盘剩余空间大小(单位GB)
  6. SP=10
  7. #日志转储切割大小(单位MB)
  8. SZ=50

vi syslog-ng.example
  1. @version: 3.2
  2. #版本号具体数值参考 /etc/syslog-ng/syslog-ng.conf 文件第一行

  3. options { long_hostnames(off); flush_lines(0); use_dns(no); use_fqdn(no);
  4.           owner("root"); group("adm"); perm(0640); stats_freq(0);
  5.           bad_hostname("^gconfd$");
  6. };

  7. source s_net { udp(ip(0.0.0.0) port(514)); };

  8. destination d_session { file("__PATH__/$HOST/session/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  9. destination d_url { file("__PATH__/$HOST/url/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  10. destination d_qq { file("__PATH__/$HOST/QQ/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  11. destination d_msn { file("__PATH__/$HOST/msn/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  12. destination d_alipay { file("__PATH__/$HOST/alipay/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  13. destination d_dns { file("__PATH__/$HOST/dns/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  14. destination d_pop3 { file("__PATH__/$HOST/pop3/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };
  15. destination d_others { file("__PATH__/$HOST/others/messages.log" perm(0777) dir_perm(0777) create_dirs(yes)); };

  16. filter f_local3 { level(info) and facility(local3); };
  17. filter f_host { host("__IP__"); };
  18. filter f_session { level(info) and facility(local1) and filter(f_host); };
  19. filter f_url { level(info) and facility(local2) and filter(f_host); };
  20. filter f_qq { filter(f_local3) and message(^qq) and filter(f_host); };
  21. filter f_msn { filter(f_local3) and message(^msn) and filter(f_host); };
  22. filter f_alipay { filter(f_local3) and message(^alipay) and filter(f_host); };
  23. filter f_dns { filter(f_local3) and message(^dns) and filter(f_host); };
  24. filter f_pop3 { filter(f_local3) and message(^pop3) and filter(f_host); };
  25. filter f_others { not facility(local1, local2, local3) and filter(f_host); };

  26. log { source(s_net); filter(f_session); destination(d_session); };
  27. log { source(s_net); filter(f_url); destination(d_url); };
  28. log { source(s_net); filter(f_qq); destination(d_qq); };
  29. log { source(s_net); filter(f_msn); destination(d_msn); };
  30. log { source(s_net); filter(f_alipay); destination(d_alipay); };
  31. log { source(s_net); filter(f_dns); destination(d_dns); };
  32. log { source(s_net); filter(f_pop3); destination(d_pop3); };
  33. log { source(s_net); filter(f_others); destination(d_others); };

vi logrotate.example
  1. __PATH__/__IP__/session/messages.log {
  2.         missingok
  3.         rotate 65535
  4.         create 0777 syslog adm
  5.         compress
  6.         size __SZ__M
  7.         dateext
  8.         dateformat .%s
  9.         postrotate
  10.         /bin/kill -HUP
    $(/bin/cat /var/run/syslog-ng.pid
    2>/dev/null) &>/dev/null
  11.         endscript
  12. }

  13. __PATH__/__IP__/url/messages.log {
  14.         missingok
  15.         rotate 65535
  16.         create 0777 syslog adm
  17.         compress
  18.         size __SZ__M
  19.         dateext
  20.         dateformat .%s
  21.         postrotate
  22.         /bin/kill -HUP
    $(/bin/cat /var/run/syslog-ng.pid
    2>/dev/null) &>/dev/null
  23.         endscript
  24. }

  25. __PATH__/__IP__/QQ/messages.log {
  26.         missingok
  27.         rotate 65535
  28.         create 0777 syslog adm
  29.         compress
  30.         size __SZ__M
  31.         dateext
  32.         dateformat .%s
  33.         postrotate
  34.         /bin/kill -HUP
    $(/bin/cat /var/run/syslog-ng.pid
    2>/dev/null) &>/dev/null
  35.         endscript
  36. }

  37. __PATH__/__IP__/msn/messages.log {
  38.         missingok
  39.         rotate 65535

抱歉!评论已关闭.