基本介绍

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远程传输的几种方式的更多相关文章

  1. 连接远程服务器的几种方式/Vscode + Remote

    连接远程服务器的几种方式 前言 最近在尝试做网盘,使用的技术栈大概是 .net core + MVC + Mysql + Layui,主要目的是通过这个具体的项目,熟悉熟悉 .net core 开发, ...

  2. 设备程序远程升级采用两种方式(优先采用IP方式)

    设备程序远程升级采用两种方式(优先采用IP方式): 采用应急广播TS流传输技术规范的消息内容表携带升级包数据.当辅助数据类型值为44时,消息内容表传输的数据为程序升级包. 采用IP方式传输升级包数据. ...

  3. Linux经常使用的文件传输的几种方式

    Linux经常使用的文件传输的几种方式 1.终端新建stfp协议连接 或者命令方式: sftp -P22 root@192.168.11.100 端口可以不用填写,默认是22,端口的P是大写. 将本地 ...

  4. Jenkins触发远程Job的几种方式

    本文叙述基于以下假设前提,将介绍三种在不同的jenkins服务器之间触发Job的方法: 本地Jenkins Server local.jenkins.com远程Jenkins Server remot ...

  5. Linux系统之文件传输的几种方式

    Linux系统安装好以后以及能上网.能进行软件安装后,接下来可能就需要从其它机器复制一些文件或者把文件复制到其它机器,那么就涉及到文件的传输和共享,下面介绍一下常规的一些文件传输和共享方案. 1.传统 ...

  6. LinkServer--访问远程数据表三种方式

    在TSQL中访问远程数据库有三种方式:1.OPENROWSET2.OPENDATASOURCE3.LinkServer 在使用openrowset/opendatasource前搜先要启用Ad Hoc ...

  7. Linux中crontab下scp文件传输的两种方式

    Linux下文件传输一般有两个命令scp.ftp(工具需要下载安装) 本文主要讲讲scp的文件传输脚本 1.scp ssh-keygen -t rsa免输入密码,传输 这里假设主机A 用来获到主机B的 ...

  8. git 拉取指定的远程分支(三种方式)

    直接拉取 git clone -b ants git@github.com:Ants-double/CareerJava.git git clone -b 远程分支名 仓库地址 本地已经有相关的仓库代 ...

  9. PHP获取远程文件的几种方式

    1.fopen() 2.file_get_contents() 3.fsocket() 4.curl()

随机推荐

  1. 查询出结果 给其 加上序号的方法 msql

    基本用法 SELECT @rownum := @rownum +1 AS rownum, e.*FROM (SELECT @rownum := 0) r , (select A.id,B.user_u ...

  2. jsp中遇到Integer的方法valueOf()和parseInt()的区别.前者要求是对象类型,后者是数字型字符串

    他们有本质区别,Integer.valueof(String s)是将一个包装类是将一个实际值为数字的变量先转成string型再将它转成Integer型的包装类对象(相当于转成了int的对象)这样转完 ...

  3. 学习笔记之SQL / MySQL

    SQL Fiddle(在线执行SQL语句的网站) http://www.sqlfiddle.com/ MySQL https://www.mysql.com/ MySQL :: MySQL 5.7 R ...

  4. spring RestTemplate用法详解

    spring RestTemplate用法详解 spring 3.2.3 框架参考有说明 21.9 Accessing RESTful services on the Client

  5. TNS:no listener error in Oracle XE after changing computer name

    This morning at work when trying to log on to my computer I noticed not my username on login screen ...

  6. TCP/IP知识总结(TCP/IP协议族读书笔记一)

    一.简述TCP/IP协议 Transmission Control Protocol/Internet Protocol的简写,即传输控制协议/互联网互联协议,又名网络通信协议.是Internet最基 ...

  7. 【319】Python 通过 Twilio 发短信

    参考:python利用twilio模块给自己发短信 参考:使用python实现往手机发短信(基于twilio) 步骤如下: 登录 Twilio 网站注册,貌似需要***,包括用户名.密码.手机号.项目 ...

  8. LevelDb日知录之五:MemTable详解

    [LevelDb日知录之五:MemTable详解] LevelDb日知录前述小节大致讲述了磁盘文件相关的重要静态结构,本小节讲述内存中的数据结构Memtable,Memtable在整个体系中的重要地位 ...

  9. Multithread之为什么spinlock必须是volatile?

    [Multithread之为什么spinlock必须是volatile?] 1.编译器的优化 在本次线程内,当读取一个变量时,为提高存取速度,编译器优化时有时会先把变量读取到一个寄存器中:以后再取变量 ...

  10. Hadoop Streaming:aggregate

    [Hadoop Streaming:aggregate] 1.实例1 测试文件test.txt mapper程序: 运行: $hadoop streaming -input /app/test.txt ...