Rsyslog远程传输的几种方式

基本介绍

Rsyslog是一个syslogd的多线程增强版,rsyslog vs. syslog-ng 链接是rsyslog官方和syslog特性和性能上的一些对比,目前大部分Linux发行版本默认也是使用rsyslog记录日志。这里介绍rsyslog远程传输的几种方式,对远程日志传输可以有一个了解。

rsyslog提供三个远程日志传输方式:

  • UDP: 数据包传输可信度不高
  • TCP: 数据包传输可信度比较高
  • RELP: 数据包传输可信度最高,避免数据丢失,比较新的协议,目前应用较少

以下为man手册对RELP协议的一个介绍:

RELP can be used instead of UDP or plain TCP syslog to provide reliable delivery of syslog messages. Please note that plain TCP syslog does NOT provide truly reliable delivery, with it messages may be lost when there is a connection problem or the server shuts down. RELP prevents message loss in hose cases.

关于RELP的更进一步了解可以参考 Using TLS with RELP RELP Input Module RELP Output Module (omrelp)

相关配置

To forward messages to another host via UDP, prepend the hostname with the at sign (“@”). To forward it via plain tcp, prepend two at signs (“@@”). To forward via RELP, prepend the string “:omrelp:” in front of the hostname.

UDP传输

Server端配置

/etc/rsyslog.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
$AllowedSender UDP, 192.168.80.0/24
# This one is the template to generate the log filename dynamically, depending on the client's IP address.
# 根据客户端的IP单独存放主机日志在不同目录,syslog需要手动创建
$template Remote,"/var/log/syslog/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log"
# Log all messages to the dynamically formed file.
:fromhost-ip, !isequal, "127.0.0.1" ?Remote
# 排除本地主机IP日志记录,只记录远程主机日志
# 注意此规则需要在其它规则之前,否则配置没有意义,远程主机的日志也会记录到Server的日志文件中
& ~ # 忽略之前所有的日志,远程主机日志记录完之后不再继续往下记录

或者把以上配置单独存放在/etc/rsyslog.d/中的xxx.conf配置文件中,尽量避免修改主配置文件,当然如果要独立文件主配置文件中必须含有以下配置

1
2
3
# grep 'rsyslog.d' /etc/rsyslog.conf
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
Client端配置

/etc/rsyslog.conf

1
*.*                     @192.168.80.130

以上配置完成之后/etc/init.d/rsyslog restart

TCP传输

TCP配置和UDP类似,如下

Server端配置

/etc/rsyslog.conf

1
2
3
4
5
6
7
8
9
10
11
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
$AllowedSender TCP, 192.168.80.0/24
# This one is the template to generate the log filename dynamically, depending on the client's IP address.
$template Remote,"/var/log/syslog/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log"
# Log all messages to the dynamically formed file.
:fromhost-ip, !isequal, "127.0.0.1" ?Remote
& ~
Client端配置

/etc/rsyslog.conf

1
*.*                     @@192.168.80.130

客户端和服务端重启相关服务即可

关于TCP和UDP的传输方式,rsyslog官方推荐使用TCP传输方式

In general, we suggest to use TCP syslog. It is way more reliable than UDP syslog and still pretty fast. The main reason is, that UDP might suffer of message loss. This happens when the syslog server must receive large bursts of messages. If the system buffer for UDP is full, all other messages will be dropped. With TCP, this will not happen. But sometimes it might be good to have a UDP server configured as well. That is, because some devices (like routers) are not able to send TCP syslog by design. In that case, you would need both syslog server types to have everything covered. If you need both syslog server types configured, please make sure they run on proper ports. By default UDP syslog is received on port 514. TCP syslog needs a different port because often the RPC service is using this port as well.

RELP传输

RELP需要安装rsyslog-relp相应模块

1
# yum install rsyslog-relp -y
Server端配置

/etc/rsyslog.conf

1
2
3
4
5
6
7
8
$ModLoad imrelp # 加载相应模块
$InputRELPServerRun 20514 # 监听端口
# This one is the template to generate the log filename dynamically, depending on the client's IP address.
$template Remote,"/var/log/syslog/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log"
# Log all messages to the dynamically formed file.
:fromhost-ip, !isequal, "127.0.0.1" ?Remote
Client端配置

/etc/rsyslog.conf

1
2
3
4
5
$ActionQueueType LinkedList     # use asynchronous processing
$ActionQueueFileName srvrfwd # set file name, also enables disk mode
$ActionResumeRetryCount -1 # infinite retries on insert failure
$ActionQueueSaveOnShutdown on # save in-memory data if rsyslog shuts down
*.* :omrelp:192.168.80.130:20514

客户端和服务端重启相关服务即可

参考和拓展资料

–EOF–

