Rsyslog

客户端配置格式

客户端需修改文件位于/etc/rsyslog.conf

只需要把尾部#*.* @@remote-host:514删除#,并把@@替换为@,remote-host替换为日志服务器主机IP即可;

 

注:日志默认使用udp协议,使用@@则使用tcp协议。

服务器配置格式

服务器端修改修改/etc/rsyslog.conf文件以及/etc/sysconfig/rsyslog文件。

1、/etc/rsyslog.conf中需有

#Provides UDPsyslog reception

$ModLoad imudp

$UDPServerRun514

以打开日志服务监听,输入netstat –lunp可见rsyslog监听于514端口(默认端口)

$ModLoad imtcp
 $InputTCPServerRun 514 

$template IpTemplate,"/var/log/%FROMHOST-IP%.log"
*.* ?IpTemplate
& ~

 

 

systemctl restart rsyslog

netstat -tulpn | grep rsyslog 

非 syslog 日志的转发

在另外一种环境中,让我们假定你已经在机器上安装了一个名为“foobar”的应用程序,它会在/var/log下生成foobar.log日志文件。现在,你想要将它的日志定向到rsyslog服务器,这可以通过像下面这样在rsyslog配置文件中加载imfile模块来实现。

首先,加载imfile模块,这只需做一次。

module(load="imfile" PollingInterval="5")

然后,指定日志文件的路径以便imfile模块可以检测到:

input(type="imfile"
File="/var/log/foobar.log"
Tag="foobar"
Severity="error"
Facility="local7")

最后,定向local7设备到远程rsyslog服务器:

local7.* @192.168.1.25:514

别忘了重启rsyslog进程哦!

 

 

 

2、/etc/sysconfig/rsyslog文件中,需修改

SYSLOGD_OPTIONS="-m240 -r"

其中-r表示接受外部日志的写入。

 

systemctlstop   rsyslog.service    关闭日志服务

systemctl start rsyslog.service     开启日志服务

systemctl enable rsyslog.service  开机自动启动

测试:

    使用logger命令发送日志进行测试,

    logger –p user.info “teststr”

发送日志到本机,本机会进行转发到日志服务器,在/var/log/messages中查看发送的日志。

 

posted @ 2018-04-24 14:36  jjp816  阅读(397)  评论(0编辑  收藏  举报