linux 操作系统修改主机名颜色以及记录操作历史记录
一、修改主机名颜色:
# root @ k8s-node05 cat /etc/profile
在文件末尾增加:
# for bash_color
PS1="\e[33;36m#\e[0m \e[31;40m\u\e[0m @ \e[32;40m\h\e[0m\] in \e[33;40m\w\e[0m\n$ "
# root @ k8s-node05 source /etc/profile
二、增加记录操作历史记录:
# root @ k8s-node05 cat /etc/bashrc
在文件末尾增加:
# for bash_history
export PROMPT_COMMAND=\
'{ msg=$(history 1 | { read x y ; echo $y ;});\
logger -t bash_history "[euid=$(whoami)]":$(who am i):[`pwd`]" $msg";}'
# root @ k8s-node05 source /etc/bashrc
所有用户的操作记录会记录到文件
# root @ k8s-node05 tail -f /var/log/messages
bash_history: [euid=root]:root pts/0 2019-08-08 18:10 (10.212.134.201):[/var/log] cat /etc/bashrc
可以结合es 将日志打入到es