CentOS 6 에서 cron 의 동작 방법 및 anacron 도입 이유
페이지 정보
작성자 관리자 (61.♡.26.29) 작성일 17-06-11 19:13 조회 3,155 댓글 0본문
센토스 6 에서 /etc/crontab 설정파일을 열어보면, 아래와 같이 별 내용이 없다.
[code]
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
[/code]
심지어 이전 버전에서는 존재하던 아래와 같은 run-parts 부분도 없다.
[code]
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[/code]
여기서 cron 의 동작 과정을 추적해 보자.
우선, cron 의 설정파일인 /etc/crontab 에는 위에서 본 바와 같이 아무것도 없다. ^^
그럼, cron 의 설정 디렉토리인 /etc/cron.d 에 들어가 보자.
0hourly 라는 것이 보인다. 열어 보자.
[code]
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
[/code]
뭔가 보인다.
매 1분마다 /etc/cron.hourly 폴더를 run-parts 한다.
/etc/cron.hourly 폴더에 들어가 보자.
빙고!
0anacron 파일이 보인다. 열어 보자.
[code]
#!/bin/sh
# Skip excecution unless the date has changed from the previous run
if test -r /var/spool/anacron/cron.daily; then
day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
exit 0;
fi
# Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power &> /dev/null
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s
[/code]
조건에 따라 그냥 exit 되기도 하고, 마지막에 anacron 이 실행이 된다.
anacron 의 설정파일은 /etc/anacrontab 파일이다. 열어보자.
[code]
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
[/code]
빙고! 찾았다! 여기에 cron.daily, cron.weekly, cron,monthly 가 등록되어 있다. ^^
그러면, anacron 시스템은 왜 도입되었을까?
위 anacrontab 설정파일 안에서 그 해답을 찾을 수 있다.
RANDOM_DELAY=45 라는 설정은 0분~45분(사이 랜덤) 지연시켜 실행한다는 내용이다.
즉, 한 서버 또는 서버간의 작업이 한꺼번에 몰려 부하가 집중되는 것을 막기 위해서
작업시간을 랜덤 지연시켜서 분산시키는 역할을 한다.
** 참고
https://www.php79.com/318
http://webdir.tistory.com/175
[code]
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
[/code]
심지어 이전 버전에서는 존재하던 아래와 같은 run-parts 부분도 없다.
[code]
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[/code]
여기서 cron 의 동작 과정을 추적해 보자.
우선, cron 의 설정파일인 /etc/crontab 에는 위에서 본 바와 같이 아무것도 없다. ^^
그럼, cron 의 설정 디렉토리인 /etc/cron.d 에 들어가 보자.
0hourly 라는 것이 보인다. 열어 보자.
[code]
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
[/code]
뭔가 보인다.
매 1분마다 /etc/cron.hourly 폴더를 run-parts 한다.
/etc/cron.hourly 폴더에 들어가 보자.
빙고!
0anacron 파일이 보인다. 열어 보자.
[code]
#!/bin/sh
# Skip excecution unless the date has changed from the previous run
if test -r /var/spool/anacron/cron.daily; then
day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
exit 0;
fi
# Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power &> /dev/null
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s
[/code]
조건에 따라 그냥 exit 되기도 하고, 마지막에 anacron 이 실행이 된다.
anacron 의 설정파일은 /etc/anacrontab 파일이다. 열어보자.
[code]
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
[/code]
빙고! 찾았다! 여기에 cron.daily, cron.weekly, cron,monthly 가 등록되어 있다. ^^
그러면, anacron 시스템은 왜 도입되었을까?
위 anacrontab 설정파일 안에서 그 해답을 찾을 수 있다.
RANDOM_DELAY=45 라는 설정은 0분~45분(사이 랜덤) 지연시켜 실행한다는 내용이다.
즉, 한 서버 또는 서버간의 작업이 한꺼번에 몰려 부하가 집중되는 것을 막기 위해서
작업시간을 랜덤 지연시켜서 분산시키는 역할을 한다.
** 참고
https://www.php79.com/318
http://webdir.tistory.com/175
추천0
댓글목록 0
등록된 댓글이 없습니다.