배너수익은 앱개발과 개선에 사용합니다.
[Centos 6.x crond (anacron)]
[root@localhost ~]# yum install crontabs
[root@localhost ~]# cat /etc/crontab
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
[root@localhost ~]#
[root@localhost ~]# ls -l /etc/cron.d
total 8
-rw-r--r-- 1 root root 113 Nov 10 2015 0hourly
-rw-r--r--. 1 root root 108 Oct 11 2013 raid-check
[root@localhost ~]# cat /etc/cron.d/0hourly
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
[root@localhost ~]#
[root@localhost ~]# ls -l /etc/cron.hourly/
total 8
-rwxr-xr-x 1 root root 409 Nov 10 2015 0anacron
-rwxr-xr-x. 1 root root 273 Nov 22 2013 mcelog.cron
[root@localhost ~]#
[root@localhost ~]# cat /etc/cron.hourly/0anacron
#!/bin/bash
# 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
[root@localhost ~]#
[root@localhost ~]# cat /etc/anacrontab
# /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
[root@localhost ~]#
$–> Field 1 is Recurrence period: This is a numeric value that specifies the number of days.
1 – daily
7 – weekly
30 – monthly
N – This can be any numeric value. N indicates number of days
@monthly’ for a job that needs to be executed monthly.
$–> Field 2 is Delay: This indicates the delay in minutes. i.e X number of minutes anacron should wait before executing the job after the the machine starts.
$–> Field 3 is Job identifier: It is the name for the job’s timestamp file. It should be unique for each job. This will be available as a file under the /var/spool/anacron directory. This file will contain a single line that indicates the last time when this job was executed.
$–> Field 4 is command: Command or shell script that needs to be executed.
START_HOURS_RANGE :- Interval, when scheduled jobs can be run, in hours, In case the time interval is missed, for example due to a power failure, the scheduled jobs are not executed that day.
RANDOM_DELAY :- maximum number of minutes that will be added to the delay in minutes variable which is specified for each job, The minimum delay value is set, by default, to 6 minutes. If RANDOM_DELAY is, for example, set to 12, then between 6 and 12 minutes are added to the delay in minutes for each job in that particular anacrontab. RANDOM_DELAY can also be set to a value below 6, including 0. When set to 0, no random delay is added. This proves to be useful when, for example, more computers that share one network connection need to download the same data every day.
[anacron 은 왜 도입되었나?]
1) 작업이 시작되는 시간을 매번 0분~45분 지연시켜 다른 서버들과 동일한 시간에 스케쥴 작업이 실행되는 부담을 줄인다.
기존 cron 에서는 /etc/cron.daily 를 매일 새벽 4시 2분에 실행하는 것이 기본값이었다. 만약 이 상황에서 rdate로 시간동기화를 time.bora.net으로 하도록 해두었다면 time.bora.net으로 새벽 4시 2분에 수많은 서버에서 동시요청을 하기 때문에 거의 DDOS 공격에 해당하게 되어 제대로 접속이 어려울 수 있다. 시간 동기화 외에도 VM이나 공유 스토리지를 사용하는 경우에도 모든 장비가 동시간에 부하가 발생하는 작업을 처리하는 것은 매우 비효율적일 것이다. 이러한 문제를 해결하는데 도움이 된다.
0분~45분 지연 시간은 /etc/anacrontab 설정의 RANDOM_DELAY=45 항목을 통해 변경할 수 있다.
2) 서버의 정지/장애 등으로 인한 매일/매주/매월 자동 실행 작업의 누락 가능성을 줄여준다.
이 부분은 자동 스케쥴러가 다소 복잡한 환경에서 유리하며 보다 자세한 내용을 알고 싶으신 분들은 다음 블로그 글을 참고한다.