{"id":436,"date":"2012-02-24T04:40:00","date_gmt":"2012-02-24T04:40:00","guid":{"rendered":"http:\/\/www.houquner.com\/?p=1881"},"modified":"2012-02-24T04:40:00","modified_gmt":"2012-02-24T04:40:00","slug":"%e9%85%8d%e7%bd%aesyslog-ng","status":"publish","type":"post","link":"https:\/\/www.houquner.com\/index.php\/archives\/436","title":{"rendered":"\u914d\u7f6esyslog-ng"},"content":{"rendered":"<p>\u6709\u53f0\u670d\u52a1\u5668\u8981\u9000\u5f79,\u9700\u8981\u8fc1\u79fb\u670d\u52a1\u4e86,\u6070\u597d\u73b0\u5728\u6709\u65b0\u7248\u672c\u7684syslog-ng,\u91cd\u65b0\u8bb0\u5f55\u4e00\u4e0b,\u8fc7\u7a0b\u5982\u4e0b<\/p>\n<ol>\n<li>\u5b89\u88c5syslog-ng<\/li>\n<\/ol>\n<p><a href=\"http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3.3.4\/source\">http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3.3.4\/source<\/a><br \/>\nwget -c &quot;<a href=\"http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3.3.4\/source\/eventlog_0.2.12.tar.gz&amp;quot\">http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3.3.4\/source\/eventlog_0.2.12.tar.gz&amp;quot<\/a>;<br \/>\ntar xzvf eventlog_0.2.12.tar.gz<br \/>\n    cd eventlog-0.2.12<br \/>\n    .\/configure<br \/>\n    make &amp;&amp; make install<br \/>\n    cd ..<br \/>\n&nbsp;<br \/>\nwget -c &quot;<a href=\"http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3.3.4\/source\/syslog-ng_3.3.4.tar.gz&amp;quot\">http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3.3.4\/source\/syslog-ng_3.3.4.tar.gz&amp;quot<\/a>;<br \/>\ntar xzvf syslog-ng_3.3.4.tar.gz<br \/>\n    cd syslog-ng-3.3.4<br \/>\n    export PKG_CONFIG_PATH=\/usr\/local\/lib\/pkgconfig<br \/>\n    .\/configure<br \/>\n    make &amp;&amp; make install<br \/>\n    cd ..<br \/>\n&nbsp;<\/p>\n<ol>\n<li>\u914d\u7f6emysql<\/li>\n<\/ol>\n<p>CREATE DATABASE syslog;<br \/>\n    USE syslog;<br \/>\nDROP TABLE IF EXISTS <code>logs<\/code>;<br \/>\n    CREATE TABLE <code>logs<\/code> (<br \/>\n    &nbsp; <code>id<\/code> bigint(20) unsigned NOT NULL auto_increment,<br \/>\n    &nbsp; <code>host<\/code> varchar(128) default NULL,<br \/>\n    &nbsp; <code>facility<\/code> varchar(10) default NULL,<br \/>\n    &nbsp; <code>priority<\/code> varchar(10) default NULL,<br \/>\n    &nbsp; <code>level<\/code> varchar(10) default NULL,<br \/>\n    &nbsp; <code>tag<\/code> varchar(10) default NULL,<br \/>\n    &nbsp; <code>datetime<\/code> datetime default NULL,<br \/>\n    &nbsp; <code>program<\/code> varchar(15) default NULL,<br \/>\n    &nbsp; <code>msg<\/code> text,<br \/>\n    &nbsp; <code>seq<\/code> bigint(20) unsigned NOT NULL default &#39;0&#39;,<br \/>\n    &nbsp; <code>counter<\/code> int(11) NOT NULL default &#39;1&#39;,<br \/>\n    &nbsp; <code>fo<\/code> datetime default NULL,<br \/>\n    &nbsp; <code>lo<\/code> datetime default NULL,<br \/>\n    &nbsp; PRIMARY KEY&nbsp; (<code>id<\/code>),<br \/>\n    &nbsp; KEY <code>datetime<\/code> (<code>datetime<\/code>),<br \/>\n    &nbsp; KEY <code>sequence<\/code> (<code>seq<\/code>),<br \/>\n    &nbsp; KEY <code>priority<\/code> (<code>priority<\/code>),<br \/>\n    &nbsp; KEY <code>facility<\/code> (<code>facility<\/code>),<br \/>\n    &nbsp; KEY <code>program<\/code> (<code>program<\/code>),<br \/>\n    &nbsp; KEY <code>host<\/code> (<code>host<\/code>)<br \/>\n    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br \/>\n&nbsp;<\/p>\n<ol>\n<li>\n<p>sqlsyslogd\u811a\u672c,\u5177\u4f53\u4f5c\u7528\u5982\u4e0b<br \/>\ncat \/etc\/init.d\/sqlsyslogd<\/p>\n<h1>!\/bin\/bash<\/h1>\n<h1> <\/h1>\n<h1>sqlsyslogd This is a daemon that takes syslog-ng input and pipe it into&nbsp; a MySQL database.<\/h1>\n<h1>chkconfig: 2345 98 10<\/h1>\n<h1>description: sqlsyslogd bridges syslog-ng and mysql.<\/h1>\n<h1>author: Josh Kuo Thu 2004\/08\/12 13:21:56 PDT<\/h1>\n<p>. \/etc\/rc.d\/init.d\/functions<\/p>\n<p>case &quot;$1&quot; in<br \/>\nstart)<br \/>\nif [ -x \/tmp\/mysql.pipe ]; then<br \/>\nmkfifo \/tmp\/mysql.pipe<br \/>\nelse<\/p>\n<h1>if the service is already running, do not start another one<\/h1>\n<p>PIDS=<code>pidofproc mysql<\/code><br \/>\nif [ &quot;$PIDS&quot; ]; then<br \/>\necho &quot;sqlsyslogd is already running.&quot;<br \/>\nexit 1<br \/>\nfi<br \/>\nmysql -u root syslog &lt; \/tmp\/mysql.pipe &amp;<\/p>\n<p>fi<br \/>\n;;<br \/>\nstop )<br \/>\nkillproc mysql<\/p>\n<h1>If you need to collect apache logs into mysql, uncomment the next line.<\/h1>\n<h1>killproc tail<\/h1>\n<p>;;<\/p>\n<p>*)<br \/>\necho &quot;Usage: sqlsyslogd {start|stop}&quot;<br \/>\nexit 1;<br \/>\nesac<br \/>\nexit 0;<br \/>\n&nbsp;<br \/>\n4.syslog-ng.conf \u914d\u7f6e\u6587\u4ef6<\/p>\n<\/li>\n<\/ol>\n<p>cat &nbsp; \/usr\/local\/etc\/syslog-ng.conf<br \/>\n#<br \/>\n    #############################################################################<br \/>\n    # Default syslog-ng.conf file which collects all local logs into a<br \/>\n    # single file called \/var\/log\/messages.<br \/>\n    #<\/p>\n<pre><code>@version: 3.3\n@include &amp;quot;scl.conf&amp;quot;\n\noptions\n{\nchain_hostnames(no);\ncreate_dirs (no);\ndir_perm(0755);\ndns_cache(no);\nkeep_hostname(yes);\nlog_fifo_size(2048);\nlog_msg_size(8192);\nperm(0644);\nstats_freq(3600);\nflush_lines(0);\ntime_reopen (10);\nuse_dns(no);\nuse_fqdn(yes);\n};\n\n#----------------------------------------------------------------------\n# Sources&amp;nbsp; For Linux\n#----------------------------------------------------------------------\nsource s_stream\n{ unix-stream(&amp;quot;\/dev\/log&amp;quot;); };\n\nsource s_internal\n{ internal(); };\n\nsource s_remote {\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; udp(ip(0.0.0.0) port(514));\n};\nsource s_kmsg { file(&amp;quot;\/proc\/kmsg&amp;quot;); };\n\n#----------------------------------------------------------------------\n# Piping method\n#----------------------------------------------------------------------\n\n\ndestination d_mysql {\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pipe(&amp;quot;\/tmp\/mysql.pipe&amp;quot;\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; template(&amp;quot;INSERT INTO logs\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (host, facility, priority, level, tag, datetime, program, msg)\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES ( &amp;#39;$HOST&amp;#39;, &amp;#39;$FACILITY&amp;#39;, &amp;#39;$PRIORITY&amp;#39;, &amp;#39;$LEVEL&amp;#39;, &amp;#39;$TAG&amp;#39;, &amp;#39;$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC&amp;#39;,&amp;#39;$PROGRAM&amp;#39;, &amp;#39;$MSG&amp;#39; );n&amp;quot;) template-escape(yes));\n};\n\n#----------------------------------------------------------------------\n# Logging to a database\n#----------------------------------------------------------------------\n\nlog { source(s_kmsg); source(s_stream);source(s_internal);&amp;nbsp; source(s_remote); destination(d_mysql); };\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<ol>\n<li>\n<p>syslog-ng\u7684\u53c2\u8003\u6587\u6863<\/p>\n<\/li>\n<li>\n<p>official syslog-ng website<br \/>\n&nbsp;&nbsp; <a href=\"http:\/\/www.balabit.com\/network-security\/syslog-ng\/\">http:\/\/www.balabit.com\/network-security\/syslog-ng\/<\/a><\/p>\n<ol>\n<li>\n<p>The syslog-ng Administrator Guide<br \/>\n&nbsp;&nbsp; <a href=\"http:\/\/www.balabit.com\/support\/documentation\/\">http:\/\/www.balabit.com\/support\/documentation\/<\/a><\/p>\n<\/li>\n<li>\n<p>syslog-ng mailing list<br \/>\n&nbsp;&nbsp; <a href=\"https:\/\/lists.balabit.hu\/mailman\/listinfo\/syslog-ng\">https:\/\/lists.balabit.hu\/mailman\/listinfo\/syslog-ng<\/a><\/p>\n<\/li>\n<li>\n<p>BalaBit Documentation Blog<br \/>\n&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/robert.blogs.balabit.com\">http:\/\/robert.blogs.balabit.com<\/a><\/p>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<\/li>\n<\/ol>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.houquner.com\">Kermit\u7684\u7f51\u7ad9<\/a> &raquo; <a href=\"https:\/\/www.houquner.com\/index.php\/archives\/436\">\u914d\u7f6esyslog-ng<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u6709\u53f0\u670d\u52a1\u5668\u8981\u9000\u5f79,\u9700\u8981\u8fc1\u79fb\u670d\u52a1\u4e86,\u6070\u597d\u73b0\u5728\u6709\u65b0\u7248\u672c\u7684syslog-ng,\u91cd\u65b0\u8bb0\u5f55\u4e00\u4e0b,\u8fc7\u7a0b\u5982\u4e0b \u5b89\u88c5syslog-ng http:\/\/www.balabit.com\/downloads\/files?path=\/syslog-ng\/sources\/3. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-436","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/posts\/436"}],"collection":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/comments?post=436"}],"version-history":[{"count":0,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/posts\/436\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/media?parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/categories?post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/tags?post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}