也许,时间见过我们

 

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

posted on 2022-02-17 16:41  画入新雪  阅读(1351)  评论(0编辑  收藏  举报

Copyright ©2017 画入新雪