阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下rsyslog日志收集服务环境部署记录

273次阅读
没有评论

共计 18356 个字符,预计需要花费 46 分钟才能阅读完成。

rsyslog 可以理解为多线程增强版的 syslog。在 syslog 的基础上扩展了很多其他功能,如数据库支持(MySQL、PostgreSQL、Oracle 等)、日志内容筛选、定义日志格式模板等。目前大多数 Linux 发行版默认也是使用 rsyslog 进行日志记录。rsyslog 提供了三种远程传输协议:

UDP 传输协议
基于传统 UDP 协议进行远程日志传输,也是传统 syslog 使用的传输协议;可靠性比较低,但性能损耗最少,在网络情况比较差,或者接收服务器压力比较高情况下,
可能存在丢日志情况。在对日志完整性要求不是很高,在可靠的局域网环境下可以使用。
 
TCP 传输协议
基于传统 TCP 协议明文传输,需要回传进行确认,可靠性比较高;但在接收服务器宕机或者两者之间网络出问题的情况下,会出现丢日志情况。这种协议相比于 UDP 在
可靠性方面已经好很多,并且 rsyslog 原生支持,配置简单,同时针对可能丢日志情况,可以进行额外配置提高可靠性,因此使用比较广。
 
RELP 传输协议
RELP(Reliable Event Logging Protocol)是基于 TCP 封装的可靠日志消息传输协议;是为了解决 TCP 与 UDP 协议的缺点而在应用层实现的传输协议,也是三者
之中最可靠的。需要多安装一个包 rsyslog-relp 以支持该协议。
 
对于线上服务器,为了日志安全起见,建议使用还是使用 RELP 协议进行传输。

rsyslog 的简单配置记录(如下将公司防火墙上的日志(UDP)打到 IDC 的 rsyslog 日志服务器上)

一、rsyslog 服务端的部署
安装 rsyslog 程序(rsyslog 默认已经在各发行版安装,如果系统中没有的话,可以用 yum 进行安装,如下:)
[root@zabbix ~]# yum install rsyslog -y
 
配置:
[root@zabbix ~]# cat /etc/rsyslog.conf
# rsyslog v5 configuration file
 
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
 
#### MODULES ####
 
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog  # provides kernel logging support (previously done by rklogd)
$ModLoad immark  # provides –MARK– message capability
 
# Provides UDP syslog reception
$ModLoad imudp                                          #开启 udp 的 514 端口。也可以开启 tcp 的 514 端口,这里只接受 udp 的
$UDPServerRun 514
 
# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
 
$WorkDirectory /var/lib/rsyslog
$AllowedSender udp, 192.168.17.0/8                    #仅仅接收来自 192.168.17.0/ 8 网段的主机的 udp 日志(这个是公司防火墙的 ip 地址)
#### GLOBAL DIRECTIVES ####
 
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template Remote,”/data/fw_logs/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log”          #定义模板,接受日志文件路径,区分了不同主机的日志
:fromhost-ip, !isequal, “127.0.0.1” ?Remote                                                        # 过滤 server 本机的日志
# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on
 
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
 
 
#### RULES ####
 
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                /dev/console
 
# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
 
# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure
 
# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog
local4.*                                                /data/fw.log
 
# Log cron stuff
cron.*                                                  /var/log/cron
 
# Everybody gets emergency messages
*.emerg                                                *
 
# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler
 
# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log
 
 
# ### begin forwarding rule ###
# The statement between the begin … end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$WorkDirectory /var/lib/rsyslog # where to place spool files
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g  # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList  # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
 
 
[root@zabbix ~]# mkdir /data/fw_logs/
 
[root@zabbix ~]# /etc/init.d/rsyslog restart
 
 
二、在公司防火墙(192.168.17.41/42)上配置 udp 日志输出策略(在防火墙添加 rsyslog 服务端的 ip 和 514 端口)
 
