应用程序的日志通过rsyslog推送到syslog服务器
centos5系列系统自带为syslog1.4.1
centos6系列自带rsyslog版本为5.8.10
centos7系列自带rsyslog版本为7.4.7
目前最新版rsyslog为8.27.0,rsyslog从8.5.0后对imfile模块进行重构,文件名中可以支持通配符。
rsyslog官网:http://www.rsyslog.com/
升级rsyslog需要配置yum源,centos默认的升级不到最新的版本。
1、配置yum



为了能够使用RPM存储库,您需要一个.repo文件。使用您的webbrowser,请访问http://rpms.adiscon.com。在这里,可以下载rsyslogall.repo文件,或者转到所需版本的子文件夹(例如v8-stable),然后从中下载rsyslog.repo文件。(google翻译来的)

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@localhost yum.repos.d]# pwd/etc/yum.repos.d[root@localhost yum.repos.d]# lsdvd.repo packagekit-media.repo rhel-source.repo rsyslog.repo[root@localhost yum.repos.d]# cat rsyslog.repo [rsyslog_v8]name=Adiscon CentOS-$releasever - local packages for $basearchbaseurl=http://rpms.adiscon.com/v8-stable/epel-$releasever/$basearchenabled=1gpgcheck=0gpgkey=http://rpms.adiscon.com/RPM-GPG-KEY-Adisconprotect=1[root@localhost yum.repos.d]# rpm -qa|grep -i rsyslogrsyslog-5.8.10-10.el6_6.x86_64[root@localhost yum.repos.d]# yum -y install rsyslog[root@localhost yum.repos.d]# rpm -qa|grep -i rsyslogrsyslog-8.27.0-2.el6.x86_64[root@localhost yum.repos.d]# |
根据官方网文档如果复制以上配置可能解析变量不正确导致安装不成功,此时需要替换第三行中的变量“$ releasever”,$releasever的值表示当前系统的发行版本,可以通过rpm -qi centos-release命令查看,其中的Version:6就是我们系统的版本号;$basearch是我们的系统硬件架构(CPU指令集),使用命令arch得到。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@localhost yum.repos.d]# rpm -qi centos-releaseName : centos-release Relocations: (not relocatable)Version : 6 Vendor: CentOSRelease : 5.el6.centos.11.1 Build Date: Wed 27 Nov 2013 07:53:33 PM CSTInstall Date: Thu 27 Apr 2017 06:39:55 PM CST Build Host: c6b9.bsys.dev.centos.orgGroup : System Environment/Base Source RPM: centos-release-6-5.el6.centos.11.1.src.rpmSize : 32670 License: GPLv2Signature : RSA/SHA1, Wed 27 Nov 2013 09:26:58 PM CST, Key ID 0946fca2c105b9dePackager : CentOS BuildSystem <http://bugs.centos.org>Summary : CentOS release fileDescription :CentOS release files[root@localhost yum.repos.d]# archx86_64[root@localhost yum.repos.d]# |
2、配置rsyslog
rsyslog默认只可以传送系统的日志,比如DHCP,cron、kern等,现在要传送一个服务的日志到远端的rsyslog服务器,要使用rsyslog的imfile模块。该模块提供将任何标准文本文件转换为syslog消息的功能。该文件逐行读取,任何读取的行都传递给rsyslog的规则引擎。
官方文档:
http://www.rsyslog.com/doc/v8-stable/configuration/modules/imfile.html





上图为配置样例,各参数可以参考文中的对应模块参数说明,module参考文中Module Parameters说明;input参考文中Input Parameters说明。
|
1
2
3
4
5
6
|
[root@localhost yum.repos.d]# cp /etc/rsyslog.conf{,.20170613bak}[root@localhost yum.repos.d]# vim /etc/rsyslog.confmodule(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 restart |
module
load="imfile" 加载imfile模块
PollingInterval="10" 轮询文件的频率,单位秒,默认10秒,
input
type="imfile"
File="/opt/CalculationUnit/java/sh/logs/bigada.log" 发送到syslog的文件绝对路径
Tag="CalculationUnit"
Severity="info"
Facility="local0"
freshStartTail="on" 设置为on每次重启rsyslog时只读取最新的数据丢弃旧日志,默认关
deleteStateOnFileDelete="on" 如此文件会重新生成需要开启次参数,例如bigdata.log每天凌晨会重命名为bigdata%YYYY%mm%dd%.log,然后重新生成bigdata.log
local0.* @10.10.15.175:514 定义syslog服务器地址
错误:Permission denied
|
1
2
3
|
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"] startJun 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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@localhost ~]# sestatusSELinux status: enabledSELinuxfs mount: /selinuxCurrent mode: enforcingMode from config file: enforcingPolicy version: 24Policy from config file: targeted[root@localhost ~]# getenforce Enforcing[root@localhost ~]# setenforce 0[root@localhost ~]# getenforce Permissive[root@localhost ~]# sestatusSELinux status: enabledSELinuxfs mount: /selinuxCurrent mode: permissiveMode from config file: enforcingPolicy version: 24Policy from config file: targeted[root@localhost ~]# vim /etc/sysconfig/selinux [root@localhost ~]# /etc/init.d/rsyslog restartShutting down system logger: [ OK ]Starting system logger: [ OK ][root@localhost ~]# |
现在可以在syslog服务端数据库里查看到信息

