Linux伺服器記錄並查詢歷史操作記錄

2021-09-16 13:16:09 字數 1227 閱讀 8768

linux伺服器在使用過程中,經常會有除自己之外的其他人員使用。

一般我們可以用history命令來檢視使用者的操作記錄,但是這個命令不能記錄是哪個使用者登入操作的,也不能記錄詳細的操作時間,且不完整;所以誤操作而造成重要的資料丟失,就很難查到是誰操作的

vi /etc/profile
在檔案末尾加入下面**:

history

user=`whoami`

user_ip=`who -u am i 2>/dev/null| awk ''|sed -e 's/[()]//g'`

if [ "$user_ip" = "" ]; then

user_ip=`hostname`

fiif [ ! -d /var/log/history ]; then

mkdir /var/log/history

chmod 777 /var/log/history

fiif [ ! -d /var/log/history/$ ]; then

mkdir /var/log/history/$

chmod 300 /var/log/history/$

fiexport histsize=4096

dt=`date +"%y%m%d_%h:%m:%s"`

export histfile="/var/log/history/$/$@$_$dt"

chmod 600 /var/log/history/$/*history* 2>/dev/null

然後儲存並退出,執行以下命令,使得編寫的配置生效。

source /etc/profile
注釋: /var/log/history這是記錄日誌的存放位置,可以自定義。

在/var/log/history下會以每個使用者為名新建乙個資料夾,如果沒有history就先新加目錄,然後設定檔案許可權

效果圖:

MapReduce歷史伺服器

作用 儲存執行job任務節點的執行日誌 將多個節點執行map任務的日誌和最終reduce日誌聚合在一起 在mapred site.xml中新增配置 1 2mapreduce.jobhistory.address 3hostname 1002045 67hostname 19888 8view cod...

linux伺服器硬體查詢

查詢伺服器物理cpu個數 cat proc cpuinfo grep physical id sort uniq wc l 查詢cpu核心個數 cat proc cpuinfo grep cpu cores uniq cat proc cpuinfo 檢視cpu資訊 型號 root aaa cat ...

Hadoop配置歷史伺服器

配置歷史伺服器 為了檢視程式的歷史運 況,需要配置一下歷史伺服器。具體配置步驟如下 配置mapred site.xml atguigu hadoop101 hadoop vi mapred site.xml 在該檔案裡面增加如下配置。mapreduce.jobhistory.addressname ...