반응형
리눅스에서 삭제된 파일의 디스크 공간을 복구하는 방법
아파치 에러 로그(error_log 3.2G 사용)
$ df -h | egrep -v 'tmpfs'
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 98G 7.0G 91G 8% /
/dev/sda1 1014M 196M 819M 20% /boot
$ du -sh /var/log/httpd/
4.1G /var/log/httpd/
$ ls -alh /var/log/httpd/ | grep -v grep | grep error_log
-rw-r--r-- 1 root root 3.2G 5월 30 21:47 error_log
-rw-r--r-- 1 root root 1.7K 5월 30 21:46 ssl_error_log
아파치 에러 로그 삭제
$ rm -f /var/log/httpd/error_log
$ df -h | egrep -v 'tmpfs'
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 98G 6.1G 92G 7% /
/dev/sda1 1014M 196M 819M 20% /boot
$ du -sh /var/log/httpd/
8.3M /var/log/httpd/
$ ls -alh /var/log/httpd/ | grep error_log
-rw-r--r-- 1 root root 1.7K 5월 30 21:46 ssl_error_log
lsof 삭제된 파일 확인
- lsof -nP +L1
- lsof -nP | grep '(deleted)'
$ lsof -nP +L1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
httpd 4060 root 2w REG 253,0 3355443100 0 837515 /var/log/httpd/error_log (deleted)
httpd 4061 apache 2w REG 253,0 3355443100 0 837515 /var/log/httpd/error_log (deleted)
httpd 4062 apache 2w REG 253,0 3355443100 0 837515 /var/log/httpd/error_log (deleted)
httpd 4063 apache 2w REG 253,0 3355443100 0 837515 /var/log/httpd/error_log (deleted)
httpd 4064 apache 2w REG 253,0 3355443100 0 837515 /var/log/httpd/error_log (deleted)
httpd 4065 apache 2w REG 253,0 3355443100 0 837515 /var/log/httpd/error_log (deleted)
(or)
$ lsof -nP | grep '(deleted)'
httpd 4060 root 2w REG 253,0 3355443100 837515 /var/log/httpd/error_log (deleted)
httpd 4061 apache 2w REG 253,0 3355443100 837515 /var/log/httpd/error_log (deleted)
httpd 4062 apache 2w REG 253,0 3355443100 837515 /var/log/httpd/error_log (deleted)
httpd 4063 apache 2w REG 253,0 3355443100 837515 /var/log/httpd/error_log (deleted)
httpd 4064 apache 2w REG 253,0 3355443100 837515 /var/log/httpd/error_log (deleted)
httpd 4065 apache 2w REG 253,0 3355443100 837515 /var/log/httpd/error_log (deleted)
/proc에서 열린 fd(file descriptor)를 찾기
$ file /proc/4060/fd/2
/proc/4060/fd/2: broken symbolic link to `/var/log/httpd/error_log (deleted)'
$ ls -al /proc/4060/fd/2
l-wx------ 1 root root 64 5월 30 21:46 /proc/4060/fd/2 -> /var/log/httpd/error_log (deleted)
파일 크기 자르기
- truncate -s 0 /proc/{PID}/fd/{FD}
- echo > /proc/{PID}/fd/{FD}
$ truncate -s 0 /proc/4060/fd/2
(or) $ echo > /proc/4060/fd/2
파일 시스템 용량 확인
$ df -h | grep -v tmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 98G 3.0G 95G 4% /
/dev/sda1 1014M 196M 819M 20% /boot
728x90
반응형
'리눅스' 카테고리의 다른 글
Ansible setup 모듈(setup module)을 사용하는 방법 (0) | 2021.06.03 |
---|---|
ansible inventory(인벤토리) 설정 (0) | 2021.06.01 |
[리눅스] ab(Apache Bench) tools 에러 (0) | 2021.05.30 |
CentOS 7에서 MongoDB Community Server를 설치하는 방법 (0) | 2021.05.28 |
리눅스 Load Average (0) | 2021.05.26 |