[Linux] CentOS6 client server NTP同步配置

布满荆棘的人生 2022-08-21 02:20 288阅读 0赞

公司局域网,已经配置好了一台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

其他都是默认设置。

发表评论

表情:
评论列表 (有 0 条评论,288人围观)

还没有评论,来说两句吧...

相关阅读

    相关 NTP服务及时间同步(CentOS6.x)

    今有一小型项目,完全自主弄,原来以为很简单的NTP服务,我给折腾了2个多小时才整撑头(以前都是运维搞,没太注意,所以这技术的东西,在简单都需要亲尝啊),这里记录为以后别再浪费时

    相关 centos7 ntp时间同步

    一 应用场景 公司分配给你两台服务器,要求你使他们时间同步,有人问为什么要时间同步?如果一个集群中,时间相差很大,那么会出现很多诡异的问题,你也不想在一个无法解决的问题上浪费