跳至主要内容

centos cleanup disk space

1. Trim log files

find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;

This will truncate any *.log files on the volume /var that are either older than 7 days and greater than 50M or older than 30 days.

2. Cleanup YUM cache

The simple command to cleanup yum caches:

yum clean all

Note that the above command will not remove everything related to yum. For instance, metadata for disabled repositories will not be affected.

You may want to free up space taken by orphaned data from disabled or removed repositories:

rm -rf /var/cache/yum

Also, when you accidentally run yum through a regular user (forgot sudo), yum will create user-cache. So let’s delete that too:

rm -rf /var/tmp/yum-*

3. Remove orphan packages

Check existing orphan packages

package-cleanup --quiet --leaves 

Confirm removing orphan packages

Now, if happy with suggestions given by the previous command, run:

package-cleanup --quiet --leaves | xargs yum remove -y

4. Remove WP CLI cached WordPress downloads

WP CLI saves WordPress archives every time you setup a new WordPress website. You can remove those caches by the following command:

rm -rf /root/.wp-cli/cache/*
rm -rf /home/*/.wp-cli/cache/*

5. Remove old kernels

Before removing old kernels, you might want to simply reboot first in order to boot up from the latest kernel.
That’s because you can’t remove an old kernel if you’re booted into it 🙂

The following commands will keep just 2 latest kernels installed:

(( $(rpm -E %{rhel}) >= 8 )) && dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
(( $(rpm -E %{rhel}) <= 7 )) && package-cleanup --oldkernels --count=2

Note that with some VPS providers (Linode for example), servers use provider’s built kernels by default and not the ones on the server itself. So it makes little sense to keep more than 1 old kernel on the system. So:

(( $(rpm -E %{rhel}) >= 8 )) && dnf remove $(dnf repoquery --installonly --latest-limit=-1 -q)
(( $(rpm -E %{rhel}) <= 7 )) && package-cleanup --oldkernels --count=1

6. Remove Composer cache

rm -rf /root/.composer/cache
rm -rf /home/*/.composer/cache

7. Remove core dumps

If you had some severe failures with PHP which caused it to segfault and had core dumps enabled, chances are – you have quite a few of those.
They are not needed after you done debugging the problem. So:

find -regex ".*/core\.[0-9]+$" -delete

8. Remove error_log files (cPanel)

If you use the disgusting cPanel, you surely got dozens of error_log files scattered across your web directories. Much better if you can install the Citrus Stack. A temporary solution is to remove all those files:

find /home/*/public_html/ -name error_log -delete

9. Remove Node.js caches

rm -rf /root/.npm /home/*/.npm /root/.node-gyp /home/*/.node-gyp /tmp/npm-*

10. Remove Mock caches

Been building some RPM packages with mock? Those root caches can be quite large.
If you no longer intend to build RPM packages on a given machine:

rm -rf /var/cache/mock/* /var/lib/mock/*

P.S. the plan is to make this into an easily-installable app.

评论

此博客中的热门博文

老毛子路由器无线桥接问题

信道带宽:改成20M 关闭DHCP 服务器  关闭动态 (DHCP) 路由修改IP地址从192.168.123.1到192.168.1.114 无线 AP 工作模式:选择AP-Client+AP无线 AP-Client 角色:选择LAN bridge连上上级wifi done

路由器自身可能上不去网,执行:

route add default  gw 192.168.1.1

不过这种方式无法翻墙

//////////////////////////////////////////////////////////////

第二种方式
不改信道不关闭DHCP,保持网段是192.168.123.1无线 AP 工作模式:选择AP-Client+AP无线 AP-Client 角色:选择WAN连上上级wifi done

路由器可以翻墙,但是192.168.1.1的机器访问不了192.168.123.1的机器
解决方法:
在192.168.123.1的机器把想要访问的机器比如192.168.123.100设置DMZ主机,这样就可以访问了,在 192.168.1.1能看到分配的ip比如192.168.1.115

申请Oracle免费服务器

网址
https://www.oracle.com/cn/cloud/free/

首先注册账号,填国家china,地区一定要选好,因为免费的机器只能在home region,绑定手机,绑定信用卡。如果提示信用卡绑定失败,那么换个ip重试,比如开手机4G,或者挂VPN

账号申请了,开始申请机器,操作系统选centos7,比较简单,需要密钥
先生成
ssh-keygen -t rsa -N "" -b 2048 然后保存两个文件,id_rsa和id_rsa.pub,创建机器使用id_rsa.pub

机器创建好了,可以先telnet yourip 22试试ip是不是通的,如果不通,那么需要更换ip,比较绕
打开你的实例->左下角 附加的VNIC->查看详细->左下角 ip地址->编辑->改成没有公共ip->保存->再编辑,临时公共ip,或者预留ip。这样ip地址就更新了,刷几下就可以没有被ban。

然后用securecrt登陆,账号选择opc,会提示要pub,然后找到刚才的id_rsa.pub,连入成功。开始安装ss等软件。

安装好了,需要改一下防火墙配置
打开你的实例->虚拟云网络->左下角 安全列表->点进去->修改出入站规则

这时候telnet yourip ss端口,如果还是不行,在服务器执行sudo iptables -F,应该就可以了

一般缺点软件
sudo yum install lrzsz cmake gcc  gcc-c++ screen -y
最后
sudo yum update -y

要使用root
sudo su

js利用pako.js

首先引入js
<script src="pako.min.js"></script>

前端加上俩函数
    function unzip(b64Data){
        var strData   = atob(b64Data);
        // Convert binary string to character-number array
        var charData  = strData.split('').map(function(x){return x.charCodeAt(0);});
        // Turn number array into byte-array
        var binData   = new Uint8Array(charData);
        // // unzip
        var data    = pako.inflate(binData);
        // Convert gunzipped byteArray back to ascii string:
        strData   = new TextDecoder("utf-8").decode(data);
        alert(strData)
        return strData;
    }
    function zip(str){
         var binaryString = pako.gzip(encodeURIComponent(str), { to: 'string' })
         return btoa(binaryString);
    }

服务端先用 gzip然后base64
实际效果基本能节省一半
var b bytes.Bufferw := gzip.NewWriter(&b) defer w.Close() w.Write([]byte(data)) w.Flush() data = base64.StdEncoding.EncodeToString(b.Bytes())