1、安装ntp服务
yum install ntp*
2、修改配置文件
#restrict default kod nomodify notrap nopeer noquery #restrict -6 default kod nomodify notrap nopeer noquery # 将上面的两行注释掉(默认是拒绝所有机器访问的),添加下面一行 restrict default nomodify # 自定义只允许某些主机可以同步时间,事例: restrict 127.0.0.1 restrict 192.168.10.2 # 指定某台机器时间同步 restrict 192.168.0.0 mask 255.255.255.0 #允许192.168.0.0/254子网内主机时间同步 restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #允许任何主机跟进行时间同步 # 注释以下内容(如果可以访问外网可以保留,否则从以下机器同步,时间服务器不会生效) #server 0.rhel.pool.ntp.org iburst #server 1.rhel.pool.ntp.org iburst #server 2.rhel.pool.ntp.org iburst #server 3.rhel.pool.ntp.org iburst # 或是自己定义要同步的时间服务器IP server 10.128.14.25 # 上海交大ntp服务器:202.120.2.101 # 若果本地机器不从其他时间服务器同步时间,必须注释以上server里的内容,且添加以下内容 server 127.127.1.0 # 从本机同步 fudge 127.127.1.0 stratum 10 # 指定阶层编号为10,降低其优先度
以下为我实际配置的配置文件:
# For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift restrict default nomodify restrict 127.0.0.1 restrict -6 ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.rhel.pool.ntp.org iburst #server 1.rhel.pool.ntp.org iburst #server 2.rhel.pool.ntp.org iburst #server 3.rhel.pool.ntp.org iburst #broadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client #crypto includefile /etc/ntp/crypto/pw # with symmetric key cryptography. keys /etc/ntp/keys #statistics clockstats cryptostats loopstats peerstats server 127.127.1.0 fudge 127.127.1.0 stratum 10
3、客户端配置
echo “00 */1 * * * root /usr/sbin/ntpdate 10.10.10.10;/sbin/hwclock -w”>>/etc/crontab 每小时同NTP server进行一次时钟同步,并写入本机BIOS
手动同步:
ntpdate 10.10.10.10
4、注意事项:
(1)注释下面两项,添加第三项:
#restrict default kod nomodify notrap nopeer noquery #restrict -6 default kod nomodify notrap nopeer noquery restrict default nomodify
(2)如果没有在server里定义要同步的时间服务地址,添加以下两天配置,从本机同步
server 127.127.1.0 fudge 127.127.1.0 stratum 10
server 里定义的服务器地址一定要可以连通,否则时间服务器不会生效。
本文出自 “汪立明” 博客,请务必保留此出处http://afterdawn.blog.51cto.com/7503144/1887730
原文:http://afterdawn.blog.51cto.com/7503144/1887730