• rsyslog 系统日志收集上报(可增加自定义项目日志)


    Linux 自带应用,没有复杂的依赖关系却有强大的日志采集上报功能

    本文以上报阿里云为例

    1、基础配置讲解

    /etc/rsyslog.conf 为其主配置文件(不用动)
    /etc/rsyslog.d/ 为其扩充配置目录,后面我们的自定义配置要放到这个目录
    /etc/rsyslog.d/50-default.conf  为其默认主扩展配置,不用动但我们的自定义配置文件需要保持格式一致并大于50数值,例如
     
    80-xx.conf
    以下配置文件中 xxx yyy ****均为代替关键字,需依据自己的项目替换,$DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-certificates.crt          
    证书需替换成自己机器上的证书,其余不用更改
    本例中是上报到阿里云故需要阿里云的id和key验证
    参数说明示例
    STRUCTURED-DATA 固定为Logservice。 Logservice
    Project 日志服务Project名称,请提前在日志服务中创建Project。 test-project-1
    Logstore 日志服务Logstore名称,请提前在日志服务中创建Logstore。 test-logstore-1
    access-key-id AccessKey ID。建议使用RAM用户的AccessKey。 <yourAccessKeyId>
    access-key-secret AccessKey Secret。建议使用RAM用户的AccessKey。 <yourAccessKeySecret>

    阿里云上报相关部分参考:

    https://help.aliyun.com/document_detail/112903.html

     1 $FileOwner root                                                                                                                                                                                                                                                                                                        
     2 $FileGroup root                                                                                                                                                    
     3 $FileCreateMode 0640                                                                                                                                               
     4 $DirCreateMode 0755                                                                                                                                                
     5 $Umask 0022                                                                                                                                                        
     6 $PrivDropToUser root                                                                                                                                               
     7                                                                                                                                                                    
     8 $PrivDropToGroup root                                                                                                                                              
     9 *.info;auth.none;mail.none;news.none;authpriv.none;cron.none    /var/log/messages                                                                                  
    10 xxx.*                          /var/log/xxx/xxx.log                                                                                     
    11                                                                                                                                                                    
    12 # 增 加 xxx日 志                                                                                                                                                      
    13 $ModLoad imfile # needs to be done just once 引 入 模 板                                                                                                               
    14 # logstash - test - remote send file.                                                                                                                                                                                                                                
    15                                                                         
    16 $InputFileName /var/log/xxx/xxx.log #指 定 监 控 日 志 文 件                                                                                                                                                                                                                 
    17 $InputFilePollInterval 10 #指 定 每 10秒 轮 询 一 次 文 件                                                                                                                   
    18 $InputFileTag xxx #指 定 文 件 的 tag                                                                                                                         
    19 $InputFileStateFile /var/log/xxx/xxx.log #指 定 状 态 文 件 存 放 位 置 , 如 不 指 定 会 报 错 。                                                                         
    20 $InputFileSeverity info #设 置 监 听 日 志 级 别                                                                                                                           
    21 $InputFileFacility local5 #指 定 告警级别                                                                                                                              
    22 $InputRunFileMonitor #启 动 此 监 控 , 没 有 此 项 , 上 述 配 置 不 生 效 。                                                                                                        
    23                                                                                                                                                                    
    24 # Setup disk assisted queues                                                                                                                                       
    25 #$WorkDirectory /var/spool/rsyslog # where to place spool files                                                                                                    
    26 $ActionQueueFileName fwdRule1     # unique name prefix for spool files                                                                                             
    27 $ActionQueueMaxDiskSpace 1g       # 1gb space limit (use as much as possible)                                                                                      
    28 $ActionQueueSaveOnShutdown on     # save messages to disk on shutdown                                                                                              
    29 $ActionQueueType LinkedList       # run asynchronously                                                                                                             
    30 $ActionResumeRetryCount -1        # infinite retries if host is down                                                                                               
    31 $ActionSendTCPRebindInterval 100  # close and re-open the connection to the remote host every 100 of messages sent.                                                
    32 #RsyslogGnuTLS set to default ca path                                                                                                                              
    33 $DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-certificates.crt                                                                                                   
    34 template(name="LogServiceFormat" type="string"                                                                                                                     
    35 string="<%pri%>1 %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [logservice project=\"xxx\" logstore=\"yyy\" access-key-id=\"******\" access-key-secret=\"*******\"] %msg%\n"                                                                                
    37 )                                                                                                                                                                  
    38 # Send messages to Loggly over TCP using the template.                                                                                                             
    39 action(type="omfwd" protocol="tcp" target="xxxProject.cn-beijing.log.aliyuncs.com" port="10009" template="LogServiceFormat" StreamDriver="gtls" StreamDriverMode="
    40 1" StreamDriverAuthMode="x509/name" StreamDriverPermittedPeers="*.cn-beijing.log.aliyuncs.com")      

     阿里云控制台日志服务入口

    https://help.aliyun.com/document_detail/29008.htm

  • 相关阅读:
    [Android 4.4.4] 泛泰A850 三版通刷 Mokee4.4.4 KTU84P 20140626 RC2.2 by syhost
    YUV12(420) (from)to RGB24
    Python图像处理(16):图像金字塔
    内存管理笔记(分页,分段,逻辑地址,物理地址)【转】
    Linux内核分析--内核中的数据结构双向链表【转】
    标准IO与文件IO 的区别【转】
    Linux中设备号及设备文件【转】
    静态编译和动态编译的区别【转】
    嵌入式系统 Boot Loader 技术内幕【转】
    理解 Linux 的硬链接与软链接【转】
  • 原文地址:https://www.cnblogs.com/cutesnow/p/15905212.html
Copyright © 2020-2023  润新知