ubuntu下ntp时间同步
2022/8/5 5:22:59
本文主要是介绍ubuntu下ntp时间同步,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 首先安装ntp服务(ubuntu 16.02)
在linux的root用户下执行以下命
sudo apt-get install ntp
(如果不是ubuntu系统则执行 yum install ntp –y)
2. 修改ntp配置文件(server)
我们需要在linux集群中找到一台作为ntp服务器的server,其他机器则为ntp的client,因此,在server服务器上修改一下配置文件
执行
退出保存,重启ntp服务
执行 service ntp restart
vim /etc/ntp.conf:
#linux自带的时间同步,需要注释掉 #pool 0.ubuntu.pool.ntp.org iburst #pool 1.ubuntu.pool.ntp.org iburst #pool 2.ubuntu.pool.ntp.org iburst #pool 3.ubuntu.pool.ntp.org iburst # Use Ubuntu's ntp server as a fallback. #pool ntp.ubuntu.com # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 #因为是内网,所以用本地时间做为服务器时间,注意这里不是127.0.0.1 server 127.127.1.0 fudge 127.127.1.0 stratum 8 #开放192.168.8.0 整个网段,即在这个网段的所有机器都可以使用 214 作为时间同步服务端 restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
3. 修改ntp配置文件(client)
同样的server端已经配置好了,client的配置相对简单
执行 sudo vim /etc/ntp.conf:
#linux自带的时间同步,需要注释掉 #pool 0.ubuntu.pool.ntp.org iburst #pool 1.ubuntu.pool.ntp.org iburst #pool 2.ubuntu.pool.ntp.org iburst #pool 3.ubuntu.pool.ntp.org iburst # Use Ubuntu's ntp server as a fallback. #pool ntp.ubuntu.com # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 #增加214作为时间服务器即可 server 192.168.0.214 # Needed for adding pool entries restrict source notrap nomodify noquery
退出保存,重启ntp服务
执行 sudo service ntp restart
4. 查看ntp服务是否配置完成
在ntp sever上执行 ntpq -p
在ntp client上执行 ntpq –p
即完成ntp服务的配置
5. ntp服务的相关命令
service ntpstart 启动
service ntp stop停止
service ntprestart 重新启动
ubuntu更改时区(东八区) tzselect
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
这篇关于ubuntu下ntp时间同步的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?