centOS5.5 局域网定时任务与时间同步

   今天配置linux的时间同步,捎带的这就把定时任务也看了下。特此记录。

我在安装系统时没有安装ntp 所以在网上下了个RPM的包。 见附件。

安装 (rpm -i  ntp.rpm )后

如下步骤:

 

 写道

  • vi /etc/ntp.conf
              将“restrict default kod nomodify notrap nopeer noquery”这行修改成:使所有机器都可以同步该机器的时间
     restrict default nomodif

  • 关闭防火墙: #service iptables stop
  • 重新启动服务:
    ntpd -stop
    ntpd -start
  • 等待大概五分钟,再到其他机上同步该机器时间。
    ntpdate IP地址

定时任务:

使用命令crontab -e编辑一个定时执行的任务或在/var/spool/cron/目录下新建一个与自己用户名相同的文件

 写道
例如:
vi root
25 5,9,14,19 * * * /usr/sbin/ntpdate 192.168.18.2
5:25 9:25 14:25 19:25 同步一次系统时间
0 21 * * * /sbin/poweroff   晚上九点定时关机

顺便提一下crontab中的命令格式:
第一个 * 表示分钟 (0-59),
第二个 * 表示小时 (0-23),
第三个 * 表示月份中的某一天 (1-31),
第四个 * 表示一年中的某一月 (1-12),
第五个 * 表示一周中的星期几 (0-6 with 0=Sunday).
 


     停止cron进程,并重启,
     命令:/etc/init.d/crond stop
     /etc/init.d/crond start

猜你喜欢

转载自kaiy-ai.iteye.com/blog/1409740