设置LINUX系统时间的更新同步

来源:互联网 发布:sublime text3 python 编辑:程序博客网 时间:2024/05/01 14:23
首先有两种方法

第一种:是开启ntp服务
1.#service ntp start
注:开启ntp 服务  如果没有 自行安装(yum在线安装ntp#yum -yinstall ntp)
2.chkconifg ntp on #开启自动启动
第二种:用计划任务来更新
1.crontab -e#  在里面写计划任务
*/15 * * * *  /usr/sbin/ntpdate0.centos.pool.ntp.org && /sbin/hwclock -w
注:0.centos.pool.ntp.org:是时间服务器,可以先择别的
*  *  *  *  *  command
分  时  日  月 周   命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
crontab文件的一些例子:
30 21 * * * /etc/init.d/smb restart
上面的例子表示每晚的21:30重启smb 。
45 4 1,10,22 * * /etc/init.d/smb restart
上面的例子表示每月1、10、22日的4 : 45重启smb 。
10 1 * * 6,0 /etc/init.d/smb restart
上面的例子表示每周六、周日的1 : 10重启smb 。
0,30 18-23 * * * /etc/init.d/smb restart
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启smb 。
0 23 * * 6 /etc/init.d/smb restart
上面的例子表示每星期六的11 : 00 pm重启smb 。
* */1 * * * /etc/init.d/smb restart
每一小时重启smb
* 23-7/1 * * * /etc/init.d/smb restart
晚上11点到早上7点之间,每隔一小时重启smb
0 11 4 * mon-wed /etc/init.d/smb restart
每月的4号与每周一到周三的11点重启smb
0 4 1 jan * /etc/init.d/smb restart
一月一号的4点重启smb
 
-w是把软件时钟写到硬件时钟 
-s 是把硬件时候写到系统里
可以运行hwclock --help查看
-s, --hctosys    setthe system time from the hardware clock 
-w, --systohc    setthe hardware clock from the current system time
 
在有些linux版本里,需要把任务重定向输出到某个文件或设备,如果没有后面的重新定向,当任务激活时,会自动发邮件。每执行一次,都会给系统邮箱发一次邮箱,执行次数频繁的话,,那邮件提醒会发爆你的邮箱!!!
 
参考文章:http://blog.csdn.net/hijiankang/article/details/8306798
0 0