配置如下(结合上面的安装配置)(服务端的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这台机器上的操作记录都被详细记录下来了。这样,就能清楚地知道登录到这台机器上的用户都做了些什么了.......