我的博客已迁移到xdoujiang.com请去那边和我交流 一、基础环境说明 rsyslog是enhanced multi-threaded syslogd rsyslog是syslogd的多线程增强版 facility(类型) auth authpriv cron kern lpr mail mark news user uucp local0~local7 log level(日志等级) debug -Kernel debugging messages, output by the kernel if the developer enabled debugging at compile time. info -Informational messages that require no action. notice -Normal, but significant events. warning -Warning conditions that should be taken care of. err -Noncritical error conditions. crit -Critical conditions. alert -Actions that must be taken care of immediately. emerg -The system is unusable. om代表输出模块(Output Modules) omelasticsearch omfile omfwd omhdfs omkafka omlibdbi ommail ommongodb ommysql omoracle omprog omrelp omruleset omsnmp omstdout omudpspoof omuxsock im代表输入模块(input Modules) im3195 imfile imgssapi imjournal imklog imkmsg impstats imptcp imrelp imsolar isimtcp imudp imuxsock serverA=debian7.8是10.1.10.117(服务端) dpkg -l |grep rsyslog ii rsyslog 5.8.11-3+deb7u2 amd64 reliable system and kernel logging daemon serverB=debian5.0.1是10.1.10.250(客户端) dpkg -l |grep rsyslog ii rsyslog 3.18.6-4 enhanced multi-threaded syslogd 二、安装 1、先查询下包 apt-cache search rsyslog rsyslog - enhanced multi-threaded syslogd 2、安装 apt-get -y install rsyslog 三、配置 1、客户端 serverB 传送自定义目录下文件(/opt/scripts/pidfile) 使用imfile模块 cat /etc/rsyslog.d/a.conf $ModLoad imfile $InputFileName /opt/scripts/pidfile $InputFileTag $InputFileFacility local5 $InputFileSeverity info $InputFileStateFile ssologs.log_state $InputFilePollInterval 1 $InputFilePersistStateInterval 1 $InputRunFileMonitor local5.info @10.1.10.117:8888 2、服务端 serverA 将/etc/default/rsyslog下的RSYSLOGD_OPTIONS="-c3"修改为RSYSLOGD_OPTIONS="-c 5 -Q -x" 参数说明 -Q do not resolve hostnames during ACL processing Do not resolve hostnames to IP addresses during ACL processing. -x Disable DNS for remote messages. -c compatibility mode -m 0 disables 'MARK' messages (deprecated, only used in compat mode < 3) -r enables logging from remote machines (deprecated, only used in compat mode < 3) 接收来自单个IP的日志(/opt/rsyslog/10.1.10.250.log自定义接收的地方) cat /etc/rsyslog.d/b.conf $ModLoad imudp $UDPServerRun 8888 :fromhost,isequal,"10.1.10.250" /opt/rsyslog/10.1.10.250.log & ~ 接收来自单网段IP的日志 cat /etc/rsyslog.d/b.conf $ModLoad imudp $UDPServerRun 8888 $template DynFile,"/opt/rsyslog/%fromhost-ip%.log" if $fromhost-ip startswith '10.1.' then ?DynFile & ~ 3、serverA和serverB都需要重启下 /etc/init.d/rsyslog restart =====================参数说明==================== & ~表示了一个重定向规则,被用来告知rsyslog守护进程停止对日志消息的进一步处理, 并且不要在本地写入。如果没有使用该重定向规则,那么所有的远程消息都会在写入 上述描述的日志文件之外同时被写入到本地日志文件,这就意味着日志消息实际上被写了两次。 使用该规则的另外一个结果就是syslog服务器本身的日志消息只会被以该机器主机名 命名的专有文件中。 四、测试 在serverB上执行logger -p local5.info 111 -p pri Enter the message with the specified priority. 在serverA的tail -f /opt/rsyslog/10.1.10.250.log 就能看到有信息传过来了。 五、参考文章 http://www.rsyslog.com/doc/ http://www.cnblogs.com/blueswu/p/3564763.html?utm_source=tuicool
六、相关图片