Centos 6.x crond (anacron) > 주인장(개발자) 로그 - [Unknown]

본문 바로가기

사이트 내 전체검색


현재: 약 50만 다운로드 / 목표: 글로벌 5,000만 다운로드 이상
인기 국가: 한국,인도,미국,홍콩,오스트리아,일본,스위스
프랑스,캐나다,이탈리아,오스트레일리아,영국,스페인

[ Android Application Links ]
Since 2011.03

ⓐ 정각알림(OnTimeAlarm)
ⓑ 알람포미(Alarm4Me)
ⓒ 플래시온(FlashOn)
ⓓ 와이파이온오프위젯
    (WifiOnOff4 Widget)

ⓔ 폴더플레이어포미
    (FolderPlayer4Me)

ⓕ 리코더포미(Recorder4Me)
ⓖ 리사이즈픽포미
    (ResizePic4Me)

ⓗ 언인스톨러포미
    (Uninstaller4Me)

ⓘ 배터리포미(Battery4Me)
ⓙ 볼륨맨포미
    (Volumeman4Me)


주인장(개발자) 로그

Linux | Centos 6.x crond (anacron)

페이지 정보

작성자 주인장 작성일2016. 06. 30. 00:56 조회23,543회 댓글0건

본문

[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 ~]#

[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) 서버의 정지/장애 등으로 인한 매일/매주/매월 자동 실행 작업의 누락 가능성을 줄여준다.
이 부분은 자동 스케쥴러가 다소 복잡한 환경에서 유리하며 보다 자세한 내용을 알고 싶으신 분들은 다음 블로그 글을 참고한다.


  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글목록

등록된 댓글이 없습니다.

주인장(개발자) 로그 목록

게시물 검색


상단으로
안드로이드 애플리케이션 테스트에 사용하고 있는 스마트폰들
Galaxy Folder2(Android 6.0), Galaxy S10+(Android 11), LG V50(Android 10), Galaxy S9+(Android 10), Redmi Note7(Android 9)
Galaxy S7(Android 8.0), Galaxy S5(Android 6.0), Nexus 5x(Android 8.1), G4(Android 7.0), Redmi 4 Prime(Android 6.0)
PC 버전으로 보기