三、过一会儿,在 rsyslog 日志服务器上设置的日志目录下就能看到防火墙的日志输出了
[root@zabbix ~]# ll /data/fw_logs/
total 4.0K
drwxrwxrwx  4 root root  46 Jul 28 10:40 .
drwxr-xr-x. 18 root root 4.0K Jul 28 10:38 ..
drwx——  2 root root  41 Jul 28 10:37 192.168.17.41
drwx——  2 root root  41 Jul 28 10:40 192.168.17.42
[root@zabbix ~]# ll /data/fw_logs/192.168.17.41
total 16K
drwx—— 2 root root  41 Jul 28 10:37 .
drwxrwxrwx 4 root root  46 Jul 28 10:40 ..
-rw——- 1 root root 13K Jul 28 14:02 192.168.17.41_2017-07-28.log
 
 
————————————————————————————
可以将上面 rsyslog 服务端的 rsyslog.conf 里的 ip 白名单设置为客户机的 ip 端,比如:
$AllowedSender tcp, 172.18.0.0/16                  #表示接收 172.18.0.0/16 网段的客户机的 tcp 日志输入,前提是打开 tcp 的 514 端口
 
客户机的配置:
只需要在 rsyslog.conf 文件里添加下面一行:
*.*                              @172.18.10.20                    #后面的 ip 是 rsyslog 服务端的 ip 地址
 
启动 rsyslog 日志即可!

==================== 再看一例 =======================
以上配置的是将公司防火墙的日志打到 rsyslog 里。现在有这么一个需求:
公司 IDC 的另外两台服务器 172.19.10.24 和 172.19.10.25 上部署了 gitlab、nexus、jenkins、jira 和 wiki,上面的权限设置的比较杂,很多人都有登录需求。现在需要将登录到这两台服务器上的用户的所有操作过程记录下来,记录达到 rsyslog 日志里,相当于做用户操作记录的审计工作。

