服务器维护日志记载,服务器记录操作日志

5.1.2.1. 服务器记录并查询历史操作记录

Linux服务器在使用过程中,经常会有除自己之外的其他人员使用。并不是每个人都对Linux服务器特别熟悉,难免会有一些操作导致服务器报错。

history是查询当前连接所操作的命令,通过编写以下内容添加至/etc/profile的原有内容之后,将每个连接的操作都进行记录,并保存在特定位置。

vim /etc/profile

添加一下内容

history

RQ=`date "+%Y%m%d"`

USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`

if [ "$USER_IP" = "" ]

then

USER_IP=`hostname`

fi

if [ ! -d /var/log/histories ]

then

mkdir /var/log/histories

chmod 777 /var/log/histories

fi

export HISTSIZE=8192

DT=`date "+%H:%M:%S"`

export HISTFILE="/var/log/histories/history.log"

export PROMPT_COMMAND='{ date "+[%Y-%m-%d %T] ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(pwd) #### $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTORY_FILE'

chmod 600 /var/log/histories/history.log 2>/dev/null

然后保存并退出,执行以下命令,使得编写的配置生效。

source /etc/profile

操作审计日志 保存在 /var/log/histories/history.log

日志管理请看这

Copyright © www.ainiok.com 2018 all right reserved,powered by Gitbook修订时间:

2019-02-25 23:48:01

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值