1.手动修改时间
通过连接工具的并发命令功能,同时运行命令修改时间
[root@redis05 ~]# date -s "2019-05-25 17:00:00"
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
3.自建时间服务器
使用ntpd server为多台服务器同步时间
- 客户端机器安装ntpdate
[root@redis06 ~]# yum install ntpdate -y
- 服务端安装ntp
[root@redis05 ~]# yum install ntp -y
- 服务端编辑配置文件
[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
- 客户端同步时间测试
[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
- 客户端设置定时任务,自动同步时间
[root@redis06 ~]# crontab -e
*/10 * * * * /usr/sbin/ntpdate 192.168.1.13 >> /root/ntpdate.log 2>&1