NTP时间同步
1
|
<br> |
(一).NTP服务端端配置
-
NTP服务器安装
1
2
3
4
5
|
[[email protected] ~] # rpm -qa ntp
ntp-4.2.6p5-5.el6.centos.x86_64 [[email protected] ~] #
没有的话就安装 [[email protected] ~] # yum -y install ntp
|
2修改NTP的配置文件,并保存退出
1
2
3
4
5
6
7
8
9
10
11
|
[[email protected] ~] # vim /etc/ntp.conf
#restrict default kod nomodify notrap nopeer noquery #restrict -6 default kod nomodify notrap nopeer noquery restrict default nomodify #nomodify客户端可以同步
#server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server ntp1.aliyun.com # 默认时间同步源改为阿里的和另外一个
server time .nist.gov
|
3..本地定时任务如果有同步时间的定时任务,注释时间同步的定时任务
1
2
3
4
|
[[email protected] ~] # crontab -l
#set by sanlang to get consistent time #*/5 * * * * /usr/sbin/ntpdate time.nist.gov>/dev/null 2>&1 [[email protected] ~] #
|
4..启动NTP服务器
1
2
3
4
5
6
|
[[email protected] ~] # /etc/init.d/ntpd start
[[email protected] ~] # ntpstat
synchronised to NTP server (182.92.12.11) at stratum 3 time correct to within 7946 ms
polling server every 64 s
[[email protected] ~] #
|
(二).NTP客户端配置(第一次会有一定的延迟)
1
2
3
4
|
[[email protected] ~] # ntpdate 10.0.0.61
22 May 23:14:48 ntpdate[11916]: step time server 10.0.0.61 offset 12727.969441 sec
[[email protected] ~] # echo "* * * * /usr/sbin/ntpdate 10.0.0.61" >>/var/spool/cron/root
客户端将这个命令写入定时任务中就可以了,最好先写注释 |
反思:1.可以用分发机分发定时任务
2.NTP服务器端时间会出现单点故障,所以要至少有两台
3.客户端做定时任务看需求,多长时间同步一次
本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1776040,如需转载请自行联系原作者