配置如下(结合上面的安装配置)(服务端的 ip 是 172.19.16.21):
1)rsyslog 服务端配置(相比于上面的配置,这里去掉了 AllowedSender 的来源 ip 的白名单限制。即允许接收所有机器的日志;上面的防火墙日志还是能继续收集)
[root@zabbix ~]# cat /etc/rsyslog.conf|grep -v “#”|grep -v “^$”
$ModLoad imudp
$UDPServerRun 514
$WorkDirectory /var/lib/rsyslog
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template Remote,”/data/fw_logs/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log”
:fromhost-ip, !isequal, “127.0.0.1” ?Remote
$IncludeConfig /etc/rsyslog.d/*.conf
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                *
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log
local5.*                                              /var/log/history.log
 
[root@zabbix ~]# /etc/init.d/rsyslog restart
 
2)在 172.19.10.24 上的配置
[root@gitlab ~]# cat /etc/rsyslog.conf|grep -v “#”|grep -v “^$”
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                *
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log
local5.*    @172.19.16.21
 
[root@gitlab ~]# /etc/init.d/rsyslog restart
 
[root@gitlab ~]# cat /etc/profile                  #在该文件的底部添加下面内容
…….
export HISTTIMEFORMAT
export PROMPT_COMMAND='{command=$(history 1 | { read x y; echo $y;}); logger -p local5.notice -t bash -i “user=$USER,ppid=$PPID,from=$SSH_CLIENT,pwd=$PWD,command:$command”; }’
 
3)在另一台 172.19.10.25 上做类似配置配置
[root@nexus ~]# cat /etc/rsyslog.conf |grep -v “#”|grep -v “^$”
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                *
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log
local5.*  @172.19.16.21
 
[root@nexus ~]# /etc/init.d/rsyslog restart
 
[root@nexus ~]# cat /etc/profile
…….
export HISTTIMEFORMAT
export PROMPT_COMMAND='{command=$(history 1 | { read x y; echo $y;}); logger -p local5.notice -t bash -i “user=$USER,ppid=$PPID,from=$SSH_CLIENT,pwd=$PWD,command:$command”; }’
 
4)过一段时间,发现在 rsyslog 服务端的日志目录 /data/fw_logs 下面已经有收集到的日志了
[root@zabbix fw_logs]# pwd
/data/fw_logs
[root@zabbix fw_logs]# cd
[root@zabbix ~]# cd /data/fw_logs/
[root@zabbix fw_logs]# ll
total 12K
drwxrwxrwx  6 root root  84 Aug 16 18:28 .
drwxr-xr-x. 18 root root 4.0K Aug 16 17:58 ..
drwx——  2 root root  74 Aug 17 09:50 172.19.10.24
drwx——  2 root root  74 Aug 17 10:00 172.19.10.25
drwx——  2 root root 4.0K Aug 17 00:01 192.168.17.41
drwx——  2 root root 4.0K Aug 17 00:01 192.168.17.42
[root@zabbix fw_logs]# cd 172.19.10.24/
[root@zabbix 172.19.10.24]# ll
total 20K
drwx—— 2 root root  74 Aug 17 09:50 .
drwxrwxrwx 6 root root  84 Aug 16 18:28 ..
-rw——- 1 root root 14K Aug 16 20:45 172.19.10.24_2017-08-16.log
-rw——- 1 root root 771 Aug 17 10:03 172.19.10.24_2017-08-17.log
[root@zabbix 172.19.10.24]# cat 172.19.10.24_2017-08-16.log
Aug 16 18:39:56 gitlab bash[138413]: user=root,ppid=124297,from=172.19.16.28 29338 22,pwd=/root,command:[2017-08-16 18:39:56]root pts/5 2017-08-16 17:23 (172.19.16.28)/etc/init.d/rsyslog restart
Aug 16 18:39:56 gitlab bash[138418]: user=root,ppid=124297,from=172.19.16.28 29338 22,pwd=/root,command:[2017-08-16 18:39:56]root pts/5 2017-08-16 17:23 (172.19.16.28)/etc/init.d/rsyslog restart
Aug 16 18:39:56 gitlab bash[138422]: user=root,ppid=124297,from=172.19.16.28 29338 22,pwd=/root,command:[2017-08-16 18:39:56]root pts/5 2017-08-16 17:23 (172.19.16.28)/etc/init.d/rsyslog restart
Aug 16 18:39:57 gitlab bash[138426]: user=root,ppid=124297,from=172.19.16.28 29338 22,pwd=/root,command:[2017-08-16 18:39:56]root pts/5 2017-08-16 17:23 (172.19.16.28)/etc/init.d/rsyslog restart
Aug 16 18:40:30 gitlab bash[138610]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/root,command:[2017-08-16 18:40:03]root pts/0 2017-08-16 18:40 (172.16.255.202)exit
Aug 16 18:40:43 gitlab bash[138652]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data,command:[2017-08-16 18:40:43]root pts/0 2017-08-16 18:40 (172.16.255.202)cd /data/
Aug 16 18:40:43 gitlab bash[138657]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data,command:[2017-08-16 18:40:43]root pts/0 2017-08-16 18:40 (172.16.255.202)ls
Aug 16 18:40:47 gitlab bash[138666]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data,command:[2017-08-16 18:40:47]root pts/0 2017-08-16 18:40 (172.16.255.202)mkdir hahahahah
Aug 16 18:40:48 gitlab bash[138671]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data/hahahahah,command:[2017-08-16 18:40:48]root pts/0 2017-08-16 18:40 (172.16.255.202)cd hahahahah/
Aug 16 18:40:48 gitlab bash[138677]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data/hahahahah,command:[2017-08-16 18:40:48]root pts/0 2017-08-16 18:40 (172.16.255.202)ls
Aug 16 18:40:54 gitlab bash[138696]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data/hahahahah,command:[2017-08-16 18:40:54]root pts/0 2017-08-16 18:40 (172.16.255.202)echo “Asdfasdf” >heihei
Aug 16 18:40:54 gitlab bash[138702]: user=root,ppid=138586,from=172.16.255.202 52496 22,pwd=/data/hahahahah,command:[2017-08-16 18:40:54]root pts/0 2017-08-16 18:40 (172.16.255.202)ls
…….
 
有上面日志可以看出,在 172.19.10.24 这台机器上的操作记录都被详细记录下来了。这样,就能清楚地知道登录到这台机器上的用户都做了些什么了 …….

=====================通过 rsyslog 收集 nginx 日志到远程服务器上 ====================
需求说明:通过 rsyslog 服务将 192.168.10.21 服务器上的 /data/nginx/logs/www.kevin.com-access.log 日志实时同步到 192.168.10.52 服务器上(路径为 /data/rsyslog/nginx)

1)192.168.10.21 为 rsyslog 客户端,即日志的推送端 rsyslog 日志是客户机主动将自己的日志推送到远程服务器上
操作如下:
[root@nginx-server ~]# yum install rsyslog -y
[root@nginx-server ~]# cp /etc/rsyslog.conf /etc/rsyslog.conf.bak
[root@nginx-server ~]# cat /etc/rsyslog.conf
# rsyslog v5 configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####

$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides –MARK– message capability
$ModLoad imfile                               ## 装载 imfile 模块,这一行手动添加

# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514

# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514

#### GLOBAL DIRECTIVES ####

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console

# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none;local5.none /var/log/messages             ## 不记录 local5 的日志

# The authpriv file has restricted access.
authpriv.* /var/log/secure

# Log all the mail messages in one place.
mail.* -/var/log/maillog

# Log cron stuff
cron.* /var/log/cron

# Everybody gets emergency messages
*.emerg *

# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler

# Save boot messages also to boot.log
local7.* /var/log/boot.log

# ### begin forwarding rule ###
# The statement between the begin … end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$WorkDirectory /var/lib/rsyslog # where to place spool files
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
user.info /var/log/history

# 在文件底部添加下面几行内容
$InputFileName /data/nginx/logs/www.kevin.com-access.log        ## 读取日志文件(要监控的日志文件)
$InputFileTag web_access             ## 日志写入日志附加标签字符串
$InputFileSeverity info           ## 日志等级
$InputFileStateFile /etc/rsyslog.d/stat-access         ## 记录日志点等信息。(相当于 msyql 的 master.info) 文件名变了,
这个 StateFile 标志必须变,否则无法传输。
$InputFileFacility local5         ## 设施类别
$InputFilePollInterval 1          ## 检查日志文件间隔(秒)
$InputFilePersistStateInterval 1       ## 回写偏移量数据到文件间隔时间(秒)
$InputRunFileMonitor                          ## 激活读取,可以设置多组日志读取,每组结束时设置本参数。以示生效。
local5.* @192.168.10.52            ## 代表 local5 设施的所有级别通过 udp 协议传送到 192.168.10.51

重启 rsyslog 服务
[root@nginx-server ~]# /etc/init.d/rsyslog restart
关闭系统日志记录器:[确定]
启动系统日志记录器:[确定]

由于作为日志的推送端,rsyslog 日志不需要开启 514 端口(如上在 rsyslog.conf 文件里没有打开 dup 或 tcp 的 514 端口)
[root@nginx-server ~]# lsof -i:514
[root@nginx-server ~]#

2)192.168.10.52 为 rsyslog 服务端,即日志的接收端。
配置如下:
[root@log-server ~]# yum install rsyslog -y
[root@log-server ~]# cp /etc/rsyslog.conf /etc/rsyslog.conf.bak
# rsyslog configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark # provides –MARK– message capability

# Provides UDP syslog reception
$ModLoad imudp                   ## 载入 imudp 模块
$UDPServerRun 514            ## 开启 udp 接收并制定端口号

# Provides TCP syslog reception
$ModLoad imtcp                 ## 载入 imtcp 模块。
$InputTCPServerRun 514             ## 开启 tcp 接收并制定端口号。tcp 和 udp 两个端口模块可以同时使用!

#### GLOBAL DIRECTIVES ####

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# 定义一个模板用来指定接收的日志消息的格式(默认会在记录的日志前加几个字段)
$template  SpiceTmpl,”%msg%\n”                   ##%msg:2:$% 为去掉日志开头的空格

# 定义一个模板用来指定接收的日志文件的存放路径 %……% 之间的是定义日志按照年 - 月 - 日命名
$template  DynaFile,”/data/rsyslog/nginx/%$YEAR%-%$MONTH%-%$DAY%.log”

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state

#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console

# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none;local5.none                /var/log/messages            ## 不记录 local5 设施的日志

# The authpriv file has restricted access.
authpriv.* /var/log/secure

# Log all the mail messages in one place.
mail.* -/var/log/maillog

# Log cron stuff
cron.* /var/log/cron

# Everybody gets emergency messages
*.emerg :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler

# Save boot messages also to boot.log
local7.* /var/log/boot.log

# 接收客户端 local5 设施传送来的日志并存放到指定位置(位置可用定义的模板。? 代表使用动态的模板)
local5.*                       ?DynaFile;SpiceTmpl

# ### begin forwarding rule ###
# The statement between the begin … end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###

编辑 /etc/sysconfig/rsyslog 中 ”SYSLOGD_OPTIONS=” 开启远程日志接收功能
[root@log-server ~]# cat /etc/sysconfig/rsyslog
# Options for rsyslogd
# Syslogd options are deprecated since rsyslog v3.
# If you want to use them, switch to compatibility mode 2 by “-c 2”
# See rsyslogd(8) for more details
SYSLOGD_OPTIONS=”-c 5″

创建日志接收过来后定义的存放目录
[root@log-server ~]# mkdir -p /data/rsyslog/nginx

重启 rsyslog 服务
[root@log-server ~]# /etc/init.d/rsyslog restart
Shutting down system logger: [OK]
Starting system logger: [OK]
[root@log-server ~]# lsof -i:514
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsyslogd 24594 root 2u IPv4 38927639 0t0 TCP *:shell (LISTEN)
rsyslogd 24594 root 3u IPv4 38927635 0t0 UDP *:syslog
rsyslogd 24594 root 4u IPv6 38927636 0t0 UDP *:syslog
rsyslogd 24594 root 5u IPv6 38927640 0t0 TCP *:shell (LISTEN)

查看日志是否接收过来了
[root@log-server ~]# ll /data/rsyslog/nginx/
total 550876
-rw——- 1 root root 483539594 Jun 13 12:58 2018-06-13.log
[root@log-server ~]# tail -2 /data/rsyslog/nginx/2018-06-13.log
1.203.163.198 – [27/Apr/2018:00:17:53 +0800] “POST /scf/%7B%7BloginConfig.loginSubmitUrl%7D%7D HTTP/1.1” 302 0 “https://www.kevin.com/scf/login” Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36 – 0.010 0.003 10.0.54.21:9020 302
1.203.163.198 – [27/Apr/2018:00:17:53 +0800] “POST /scf/%7B%7BloginConfig.loginSubmitUrl%7D%7D HTTP/1.1” 302 0 “https://www.kevin.com/scf/login” Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36 – 0.012 0.003 10.0.54.21:9020 302

==========================================================================
注意:
a)如果发现日志还没有接收过来,即 /data/rsyslog/nginx 目录下没有日志产生,就同时重启推送端和接收端的 rsyslog 服务。确保双方的 iptables 防火墙和 selinux 关闭!
b)也可以自行修改接收的日志文件的存放路径,如改为下面的配置:
$template DynaFile,”/data/rsyslog/nginx/nginx-access.log”
则日志收集后存放的文件如下:
[root@log-server ~]# ll /data/rsyslog/nginx/
total 571716
-rw——- 1 root root 483539594 Jun 13 12:58 2018-06-13.log
-rw——- 1 root root 101893593 Jun 13 13:13 nginx-access.log

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计18356字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中