网站首页 > 技术教程 正文
NTP:NTP 是网络时间协议(Network Time Protocol),它是用来同步网络
中各个计算机时间的协议。其对时精度在局域网内可达 0.1ms,且相较于
ntpdate 方式,ntp 对时更加平滑,不会造成时间跳跃式突变。
1.操作安系统出厂默认已安装 ntp 包,但 ntp 服务未自启动,需要进行
配置后再行启动,配置文件为/etc/ntp.conf,ntp 服务使用的端口号是 123,
使用 rpm -qa | grep ntp 命令查询当前系统是否已安装 ntp 包。
2. 客户端配置
vi /etc/ntp.conf 文件,找到如下内容
server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
将这默认 4 行 server 开头的行添加#注释,并在上面添加一行:
server <时钟设备对时的 IP 地址> iburst 如下图所示
3. 服务端配置
vi /etc/ntp.conf 文件,添加内容
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
//表示允许 192.168.1.0 网段所有的机器与该服务器进行对时
server 127.127.1.0
//在不联网的时候可以把本机时间作为同步时间源
fudge 127.127.1.0 stratum 10
//设置 ntp 优先级。stratum 取值是 0-16,数字越小优先级越高
4. 服务端和客户端都启动 ntp 服务并设置开机自启动
systemctl start ntpd.service
systemctl enable ntpd.service
在客户端查看与服务端的对时状态:ntpq -p
用 date 命令查看客户端和服务端的时间是否一致。
最后使用crontab -e 添加一个定时任务,让系统定时去执行任务。
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/300 * * * * /usr/sbin/ntpdate -u 192.168.1.1 >/dev/null 2>&1
猜你喜欢
- 2025-05-08 Linux高性能服务器设计(linux高性能服务器编程:使用muduo c++网络库)
- 2025-05-08 CentOS系统时间 ( utc)与现在时间(cst)相差8小时解决方法
- 2025-05-08 linux实例之设置时区的方式有哪些
- 2025-05-08 CentOS7下使用Lsyncd实现文件实时同步
- 2025-05-08 Redis数据持久化机制、主从同步原理、常见规范与优化详解
- 2025-05-08 linux服务器开发之网关服务器的实现
- 2025-05-08 耗时很长的程序忘加nohup就运行了怎么办?
- 2025-05-08 手绘10张图,细谈Redis 持久化,详解RDB和AOF及混合机制
- 2025-05-08 开源的Linux文件同步工具有哪些?(linux 文件同步方案)
- 2025-05-08 如何使用Rsync同步两个网站服务器的内容
你 发表评论:
欢迎- 最近发表
-
- linux日志文件的管理、备份及日志服务器的搭建
- Linux下挂载windows的共享目录操作方法
- Linux系统中的备份文件命令(linux系统中的备份文件命令有哪些)
- 麒麟KYLINOS|通过不同方法设置用户访问文件及目录权限
- 「Linux笔记」系统目录结构(linux目录的结构及含义)
- linux中修改归属权chown命令和chgrp命令
- 工作日报 2021.10.27 Android-SEAndroid权限问题指南
- Windows和Linux环境下,修改Ollama的模型默认保存路径
- 如何强制用户在 Linux 上下次登录时更改密码?
- 如何删除Linux文件夹中除某些扩展名之外的所有文件?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)