CentOS清除SSH登录记录、历史命令及日志缓存

Kevin 教程 6,486 次浏览 49条评论

清除 SSH 登录记录

SSH 登录日志以二进制方式存储在以下文件内,需要使用对应命令查看,不然会显示乱码。

日志文件 查看命令 日志内容
/var/log/wtmp last 登录成功日志,包含用户名、IP 地址和时间记录
/var/log/btmp lastb 登录失败日志,包含信息同上
/var/log/lastlog lastlog 各用户的最近登录日志
/var/log/secure cat查看 各类需要输入口令的登录日志

清除 SSH 登录日志使用下面命令。

cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/btmp
cat /dev/null > /var/log/lastlog
cat /dev/null > /var/log/secure

清除 Bash 历史命令

Bash 执行过的命令存在用户目录下的.bash_history文件里,用history命令查看。

清除所有历史命令记录,第二条命令表示立即更新日志文件。

history -c
history -w

如果只需清除当前会话用过的命令记录,使用history -r命令清除。

删除重复软件包

用于解决因同时安装32位和64位软件包导致的问题。先安装yum-utils软件。

yum -y install yum-utils

列出所有重复的软件包。

package-cleanup --dupes

删除重复软件包,过程中需确认操作。

package-cleanup --cleandupes

清除 YUM 缓存

用法一:清除已启用软件仓库里的所有类型缓存。

yum clean all

延伸:Ubuntu / Debian 用apt-get clean命令清除缓存,还可用apt-get autoremove清除重复多余软件包。

用法二:添加--enablerepo='*'选项临时清除禁用状态的软件仓库缓存。

yum --enablerepo='*' clean all

用法三:清除指定类型 YUM 缓存。

命令 作用
yum clean expire-cache 清除元数据和镜像列表的获取时间,使下次使用 YUM 时重新验证缓存。如果缓存数据仍有效,则不会删除任何重要数据。
yum clean packages 清除缓存目录下的软件包。
yum clean headers 清除旧版 YUM 用来确认软件包依赖关系的文件,在下次运行 YUM 时重新下载。
yum clean metadata 清除 YUM 用于确认软件包远程可用性的文件,在下次运行 YUM 时重新下载。
yum clean dbcache 清除加速元数据访问的 sqlite 缓存,下次运行时重新创建(注:不适用仅包含 .xml 数据的软件仓库,其清除后不会重新创建)。
yum clean rpmdb 清除任何本地 rpmdb 中的缓存数据。
yum clean plugins 清除已启用 YUM 插件的缓存数据。
上述列表中的expire-cache是较温和选项,可以用来替代clean all

清除系统日志文件

已排除上面提到的日志文件。其中/var/log/messages是重要日志文件,记录了几乎所有系统错误及重要的相关信息。如果系统出了问题,该文件是经常要检查的项目之一。

cat /dev/null > /var/log/boot.log
cat /dev/null > /var/log/cron
cat /dev/null > /var/log/dmesg
cat /dev/null > /var/log/firewalld
cat /dev/null > /var/log/maillog
cat /dev/null > /var/log/messages
cat /dev/null > /var/log/spooler
cat /dev/null > /var/log/syslog
cat /dev/null > /var/log/tallylog
cat /dev/null > /var/log/yum.log

关于系统日志文件的路径设置可以查看/etc/rsyslog.conf文件,CentOS 旧版本则是/etc/syslog.conf

释放内存缓存

内存缓存分 Page Cache 和 Buffer Cache。前者从硬盘读取的文件缓存,譬如 find 查找文件首次速度慢,而后就变快了。后者是 slab 分配器中的对象(Dentry 缓存、Inode 缓存)。为避免清除缓存引发可能的内存 Buffer 数据丢失,清除前先运行sync命令使数据写到硬盘。

下面命令将同时清除两种类型缓存。如要选择性清除替换其中数字,1 表示 Page Cache,2表示 Buffer Cache。

sync && echo 3 > /proc/sys/vm/drop_caches

free -h命令检查运行前后的内存 buff/cache 用量,available 表示剩余可用容量。

可以crontab -e添加定时释放内存缓存任务。例如每天凌晨 4 点运行一次。

