时间服务器


1.手动修改时间

通过连接工具的并发命令功能,同时运行命令修改时间

[root@redis05 ~]# date -s "2019-05-25 17:00:00"

image.png

2.使用公网时间服务器

linux服务器作为client端,直接同步公网时间

210.72.145.44国家授时中心服务器IP地址
ntp.ntsc.ac.cn中国科学院国家授时中心NTP授时服务器地址
ntp.tencent.com腾讯云
ntp1.tencent.com
ntp2.tencent.com
ntp3.tencent.com
ntp4.tencent.com
ntp5.tencent.com
ntp.aliyun.com阿里云
# 安装工具
[root@redis05 ~]# yum install ntp ntpdate -y
# 同步网络时间
[root@redis05 ~]# ntpdate ntp.ntsc.ac.cn
# 设置计划任务,定时自动更新时间
[root@redis05 ~]# crontab -e
*/10 * * * * /usr/sbin/ntpdate ntp.ntsc.ac.cn	# 每十分钟执行一次
[root@redis05 ~]# crontab -l
*/10 * * * * /usr/sbin/ntpdate ntp.ntsc.ac.cn	

image.png

3.自建时间服务器

使用ntpd server为多台服务器同步时间

  1. 客户端机器安装ntpdate

[root@redis06 ~]# yum install ntpdate -y

  1. 服务端安装ntp

[root@redis05 ~]# yum install ntp -y

  1. 服务端编辑配置文件
[root@redis05 ~]# vim /etc/ntp.conf
restrict 127.0.0.1		# 给予本机所有权限
#restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap		# 给予局域网的机器同步时间的权限
#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 ntp.ntsc.ac.cn prefer		# 设置时间服务器,prefer表示优先使用。
server 127.127.1.0							# local clock
fudge  127.127.1.0 startum 10
[root@redis05 ~]# systemctl start ntpd
[root@redis05 ~]# systemctl enable ntpd
  1. 客户端同步时间测试
[root@redis06 ~]# ntpdate 192.168.1.13
# 回显如下
22 Oct 08:00:39 ntpdate[7118]: step time server 192.168.1.13 offset -330920678.361349 sec
  1. 客户端设置定时任务,自动同步时间
[root@redis06 ~]# crontab -e
*/10 * * * * /usr/sbin/ntpdate 192.168.1.13 >> /root/ntpdate.log 2>&1

image.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值