Centos7 配置rsyslog客户端接收远程日志

   2023-02-09 学习力0
核心提示:rsyslog因为路由器我设定每天重启,但是日志一重启就会清除,并且路由器最多只能保存1024条记录,所以我想把路由器的日志记录到一台服务器上,发现路由器包含远程日志功能于是我就在我的centos7服务器配置了下rsyslog,把日志记录到这里编辑服务端的/etc/rsys

因为路由器我设定每天重启,但是日志一重启就会清除,并且路由器最多只能保存1024条记录,所以我想把路由器的日志记录到一台服务器上,发现路由器包含远程日志功能

Centos7 配置rsyslog客户端接收远程日志

于是我就在我的centos7服务器配置了下rsyslog,把日志记录到这里

编辑服务端/etc/rsyslog.conf文件
注意下中文注释地方

# rsyslog configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception
$ModLoad imudp  # 引用udp协议的模块
$UDPServerRun 514  # 设置udp协议使用端口

# Provides TCP syslog reception
$ModLoad imtcp  # 引用tcp协议的模块
$InputTCPServerRun 514  # 设置tcp协议使用端口


#### GLOBAL DIRECTIVES ####

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

$template Remote,"/var/log/%$YEAR%-%$MONTH%-%$DAY%/%fromhost-ip%.log" # 设置远程日志存放路径和文件格式
:fromhost-ip, !isequal, "127.0.0.1" ?Remote  # 如果是本机日志则不记录

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state


#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
# 关于内核的所有日志都放到/dev/console(控制台)
#kern.*                                                 /dev/console  

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
# 记录所有日志类型的info级别以及大于info级别的信息到/var/log/messages,但是mail邮件信息,authpriv验证方面的信息和cron时间任务相关的信息除外
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
# authpriv验证相关的所有信息存放在/var/log/secure
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
# 邮件的所有信息存放在/var/log/maillog; 这里有一个-符号, 表示是使用异步的方式记录, 因为日志一般会比较大
mail.*                                                  -/var/log/maillog


# Log cron stuff
# 计划任务有关的信息存放在/var/log/cron
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
# 启动的相关信息
*.emerg                                                 :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log


# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList   # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###

然后重启rsyslog

systemctl restart rsyslog

客户端直接填写ip,端口默认是514,就完成了

 
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • 用Xshell设置CentOS密钥登录
    用Xshell设置CentOS密钥登录
    今天带来设置X shell 密钥登录  因为用的中文x shell 所以按照中文设置很简单1.点击工具(Tools)------新建用户密钥生成向导(New User key Wizard)(附图)2.然后出现下图时,记得密钥类型 选择RSA.其实选择DSA ,也能实现,二者其实是不同的算法。(我用的R
    03-08
  • centOS下安装Adobe Flash Player
    centOS下安装Adobe Flash Player
    centOS下安装Adobe Flash Player  2009-10-09 11:29:33|  分类:linux|  标签: |订阅 写出来就这么简单几步,当初刚接触Linux的时候搜索了很长时间,找了很多资料,总是出现这样那样的问题,最后终于摸索出最简单最有效的安装的方法。 随便打开一个带
    03-08
  • 部署Node.js项目(CentOS) node项目搭建
    部署Node.js项目(CentOS) node项目搭建
    操作步骤步骤 1:创建ECS实例选择操作系统为公共镜像CentOS7.2。使用root用户登录Linux实例。步骤2:部署Node.js环境—二进制文件安装该部署过程使用的安装包是已编译好的二进制文件,解压之后,在bin文件夹中就已存在node和npm,无需手工编译。安装步骤:1、
    02-10
  • centos安装python与jdk centos安装python3.7
    centos安装python与jdk centos安装python3.7
    安装python#压缩包安装[root@china ~]# yum -y install zlib*Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun
    02-10
  • centos6下同时安装python2和python3
    #build-essential compile packagesyum groupinstall "Development Tools"yum install openssl-develyum install zlib-develyum install make gcc gcc-c++ kernel-develhttp://unix.stackexchange.com/questions/291737/zipimport-zipimporterror-cant-decomp
    02-10
  • CentOS下查看文件和文件夹大小 linux查看文件夹
    当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择。  df可以查看一级文件夹大小、使用比例、档案系统及其挂入点,但对文件却无能为力。当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择。  df可以查
    02-10
  • centos7 离线升级/在线升级操作系统内核
    centos7 离线升级/在线升级操作系统内核
    centos7 离线升级/在线升级操作系统内核目录一.前言二.系统环境三.系统内核下载网址四.centos7离线升级系统内核1.先查看系统环境2.离线升级系统内核五.在线升级系统内核一.前言CentOS(Community ENTerprise Operating System)是Linux发行版之一,它是来自于
    02-10
  • centos7 rc.local脚本执行不成功
    腾讯云 centos7   配置文件/etc/rc.local的内容如下:#!/bin/sh#secu_agent init monitor, install at Thu Aug 3 11:19:41 CST 2017/usr/local/sa/agent/init_check.sh/dev/null 21/usr/sbin/ntpdate ntpupdate.tencentyun.com /dev/null 21 /usr/local/qclo
    02-10
  • 如何在centos7启动时自动挂载硬盘
    在/etc/rc.local中加入如下的语句,这样就不用每次重启后手动挂载了(后面挂载的目录根据自己的需求而定):mount  /dev/sdb1 /usr/sharedfiles/sdbmount  /dev/sdc1 /usr/sharedfiles/sdcmount  /dev/sdb1 /root/sdbmount  /dev/sdc1 /root/sdc注意:可以
    02-10
  • centos7.2 开启防火墙
    开启防火墙当我们修改了某些配置之后(尤其是配置文件的修改),firewall并不会立即生效。可以通过两种方式来激活最新配置 systemctl restart firewalld 和 firewall-cmd --reload 两种方式,前一种是重启firewalld服务,建议使用后一种“重载配置文件”
    02-10
点击排行