系统日志文件:/var/log/messages
该日志会被logrotate服务启动切割:
[root@linux ~]# ls /var/log/messages*
/var/log/messages /var/log/messages-20190923 /var/log/messages-20190929
查看logrotate配置文件:
[root@linux ~]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
weekly:表示每周切割一次
rotate:表示保存4个日志文件(也就是4次的切割文件:保留一个月)
dmesg命令:
1.执行dmesg命令会输出系统硬件相关的日志,输出信息在内存中,所有没有具体文件,在排查硬件问题时可使用
2. dmesg -c :清空硬件日志信息
3. 与/var/log/dmesg文件没有关联,该文件记录的是系统启动的一些信息
last命令: 查看登录成功的用户的历史记录
该命令调用的/var/log/wtmp文件,该文件为二进制文件,不能直接cat,执行last命令输出信息
[root@linux ~]# last
root pts/0 192.168.234.1 Wed Oct 2 14:48 still logged in
root pts/0 192.168.234.1 Mon Sep 30 19:52 - 21:10 (01:18)
root pts/0 192.168.234.1 Mon Sep 30 09:34 - 13:56 (04:22)
root pts/0 192.168.234.1 Sun Sep 29 23:05 - 23:48 (00:43)
lastb命令:
与last命令相反,记录登录失败的用户的历史记录,对应的文件为/var/log/btmp,在服务器被暴力破解时,该文件可能会产生大量数据
/var/log/secure日志: 记录登录成功和失败的信息
[root@linux ~]# tail -8 /var/log/secure
Sep 30 09:34:19 linux sshd[6765]: Accepted password for root from 192.168.234.1 port 51975 ssh2
Sep 30 09:34:19 linux sshd[6765]: pam_unix(sshd:session): session opened for user root by (uid=0)
Sep 30 13:56:44 linux sshd[6765]: pam_unix(sshd:session): session closed for user root
Sep 30 19:52:02 linux sshd[7932]: Accepted password for root from 192.168.234.1 port 50528 ssh2
Sep 30 19:52:02 linux sshd[7932]: pam_unix(sshd:session): session opened for user root by (uid=0)
Sep 30 21:10:14 linux sshd[7932]: pam_unix(sshd:session): session closed for user root
Oct 2 14:48:43 linux sshd[8224]: Accepted password for root from 192.168.234.1 port 51773 ssh2
Oct 2 14:48:43 linux sshd[8224]: pam_unix(sshd:session): session opened for user root by (uid=0)
screen虚拟终端工具:
使用场景:当使用远程工具连接着服务器需要执行一个耗时很长的脚本或者命令时,为了保证不因为网络等因素导致终端连接中断而影响操作中断,可以使用screen工具创建虚拟终端执行这种命令或脚本
安装:
[root@linux ~]# yum -y install screen
进入终端:(开启一个终端)
screen+回车
将终端切换到后台运行:
ctrl+a+d
进入终端时,自定义终端名称 -S 参数:
[root@linux ~]# screen -S test
查看虚拟终端列表:
[root@linux ~]# screen -ls
There are screens on:
8502.test (Detached)
8485.pts-0.linux (Detached)
8460.pts-0.linux (Detached)
3 Sockets in /var/run/screen/S-root.
进入指定终端 -r 参数:
指定终端列表中的终端编号即可:
[root@linux ~]# screen -r 8502
或者指定终端名也可以进入:
[root@linux ~]# screen -r test
关闭虚拟终端:
当终端使用完需要关闭时,在虚拟终端内执行exit即可