您的位置:首页 > 运维架构 > Linux

CentOS6 client server NTP同步配置

2016-03-11 13:46 351 查看
公司局域网,已经配置好了一台NTP服务器,现配置客户机与服务端时间同步。

 

方法一:

crontab定时任务,ntpdate同步客户机与NTP服务器时间

每天7:30同步时间,并写入BIOS

[root@VMServer etc]# crontab -l
30 7 * * * /usr/sbin/ntpdate 10.191.130.130; /sbin/hwclock -w
[root@VMServer etc]#

 

方法二:

ntpd既是服务器端,又是客户端。

1)作为客户端运行时,修改ntp.conf文件增加server 192.168.1.1

vi /etc/ntp.conf

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

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 192.168.1.1

2)ntpd设为开机启动并运行:

[root@VMServer etc]# chkconfig ntpd on
[root@VMServer etc]# chkconfig | grep ntpd

ntpd            0:off 1:off 2:on 3:on 4:on 5:on 6:off

ntpdate         0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@VMServer etc]# service ntpd start
Starting ntpd:                                             [  OK  ]

[root@VMServer etc]# service ntpd status

ntpd (pid  9897) is running...

[root@VMServer etc]#

 

两种方法的区别:

ntpd在实际同步时间是一点点的校准过来时间的,最终把时间慢慢的矫正对。

而ntpdate不会考虑其他程序是否会阵痛,直接调整时间。

一个是校准时间,一个是调整时间。

 

备注:

ntpd既是服务器端,也是客户端

作为服务器运行时:

1)修改/etc/ntp.conf增加

restrict 127.0.0.1

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

2)运行:

service ntpd start

作为客户端运行时:

1)修改/etc/ntp.conf增加

server 192.168.1.1

2)运行:

service ntpd start

其他都是默认设置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: