CentOS清除SSH登录记录、历史命令及日志缓存
清除 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
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/
how to use dapoxetine citrate https://salemeds24.wixsite.com/dapoxetine
stromectol 3 mg tablets price https://ivermectin.mlsmalta.com/
african ivermectin ingredients https://ivermectin.webbfenix.com/
how much vidalista is safe https://vidalista.mlsmalta.com/
hydroxychloroquine 200mg for lupus https://hydroxychloroquine.mlsmalta.com/
hydroxychloroquine coronavirus success https://hydroxychloroquine.webbfenix.com/
does viagra work on women http://droga5.net/
dapoxetine 60 mg in uk https://dapoxetine.confrancisyalgomas.com/
generic professional vidalista https://vidalista40mg.mlsmalta.com/
albuterol ipratropium vs albuterol sulfate https://amstyles.com/
is generic cialis real https://wisig.org/
cost of prescription drugs without insurance https://edmeds.buszcentrum.com/
60mg priligy daily side effects https://ddapoxetine.com/
black cialis 1000mg https://tadalafili.com/
Cialis Vs Viagra Reviews Easettenex is cialis generic Alicky prix levitra 10 acheter
buy hydroxychloroquine from canada https://sale.azhydroxychloroquine.com/
compare drug prices in canada https://medpills.bee-rich.com/
compare drug prices in canada https://buymeds.mlsmalta.com/
plaquenil dosage based on weight https://hydroxychloroquinee.com/
vidalista adcirca 20mg https://vidalista.buszcentrum.com/
generic cialis http://cialllis.com/
generic cialis cialis australia https://tadalafil.cleckleyfloors.com/
can you mix cialis and alcohol http://tadalafila.online/
try this out…
pussy888
need money today
sildalis 100mg 20mg
tadalafil price in canada
installment loan guaranteed approval
loan payday
Very useful ! Thank U
วิธีดูราคาบอล
vidalista 20 reviews http://vidallista.com/
advanced cash
cialis 2.5 mg
buy cialis https://cialzi.com/
hydroxychloroquine brands http://hydroxychloroquined.online/
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
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/
You are a very bright individual!
http://www.vreyrolinomit.com/
cialis 100mg price https://cialis.mrdgeography.com/
cialis 100mg price https://cialis.stdstory.com/
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
buy hydroxychloroquine online https://hydroxychloroquinex.com/
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/
vidalista for bph reviews http://viidalista.co/
Выживший смотреть онлайн просмотр
At the same time, there is another side of the formation and organization of the utterance.
my blog просмотр фильма
http://cleantalkorg2.ru/
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/