0 4 * * * sync && echo 3 > /proc/sys/vm/drop_caches

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    how to use dapoxetine citrate https://salemeds24.wixsite.com/dapoxetine

  3. #3

    stromectol 3 mg tablets price https://ivermectin.mlsmalta.com/

  4. #4

    african ivermectin ingredients https://ivermectin.webbfenix.com/

  5. #5

    how much vidalista is safe https://vidalista.mlsmalta.com/

  6. #6

    hydroxychloroquine 200mg for lupus https://hydroxychloroquine.mlsmalta.com/

  7. #7

    hydroxychloroquine coronavirus success https://hydroxychloroquine.webbfenix.com/

  8. #8

    does viagra work on women http://droga5.net/

  9. #9

    dapoxetine 60 mg in uk https://dapoxetine.confrancisyalgomas.com/

  10. #10

    generic professional vidalista https://vidalista40mg.mlsmalta.com/

  11. #11

    albuterol ipratropium vs albuterol sulfate https://amstyles.com/

  12. #12

    is generic cialis real https://wisig.org/

  13. #13

    cost of prescription drugs without insurance https://edmeds.buszcentrum.com/

  14. #14

    60mg priligy daily side effects https://ddapoxetine.com/

  15. #15

    black cialis 1000mg https://tadalafili.com/

  16. #16

    Cialis Vs Viagra Reviews Easettenex is cialis generic Alicky prix levitra 10 acheter

  17. #17

    buy hydroxychloroquine from canada https://sale.azhydroxychloroquine.com/

  18. #18

    compare drug prices in canada https://medpills.bee-rich.com/

  19. #19

    compare drug prices in canada https://buymeds.mlsmalta.com/

  20. #20

    plaquenil dosage based on weight https://hydroxychloroquinee.com/

  21. #21

    vidalista adcirca 20mg https://vidalista.buszcentrum.com/

  22. #22

    generic cialis http://cialllis.com/

  23. #23

    generic cialis cialis australia https://tadalafil.cleckleyfloors.com/

  24. #24

    can you mix cialis and alcohol http://tadalafila.online/

  25. #25

    try this out…
    pussy888

  26. #26

    need money today

  27. #27

    sildalis 100mg 20mg

  28. #28

    tadalafil price in canada

  29. #29

    installment loan guaranteed approval

  30. #30

    loan payday

  31. #31

    Very useful ! Thank U
    วิธีดูราคาบอล

  32. #32

    vidalista 20 reviews http://vidallista.com/

  33. #33

    advanced cash

  34. #34

    cialis 2.5 mg

  35. #35

    buy cialis https://cialzi.com/

  36. #36

    hydroxychloroquine brands http://hydroxychloroquined.online/

  37. #37

    Aw, this was a really good post. Taking the time and actual effort to generate a very good article… but what
    can I say… I procrastinate a lot and don’t manage to get anything done. https://cialis.confrancisyalgomas.com/tadalafil

  38. #38

    I’m amazed, I have to admit. Seldom do I come across a blog that’s both educative and engaging,
    and without a doubt, you have hit the nail on the
    head. The issue is an issue that too few folks are speaking intelligently about.

    I am very happy that I stumbled across this in my hunt for something regarding this. http://hydroxychloroquinea.anafassia.com/

  39. #39

    You are a very bright individual!

    http://www.vreyrolinomit.com/

  40. #40

    cialis 100mg price https://cialis.mrdgeography.com/

  41. #41

    cialis 100mg price https://cialis.stdstory.com/

  42. #42

    Pretty great post. I just stumbled upon your weblog
    and wanted to say that I have really loved browsing your blog
    posts. In any case I’ll be subscribing for your rss feed and I am hoping you write once more soon! http://www.deinformedvoters.org/viagra-generic

  43. #43

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  44. #44

    Attractive part of content. I just stumbled upon your weblog and in accession capital to claim that I acquire actually enjoyed account your blog posts. Anyway I’ll be subscribing in your augment or even I fulfillment you access persistently quickly.

    http://www.zortilonrel.com/

  45. #45

    vidalista for bph reviews http://viidalista.co/

  46. #46

    Выживший смотреть онлайн просмотр

  47. #47

    At the same time, there is another side of the formation and organization of the utterance.

    my blog просмотр фильма

  48. #48

    http://cleantalkorg2.ru/

  49. #49

    Very well written information. It will be supportive to anybody who utilizes it, as well as me. Keep up the good work – i will definitely read more posts.

    http://www.vreyrolinomit.com/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。