linux ntp 时间服务器

本文档详细介绍了在Linux系统中关闭selinux和firewall、禁用chronyd服务、设置时区为上海、安装及配置ntp服务、检查ntp连接状态以及手动同步和保存时间的步骤。通过这些操作,确保系统时间准确并与上级ntp服务器保持同步。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

1. 关闭selinux、firewall 

2. 关闭chronyd时间服务

3. 调整系统时区为亚洲上海【shanghai】

4. 安装ntp服务

5. 配置并启动ntp

6. 查看ntp是否与上层ntp连通

7. 查看ntp与上层的状态

8. 手动与ntp服务器同步时间

9. 将时间写入BIOS

10. 总结


1. 关闭selinux、firewall 

#     注意:生产环境,要开启防火墙,并仅允许 ntp的协议和端口

#     ntp使用UDP协议的123端口

sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
setenforce 0
systemctl disable firewalld.service
systemctl stop firewalld.service
systemctl status firewalld.service

2. 关闭chronyd时间服务

systemctl stop chronyd.service
systemctl disable chronyd.service

3. 调整系统时区为亚洲上海【shanghai】

timedatectl set-timezone Asia/Shanghai

4. 安装ntp服务

yum -y install ntp

5. 配置并启动ntp

egrep -v "^#|^$" /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify     # 允许任何IP进行时间同步
restrict 127.0.0.1 
restrict ::1
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

 

 

 

 

 

 

 

systemctl enable ntpd.service 
systemctl start ntpd.service 

6. 查看ntp是否与上层ntp连通

ntpstat

#     由上可知我们处于地3层,因为我们是从第2层同步时间的

7. 查看ntp与上层的状态

ntpq -p

8. 手动与ntp服务器同步时间

ntpdate -u 0.cn.pool.ntp.org

9. 将时间写入BIOS

hwclock -r	# 查看BIOS时间
hwclock -w	# 将系统时间写入到BIOS

10. 总结

# ntpd         同步是平滑同步

# ntpdate    依赖ntp服务器,是立即同步,不管之前的时间是多少

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值