症状描述:
[root@VM_58_118_centos ~]# cd /data //没有空间的情况下不要tab快捷键操作 /da-bash: cannot create temp file for here-document: 设备上没有空间 [root@VM_58_118_centos ~]# crontab -e /tmp/crontab.siEqwL: 设备上没有空间
查看磁盘空间使用率:
[root@VM_58_118_centos Uploads]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/vda1 7.8G 7.7G 0 100% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 24K 3.9G 1% /dev/shm tmpfs 3.9G 13M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vdb1 985G 594G 341G 64% /data tmpfs 783M 0 783M 0% /run/user/0
空间清理释放说明:
/dev/vda1是系统盘,
/data目录挂在在/dev/vdb1,建议用户日志,程序,数据文件都放在/data目录下,方便清理空间,清理/data目录下的文件,只会影响/dev/vdb1空间
清理/dev、/dev/shm、/run、/sys/fs/cgroup、/data之外的目录文件,就相当清理/dev/vda1的空间,如/opt
释放/dev/vda1空间:
[root@VM_58_118_centos xxx.net]# cd / [root@VM_58_118_centos /]# ll 总用量 80 dr-xr-xr-x. 19 root root 4096 12月 11 15:16 ./ dr-xr-xr-x. 19 root root 4096 12月 11 15:16 ../ -rw-r--r-- 1 root root 0 11月 26 2015 .autorelabel lrwxrwxrwx 1 root root 7 3月 11 2016 bin -> usr/bin/ dr-xr-xr-x. 4 root root 4096 3月 25 2016 boot/ drwxr-xr-x 20 root root 4096 12月 11 15:16 data/ drwxr-xr-x 18 root root 2920 10月 29 11:31 dev/ drwxr-xr-x. 108 root root 12288 12月 11 11:21 etc/ drwxr-xr-x. 8 root root 4096 12月 5 23:14 home/ lrwxrwxrwx 1 root root 7 3月 11 2016 lib -> usr/lib/ lrwxrwxrwx 1 root root 9 3月 11 2016 lib64 -> usr/lib64/ drwx------. 2 root root 16384 11月 25 2015 lost+found/ drwxr-xr-x. 2 root root 4096 8月 12 2015 media/ drwxr-xr-x. 2 root root 4096 8月 12 2015 mnt/ drwxr-xr-x. 7 root root 4096 11月 29 10:20 opt/ dr-xr-xr-x 208 root root 0 10月 29 11:31 proc/ dr-xr-x---. 12 root root 4096 12月 11 11:42 root/ drwxr-xr-x 27 root root 960 12月 3 21:12 run/ lrwxrwxrwx 1 root root 8 3月 11 2016 sbin -> usr/sbin/ drwxr-xr-x. 2 root root 4096 8月 12 2015 srv/ dr-xr-xr-x 13 root root 0 10月 29 11:31 sys/ drwxrwxrwx. 12 root root 4096 12月 11 15:04 tmp/ drwxr-xr-x. 14 root root 4096 9月 23 2016 usr/ drwxr-xr-x. 22 root root 4096 10月 29 11:31 var/
[root@VM_58_118_centos /]# du -smh * | sort -n
[root@VM_58_118_centos /]# cd /opt
[root@VM_58_118_centos opt]# du -smh * | sort -n
4.0K rh
11M kibana
11M remi
267M logstash
1.2G dbback
[root@VM_58_118_centos opt]# cd dbback
[root@VM_58_118_centos opt]# ll -h *
[root@VM_58_118_centos opt]# rm -f *.sql.tgz
[root@VM_58_118_centos opt]# df -h
文件系统 容量 已用 可用 已用% 挂载点 /dev/vda1 7.8G 5.9G 1.5G 80% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 24K 3.9G 1% /dev/shm tmpfs 3.9G 13M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vdb1 985G 594G 341G 64% /data tmpfs 783M 0 783M 0% /run/user/0
以/opt为例,同理清理/usr、/var目录
释放/dev/vdb1空间:
[root@VM_58_118_centos opt]# cd /data/
[root@VM_58_118_centos data]# du -smh * | sort -n
[root@VM_58_118_centos data]# cd /data/httpd/logs/
[root@VM_58_118_centos data]# ll -h
[root@VM_58_118_centos logs]# rm -f /data/scripts/logs/*.log
[root@VM_58_118_centos logs]# rm -f /data/httpd/logs/*access*
[root@VM_58_118_centos logs]# cat /dev/null > /data/logstash.log
[root@VM_58_118_centos logs]# /data/www/xxx.net/Uploads/app/apk 转存
[root@VM_58_118_centos logs]# /data/www/xxx.net/Uploads/ota 转存
清理nginx访问错误日志
[root@VM_58_118_centos logs]# rm -f /data/nginx/logs/*.log
关闭nginx访问日志
[root@VM_58_118_centos vhosts]# cat /data/nginx/vhosts/xxx.net.conf |grep access_log
#access_log /data/nginx/logs/xxx.net.access.log combined;
#access_log /data/nginx/logs/api.xxx.net.access.log combined;
#access_log /data/nginx/logs/chart.xxx.net.access.log combined;
#access_log /data/nginx/logs/chart.xxx.net.access.log combined;
#access_log /data/nginx/logs/chart.xxx.net.access.log combined;
#access_log /data/nginx/logs/bug.xxx.net.access.log combined;
#access_log /data/nginx/logs/blibao.xxx.net.access.log combined;
#access_log logs/host.access.log main;
#access_log /data/nginx/logs/dashboard.xxx.net.access.log combined;
[root@VM_58_118_centos vhosts]# systemctl restart nginx
关闭apache访问日志
[root@VM_58_118_centos data]# cat /etc/httpd/conf/extra/httpd-vhosts.conf |grep CustomLog
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/xxx.net-access-%y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/api.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/api.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/chart.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/myadmin.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/api.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/api.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/myadmin.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
#CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/myadmin.xxx.net-access-%Y%m%d.log 86400" common env=!IMAGE
[root@VM_58_118_centos logs]# systemctl restart httpd
清空mysql错误日志文件
[root@VM_58_118_centos data]# cat /etc/my.cnf|grep log-error
log-error=/data/mysql/logs/mysqld.log
[root@VM_58_118_centos logs]# cat /dev/null > /data/mysql/logs/mysqld.log
关闭mysql log-bin日志
[root@VM_58_118_centos data]# cat /etc/my.cnf|grep -n2 log-bin
46-#max_allowed_packet = 50M
47-
48:#关闭log-bin
49:#log-bin=/data/mysql/logs/log-bin.log
50-#expire_logs_days = 7
51-#binlog_format=statement
[root@VM_58_118_centos logs]# systemctl restart mysqld
总结:
刘超 10:31:18 产生的文件尽量放/data目录下,方便空间清理释放 刘超 10:31:48 关闭各种日志,或者定时清理日志文件apache、nginx、mysql等