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
------
往事如烟,伴着远去的步伐而愈加朦胧。未来似雾,和着前进的风儿而逐渐清晰!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现