Linux 서버용 단순 디스크 공간 모니터
Linux 서버는 사용 가능한 디스크 공간이 0%에 도달하면 중지하므로 디스크 공간이 매우 부족할 때를 아는 것이 매우 중요합니다. 따라서 경고, 자동 경고, 이메일 자동 경고가 필요합니다.
이 (간단한) 가이드를 보려면 다음을 사용하십시오.
시작하기 전에 postfix 서비스 상태를 확인하거나 다시 시작하거나 설치 및 구성
보기 상태를 보려면 터미널을 열고 다음을 입력하십시오.
sudo systemctl status postfix
Postfix가 설치되지 않은 경우 다음과 같이 표시하십시오.

Postfix가 설치되었지만 실행 중이 아닌 경우 다음과 같이 표시됩니다.

"sudo systemctl start postfix"를 입력하면 문제가 해결될 수 있습니다.
Postfix가 설치되고 실행되면 다음을 표시합니다.

시스템 관리자에게 모든 것을 확인하십시오. 그러나 귀하가 시스템 관리자라면 신이 우리를 도와주세요!!! 신 = Google 또는 StackOverflow 또는 https://www.cyberciti.biz/
첫 번째 단계: bash 스크립트 모니터 만들기
하드 드라이브 공간을 확인하는 코드로 bash 스크립트를 만듭니다.
터미널을 열고 다음을 입력합니다.
nano /usr/diskSpace.sh
그런 다음 이 코드를 붙여넣습니다(먼저 읽고 이해하면 매우 간단하지만 유용합니다)
#!/bin/bash
#a simple script that warn me about low disk space for partition in linux
#this script send a email when disk partition reach a DISKLIMIT
#to sysadmin ninja guy use a jutsu and save the world
#usign command df -h grep and contrab you get an email for low hard disk space in partitions
#You need and email server running like postfix (maybe sendmail)
#here and practical example to reach a postfix mail server, you choose: http://www.postfix.org/STANDARD_CONFIGURATION_README.html
PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
export $PATH
#ADDRESS FOR SERVER
DIRIP=$(/sbin/ifconfig | awk -F':' '/inet/&&!/127.0.0.1/{split($2,_," ");print _[1]}')
#EMAIL ACCOUNTS SENDER AND RECEIBERS
SENDERS="[email protected]"
RECEIBERS="[email protected] [email protected] [email protected] [email protected]"
#RED LINE FLAG TO SEND AN EMAIL
DISKLIMIT=80
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
usep=$(echo $output | awk '{print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ "$usep" -ge "$DISKLIMIT" ]; then
echo -e $DIRIP"\n The disk space for some partitions is very low \n\n Please read the following report and do something: \n\nFor partition $partition space used is $usep % \n\n This report was generated at: $(date)" |
mail -s "[SOME SERVER] VERY LOW DISK SPACE "${DIRIP}" " -a "From: "${SENDERS}" "${RECEIBERS}
fi
done
service postfix restart
테스트 제안을 위해 DISKLIMIT를 수정하여 실행하고 이메일을 받을 수 있습니다.
두 번째 단계: 1분마다 cron 작업 포함
cron 작업을 사용하면 몇 분, 몇 시간, 몇 일, 몇 주 만에 스크립트를 실행할 수 있습니다. 서버는 매분 내 스크립트/usr/diskSpace를 실행한 다음 파티션이 DISKLIMIT 퍼센트 접미사에 도달하여 이메일을 보냅니다. 주말을 포함하여 적시에 통보하려면 DISKLIMIT를 계산하거나 휴가를 수정하십시오.
터미널을 열고 다음을 입력하십시오.
sudo nano /etc/crontab
이것은 crontab 템플릿입니다. 맨 아래에 추가하십시오.
* * * * * root sh /usr/diskSpace.sh
그런 다음 매분 서버는/usr/diskSpace.sh를 실행하고 하드 디스크 공간이 부족한 파티션에 대해 이메일을 보낼 수 있습니다.
이 간단한 가이드는 좋은 결과에 도달하기 위해 ciberciti.biz tuts를 읽고 Debian, freeBSD, Ubuntu 및 CentOS에서 테스트를 작성했습니다.
읽어 주셔서 감사합니다.
Reference
이 문제에 관하여(Linux 서버용 단순 디스크 공간 모니터), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/sentadoensilla/simple-disk-space-monitor-for-linux-servers-1ahf텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)