应用程序的日志通过rsyslog推送到syslog服务器的更多相关文章
- 【Nginx】如何格式化日志并推送到远程服务器?看完原来很简单!!
写在前面 Nginx作为最常用的反向代理和负载均衡服务器,被广泛的应用在众多互联网项目的前置服务中,很多互联网项目直接将Nginx服务器作为整个项目的流量入口.这就使得我们可以通过对Nginx服务器日 ...
- JavaCV 采集摄像头和麦克风数据推送到流媒体服务器
越来越觉得放弃JavaCV FFmpeg native API,直接使用JavaCV二次封装的API开发是很明智的选择,使用JavaCV二次封装的API开发避免了各种内存操作不当引起的crash. 上 ...
- 上传文件到服务器端后进一步推送到sftp服务器
扩展安装 要想sftp服务端发送文件,就需要php脚本具有作为ssh客户端的能力,所以需先为php安装如下扩展 openssl openssl-dev libssh php ssh 扩展 按照下面的命 ...
- javaCV开发详解之6:本地音频(话筒设备)和视频(摄像头)抓取、混合并推送(录制)到服务器(本地)
javaCV系列文章: javacv开发详解之1:调用本机摄像头视频 javaCV开发详解之2:推流器实现,推本地摄像头视频到流媒体服务器以及摄像头录制视频功能实现(基于javaCV-FFMPEG.j ...
- windows环境下,spring boot服务使用docker打包成镜像并推送到云服务器私有仓库
最近在淘宝上学习springcloud教程,其中有几节课是讲解讲本地springboot服务打包成镜像并推送到云服务器私有仓库,但是教程里面用的事Mac环境,我的是Windows环境,而且课程里面没有 ...
- Git push将本地版本库的分支推送到远程服务器上对应的分支
在使用git commit命令将修改从暂存区提交到本地版本库后,只剩下最后一步将本地版本库的分支推送到远程服务器上对应的分支了,如果不清楚版本库的构成,可以查看我的另一篇,git 仓库的基本结构. g ...
- 将HG版本库推送到Git服务器
如何将HG版本库推送到Git服务器? 目的 习惯使用HG来进行版本管理,但是GitHub代码统计比Bitbucket要丰富,所以准备主力仓库选用Bitbucket,GitHub作为备用仓库. GitH ...
- 微信小程序开发:设置消息推送
开发设置中,启用并设置消息推送配置后,用户发给小程序的消息以及开发者需要的事件推送,都将被微信转发至该服务器地址中. 不过照着说明去操作,即使按照最简单的明文方式去设置,还是提示Token验证失败.仔 ...
- 小程序mdns+udpSocket实现电视推送
起因:公司以前小程序推送架构为:小程序->接口->后台->socket->机顶盒client->socket->后台->接口->小程序,一系列接口才得到 ...
随机推荐
- python5
print应用 // 输出两行 print "hahaha" print "hehehe" // 输出在同一行里 print "hahaha" ...
- JavaScript学习笔记(二)——函数和数组
第二章 函数简介 1 第一个函数示例 <script language="JavaScript" type="text/JavaScript"> f ...
- [线性DP][codeforces-1110D.Jongmah]一道花里胡哨的DP题
题目来源: Codeforces - 1110D 题意:你有n张牌(1,2,3,...,m)你要尽可能多的打出[x,x+1,x+2] 或者[x,x,x]的牌型,问最多能打出多少种牌 思路: 1.三组[ ...
- GitLab 搭建与使用
操作系统:Centos 7 环境:VM虚拟机 0x00:这里说下VM 虚拟机的配置 然后选择NAT模式 接下来配置网络 cd /etc/sysconfig/network-scripts/ 编辑:vi ...
- tomcat 最大并发连接数设置
转自: http://blog.csdn.net/qysh123/article/details/11678903 这是个很简单的问题,但是搜了一圈,发现大家都写错了.所以这里总结一下: 几乎所有的中 ...
- [leetcode-811-Subdomain Visit Count]
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...
- 四则运算(Android)版
实验题目: 将小学四则运算整合成网页版或者是Android版.实现有无余数,减法有无负数.... 设计思路: 由于学到的基础知识不足,只能设计简单的加减乘除,界面设计简单,代码量少,只是达到了入门级的 ...
- Navicat for mysql导入.sql数据库大小受限制
把导入单个表的最大限制调一下就行(在my.ini里面就算改了max_allowed_packet也不一定行,因为Navicat貌似并不调用,实际他有自己的一套默认配置,所以需要在Navicat上调整) ...
- android入门 — Activity启动模式
1.standard模式 standard模式是系统的默认启动方式,每次激活Activity都会创建Activity,并放在任务栈中. 系统不会在乎活动是否已经存在于返回栈中,每次启动都会创建该活动的 ...
- 第13章 学习shell script
由于博客园中dollar符号有别的意义,所以文中的dollar符号使用¥表示 第一个script [root@localhost script]# cat -n sh01.sh #!/bin/bash ...