Centos配置ntp时间同步

1.修改机器本地时间为标准时区时间

# 操作系统版本检查
cat /etc/redhat-release

# 操作系统默认语言检查
echo $LANG
echo 'export LANG=en_US.UTF-8' >> ~/.bashrc

# 操作系统时区设置
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

2.安装ntp

# 检查npt安装版本
yum list installed | grep ntp

# 安装ntp(所有同步机器都要安装)
yum -y install ntp

# 非时间服务器(主)都安装ntpdate服务
yum install -y ntpdate

3.配置ntp时间同步

3.1配置ntp服务端(主)

#####
# 注释掉
#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 127.127.1.0
Fudge 127.127.1.0 stratum 10
#####

3.2配置npt客户端,除了服务端都要配置

#####
# 注释掉
#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.26.21
Fudge 192.168.26.21 stratum 10
#####

4.启动ntp

# 启动ntp
service ntpd start

# 设置开机启动
systemctl enable ntpd.service

# 查看状态
systemctl status ntpd.service

5.检查ntp同步状态

# 查看同步的是哪台服务器
ntpq -p
异常处理:localhost: timed out, nothing received
                   ***Request timed out
问题:因为开启了Ipv6 ,默认ntpq 先走Ipv6的通道,而ECS  linux 默认无法直接访问ipv6地址,因此会访问超时
修改配置:永久关闭ipv6

# 重启生效
service ntpd restart
##### 添加如下参数
# 禁用整个系统所有接口的IPv6
net.ipv6.conf.all.disable_ipv6 = 1
# 禁用某一个指定接口的IPv6(例如:eth0, eth1)
# net.ipv6.conf.eth1.disable_ipv6 = 1
# net.ipv6.conf.eth0.disable_ipv6 = 1
#####

6.时间差:ntpstat

异常1处理:inappropriate address 192.168.26.21 for the fudge command, line ignored

修改配置:vi /etc/ntp.conf

将fudge 192.168.26.21 stratum 10 改成 Fudge 192.168.26.21 stratum 10

7.同步时间

ntpdate bigdata01

8.定时同步时间

通过crontab编写定时任务

crontab -e

# 添加如下内容

29,59 * * * * /usr/sbin/ntpdate bigdata01 # 每小时的第29分和59分同步一次时间

到达时间点后通过date命令查看时间是否已经同步,当然配置间隔时间更短的任务,这样可以更快的看到效果。

参数hwclock -w

*/10 * * * * /usr/sbin/ntpdate 11.125.0.3;hwclock -w

hwclock -w 命令的参数 -w 代表“同步”,其全称是 --sync。这个参数的作用是将系统时间(由 /usr/sbin/ntpdate 设置的)同步到硬件时钟。简而言之,hwclock -w 将内存中的系统时间写入到硬件时钟中,确保即使在系统关闭后,硬件时钟也能保持正确的时间。

9.参考:离线安装NTP

参考:Linux完全离线RPM安装NTP(时间同步)服务器及基本配置-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大数据探索者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值