网站首页 > 技术教程 正文
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同步两个网站服务器的内容
欢迎 你 发表评论:
- 12-14windows系统下载msdn(win10 2004下载msdn)
- 12-14电脑怎么把360卸载干净(如何将电脑360完全卸载)
- 12-14deepin 应用商店(deepin应用商店页面加载错误)
- 12-14手机照片怎么改成300k的软件
- 12-14手机怎么查看自己的qq邮箱号
- 12-14系统装机软件排行榜(最好用的装机系统)
- 12-14win10安装包打不开(win10有些安装包打不开)
- 12-14金士顿官网序列号查询(金士顿序列码查询)
- 最近发表
- 标签列表
-
- 下划线是什么 (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)

本文暂时没有评论,来添加一个吧(●'◡'●)