zoukankan      html  css  js  c++  java
  • 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中查看发送的日志。

  • 相关阅读:
    查找1
    动态规划
    分治
    [LeetCode] 1339. Maximum Product of Splitted Binary Tree
    [LeetCode] 1509. Minimum Difference Between Largest and Smallest Value in Three Moves
    [LeetCode] 233. Number of Digit One
    [LeetCode] 1963. Minimum Number of Swaps to Make the String Balanced
    [LeetCode] 1053. Previous Permutation With One Swap
    [LeetCode] 1962. Remove Stones to Minimize the Total
    [LeetCode] 1961. Check If String Is a Prefix of Array
  • 原文地址:https://www.cnblogs.com/jjp816/p/8930274.html
Copyright © 2011-2022 走看看