应用程序的日志通过rsyslog推送到syslog服务器
centos5系列系統(tǒng)自帶為syslog1.4.1
centos6系列自帶rsyslog版本為5.8.10
centos7系列自帶rsyslog版本為7.4.7
目前最新版rsyslog為8.27.0,rsyslog從8.5.0后對imfile模塊進行重構(gòu),文件名中可以支持通配符。
rsyslog官網(wǎng):http://www.rsyslog.com/
升級rsyslog需要配置yum源,centos默認的升級不到最新的版本。
1、配置yum
為了能夠使用RPM存儲庫,您需要一個.repo文件。使用您的webbrowser,請訪問http://rpms.adiscon.com。在這里,可以下載rsyslogall.repo文件,或者轉(zhuǎn)到所需版本的子文件夾(例如v8-stable),然后從中下載rsyslog.repo文件。(google翻譯來的)
根據(jù)官方網(wǎng)文檔如果復(fù)制以上配置可能解析變量不正確導(dǎo)致安裝不成功,此時需要替換第三行中的變量“$ releasever”,$releasever的值表示當(dāng)前系統(tǒng)的發(fā)行版本,可以通過rpm -qi centos-release命令查看,其中的Version:6就是我們系統(tǒng)的版本號;$basearch是我們的系統(tǒng)硬件架構(gòu)(CPU指令集),使用命令arch得到。
[root@localhost?yum.repos.d]#?rpm?-qi?centos-release Name????????:?centos-release???????????????Relocations:?(not?relocatable) Version?????:?6?????????????????????????????????Vendor:?CentOS Release?????:?5.el6.centos.11.1?????????????Build?Date:?Wed?27?Nov?2013?07:53:33?PM?CST Install?Date:?Thu?27?Apr?2017?06:39:55?PM?CST??????Build?Host:?c6b9.bsys.dev.centos.org Group???????:?System?Environment/Base???????Source?RPM:?centos-release-6-5.el6.centos.11.1.src.rpm Size????????:?32670????????????????????????????License:?GPLv2 Signature???:?RSA/SHA1,?Wed?27?Nov?2013?09:26:58?PM?CST,?Key?ID?0946fca2c105b9de Packager????:?CentOS?BuildSystem?<http://bugs.centos.org> Summary?????:?CentOS?release?file Description?: CentOS?release?files [root@localhost?yum.repos.d]#?arch x86_64 [root@localhost?yum.repos.d]#2、配置rsyslog
rsyslog默認只可以傳送系統(tǒng)的日志,比如DHCP,cron、kern等,現(xiàn)在要傳送一個服務(wù)的日志到遠端的rsyslog服務(wù)器,要使用rsyslog的imfile模塊。該模塊提供將任何標準文本文件轉(zhuǎn)換為syslog消息的功能。該文件逐行讀取,任何讀取的行都傳遞給rsyslog的規(guī)則引擎。
官方文檔:
http://www.rsyslog.com/doc/v8-stable/configuration/modules/imfile.html
上圖為配置樣例,各參數(shù)可以參考文中的對應(yīng)模塊參數(shù)說明,module參考文中Module Parameters說明;input參考文中Input Parameters說明。
[root@localhost?yum.repos.d]#?cp?/etc/rsyslog.conf{,.20170613bak} [root@localhost?yum.repos.d]#?vim?/etc/rsyslog.conf module(load="imfile"?PollingInterval="10") input(type="imfile"?File="/opt/CalculationUnit/java/sh/logs/bigada.log"?Tag="CalculationUnit"?Severity="info"?Facility="local0"?freshStartTail="on"?deleteStateOnFileDelete="on") local0.*?@10.10.15.175:514 [root@localhost?yum.repos.d]#?/etc/init.d/rsyslog?restartmodule
? ? ??load="imfile"????加載imfile模塊
? ? ??PollingInterval="10"?????輪詢文件的頻率,單位秒,默認10秒,
input
???? type="imfile"?
? ? ?File="/opt/CalculationUnit/java/sh/logs/bigada.log"????發(fā)送到syslog的文件絕對路徑
? ? ?Tag="CalculationUnit"?
? ? ?Severity="info"?????
? ? ?Facility="local0"?
? ? ?freshStartTail="on"????設(shè)置為on每次重啟rsyslog時只讀取最新的數(shù)據(jù)丟棄舊日志,默認關(guān)
? ? ?deleteStateOnFileDelete="on" 如此文件會重新生成需要開啟次參數(shù),例如bigdata.log每天凌晨會重命名為bigdata%YYYY%mm%dd%.log,然后重新生成bigdata.log
local0.* @10.10.15.175:514 ? 定義syslog服務(wù)器地址
錯誤:Permission denied?
Jun?27?18:33:46?localhost?rsyslogd:?imfile?warning:?directory?'/opt/CalculationUnit/java/sh/logs':?Permission?denied?[v8.27.0?try?http://www.rsyslog.com/e/2046?] Jun?27?18:33:46?localhost?rsyslogd:??[origin?software="rsyslogd"?swVersion="8.27.0"?x-pid="19409"?x-info="http://www.rsyslog.com"]?start Jun?27?18:33:46?localhost?rsyslogd:?imfile:?error?with?inotify?API,?ignoring?file?'/opt/CalculationUnit/java/sh/logs/bigada.log':?Permission?denied??[v8.27.0]檢查selinux
[root@localhost?~]#?sestatus SELinux?status:?????????????????enabled SELinuxfs?mount:????????????????/selinux Current?mode:???????????????????enforcing Mode?from?config?file:??????????enforcing Policy?version:?????????????????24 Policy?from?config?file:????????targeted [root@localhost?~]#?getenforce? Enforcing [root@localhost?~]#?setenforce?0 [root@localhost?~]#?getenforce? Permissive [root@localhost?~]#?sestatus SELinux?status:?????????????????enabled SELinuxfs?mount:????????????????/selinux Current?mode:???????????????????permissive Mode?from?config?file:??????????enforcing Policy?version:?????????????????24 Policy?from?config?file:????????targeted [root@localhost?~]#?vim?/etc/sysconfig/selinux? [root@localhost?~]#?/etc/init.d/rsyslog?restart Shutting?down?system?logger:???????????????????????????????[??OK??] Starting?system?logger:????????????????????????????????????[??OK??] [root@localhost?~]#現(xiàn)在可以在syslog服務(wù)端數(shù)據(jù)庫里查看到信息
轉(zhuǎn)載于:https://blog.51cto.com/ityunwei2017/1934910
總結(jié)
以上是生活随笔為你收集整理的应用程序的日志通过rsyslog推送到syslog服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 9.98万的比亚迪秦PLUS DM-i
- 下一篇: 吉利银河全新 Logo 发布,首款原型车