环境:
C6.x和C7.x通用:
[root@localhost rsyslog.d]# uname -a
Linux localhost.localdomain 3.10.0-514.26.1.el7.x86_64 #1SMP Thu Jun 29 16:05:25 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost rsyslog.d]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
配置:
在以下文件中添加命令行监控命令,这行命令将命令行的命令写到/var/log/messages文件中
vim /etc/bashrc
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y;echo $y; });logger "[euid=$(whoami)]":$(who ami):[`pwd`]"$msg"; }'
#source /etc/bashrc
配置rsyslog服务,将/var/log/messages文件的内容推送到rsyslog服务端:
[root@localhost rsyslog.d]#mkdir -p /var/spool/rsyslog
[root@node10 rsyslog.d]# pwd
/etc/rsyslog.d
[root@localhost rsyslog.d]# ls
listen.conf messages.conf nginx-binlog.conf
[root@localhost rsyslog.d]# cat messages.conf
$ModLoad imfile
$InputFilePollInterval 10
$WorkDirectory /var/spool/rsyslog
$PrivDropToGroup adm
$InputFileName /var/log/messages #指定要监控的文件
$InputFileTag messages-access:
$InputFileStateFile stat-messages-access
$InputFileSeverity info
$InputFilePersistStateInterval 25000
$InputRunFileMonitor
## 指定日志格式模板:
$template BiglogFormatNginx,"%msg%\n"
## 注意syslog日志服务器接收地址,根据实dd际情况修改:
if $programname == 'messages-access' then@192.168.66.10;BiglogFormatNginx
if $programname == 'messages-access' then ~
重启服务:
#service rsyslog restart