rsyslog传输type的更多相关文章

  1. rsyslog 传输mysql 日志

    在另外一种环境中,让我们假定你已经在机器上安装了一个名为"foobar"的应用程序,它会在/var/log下生成foobar.log日志文件.现在,你想要将它的日志定向到rsysl ...

  2. rsyslog 传输日志

    nginx 服务器: front-end:/usr/local/nginx/logs# cat /etc/rsyslog.conf | grep -v "^$" | grep -v ...

  3. <二>ELK-6.5.3学习笔记–使用rsyslog传输管理nginx日志

    http://www.eryajf.net/2362.html 转载于 本文预计阅读时间 28 分钟 文章目录[隐藏] 1,nginx日志json化. 2,发送端配置. 3,接收端配置. 4,配置lo ...

  4. rsyslog传输指定目录下的全部日志数据

    准备: 两台Linux电脑 server(A):10.1.75.177 client(B):10.1.75.229 目的: 将B上的/usr/local/record目录下的所有日志数据传输到A的/v ...

  5. Rsyslog日志服务搭建

    rsyslog是比syslog功能更强大的日志记录系统,可以将日志输出到文件,数据库和其它程序.Centos 6.x默认的rsyslog版本是5.x. 网上关于rsyslog的安装配置文档倒是不少,但 ...

  6. 003-centos7:rsyslog简单配置客户端和服务器端

    实现把一个主机作为客户端,把日志发送到指定的服务器端: [服务器端] 开放tcp端口,udp端口: vim /etc/rsyslog.conf: # Provides UDP syslog recep ...

  7. 日志收集之rsyslog to kafka

    项目需要将日志收集起来做存储分析,数据的流向为rsyslog(收集) -> kafka(消息队列) -> logstash(清理) -> es.hdfs: 今天我们先将如何利用rsy ...

  8. 用ElasticSearch存储日志

    介绍 如果你使用elasticsearch来存储你的日志,本文给你提供一些做法和建议. 如果你想从多台主机向elasticsearch汇集日志,你有以下多种选择: Graylog2 安装在一台中心机上 ...

  9. jsignature 中文开发手册

    2017年5月9日21:23:17,最近比较忙,没时间写博客,真的是越来越懒来了 github:https://github.com/brinley/jSignature http://www.unb ...

随机推荐

  1. 设计模式 - 代理模式(Proxy Pattern)

    一.引言 在软件开发过程中,有些对象有时候会由于网络或其他的障碍,以至于不能够或者不能直接访问到这些对象,如果直接访问对象给系统带来不必要的复杂性,这时候可以在客户端和目标对象之间增加一层中间层,让代 ...

  2. allow-hotplug eth0 allow-hotplug error

    /********************************************************************* * allow-hotplug eth0 error * ...

  3. storyboard出口回退问题

    问题 直接在Main.storyboard拖动添加到出口的时候总是出一些不知名的错误.猜想可能是swift4又TM换了新特性(不过好喜欢啊哈哈哈哈) 解决 其实可以先拖动添加@IBAction函数到代 ...

  4. windows中查看端口被什么应用程序占用并删除

    windows中查看端口的命令是netstat,具体用法如下: 查看端口信息时可以使用如下命令: netstat -ano 运行结果如下: 当前我的本地13067端口被占用,使用命令如下: c:\&g ...

  5. 《selenium2 python 自动化测试实战》(4)——鼠标事件

    鼠标事件包含在ActionChains类中,导入时只需要: from selenium.webdriver.common.action_chains import ActionChains 导入类即可 ...

  6. 【java基础】java集合系列之HashMap

    Hashmap是一种非常常用的.应用广泛的数据类型,最近研究到相关的内容,就正好复习一下.网上关于hashmap的文章很多,但到底是自己学习的总结,就发出来跟大家一起分享,一起讨论. 1.hashma ...

  7. .ncx文件剖析

    ncx文件是epub电子书的又一个核心文件,用于制作电子书的目录,其文件的命名通常为toc.ncx. ncx文件是一个XML文件,该标准由DAISY Consortium发布(参见http://www ...

  8. Python猴子补丁

    属性在运行时的动态替换,叫做猴子补丁(Monkey Patch). 为什么叫猴子补丁 属性的运行时替换和猴子也没什么关系,关于猴子补丁的由来网上查到两种说法: 1,这个词原来为Guerrilla Pa ...

  9. Unite 2018 | 《崩坏3》:在Unity中实现高品质的卡通渲染(上)

    http://forum.china.unity3d.com/thread-32271-1-1.html 我们已经发布了Unite 2018 江毅冰的<发条乐师>.Hit-Point的&l ...

  10. Eclipse导入工程后,XDoclet错误:Missing library: xdoclet-1.2.1.jar. Select the home directory for XDoclet

    这几天在使用Open Health Tools的OpenXDS工程,在导入Eclipse后,出现下面的错误: 遂google之,在网上找到了答案.答案网址为http://blog.v-s-f.co.u ...