centos中ntp安装配置的一些问题

生产环境因为要为服务器配置ntp,从而让时间保持同步:
centos6.7 服务器作为服务器端:
yum install ntp ntpdate -y
注意:因为你用的yum源不同,安装的ntp偶尔会有一些问题,可能你会遇见,后面介绍
cp /etc/ntp.conf{,.bak} #备份配置文件

服务器端的时间同步的地方:
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst

/etc/init.d/ntpd stop
/etc/init.d/ntpd start
或者
systemctl stop ntpd.service
systemctl start ntpd.service

服务器端配置好了,自己测试下
ntpdate -u 192.168.83.12
注意:如果出现问题的排错思路
1.网络ping通能否
2.是否关闭防火墙
3.是否关闭selinux
4.server服务器中配置文件中的定义的文件是否生成存在,因为用到的镜像包不同,导致生成的服务偶尔会有差异。
我的用的ali源安装,跟用光盘安装的ntp服务就有差别:
ali安装:driftfile /var/lib/ntp/drift 已经生成
镜相安装:driftfile /var/lib/ntp/drift不存在,需要自己创建,添加5.994进去,自己创建注意属主属组问题(ntp:ntp),否则ntpdate或者ntpq -p会报错,出现问题。

centos 7.3作为客户端
yum install ntp ntpdate -y

注释存在的server内容如下:
#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.83.12 prefer #主时间服务器ip地址
(可以添加多个)
logfile /var/log/ntp.log #启动ntpd进程后,查看此文件是否正常生成

同步硬件时间:
hwclock --systohc #同步硬件时间
vim /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes

systemctl enable ntpd.service
systemctl stop ntpd.service
ntpdate 192.168.83.12
systemctl start ntpd.service
ntpq -p
注意:1.ntpdate执行目的是防止时间相差过大,如果相差过大,那么ntp服务不会同步的。同时,执行ntpdate时候需要先关闭ntp服务才行。

2.同样需要注意上面提到的不同镜像文件是否生成问题。

正常结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值