[root@MySQL-B ~]# echo "*.info /var/log/client" >> /etc/syslog.conf
#配置日志保存文件,把该文件第一行的*.info 提出来。单独放一行。
[root@MySQL-B ~]# service syslog restart #重启syslog日志服务。
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
[root@MySQL-B ~]# vim /etc/sysconfig/syslog #接收客户端写入。
[root@MySQL-A ~]# vim /etc/profile #添加如下行。
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
[root@MySQL-A ~]# source /etc/profile #重新手动source更新。
2.1.客户机修改日志服务器10.0.2.165主机上操作:
代码如下:
[root@MySQL-A ~]# echo "10.0.2.164 logserver" >> /etc/hosts #日志服务器地址。
[root@MySQL-A ~]# echo "*.info @logserver" >> /etc/syslog.conf
#将info日志推送到日志服务器,把该文件第一行的*.info 提出来。单独放一行。
[root@MySQL-A ~]# /etc/init.d/syslog restart #重启syslog日志。
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
3.测试,在客户端主机上10.0.2.165主机上测试并操作:
代码如下:
[root@MySQL-A ~]# test
[root@MySQL-A ~]# echo "this is a test 1"
this is a test 1
[root@MySQL-A ~]# echo "this is a test 2"
this is a test 2
[root@MySQL-A ~]# echo "this is a test 3"
this is a test 3
[root@MySQL-A ~]# echo "this is a test 4"
this is a test 4
[root@MySQL-A ~]# echo "this is a test 5"
this is a test 5
4.返回日志服务器10.0.2.164主机上看结果,是否记录下来客户端主机执行的操作?
代码如下:
[root@MySQL-B ~]# cat /var/log/client
Apr 6 10:37:55 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test1"
Apr 6 10:37:59 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test2"
Apr 6 10:38:01 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test3"
Apr 6 10:38:04 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test4"
Apr 6 10:38:06 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test5"