NTP同步网络时间

NTP同步网络时间


废话不多说,直接执行如下命令即可
# yum install -y ntpdate
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;ntpdate -u ntp.api.bz && hwclock -w

时区操作

1. 查看时区
 date "+%Z"
[root@lb-node1 ~]# ll /etc/localtime
lrwxrwxrwx. 1 root root 38 Oct 17 14:26 /etc/localtime -> ../usr/share/zoneinfo/America/New_York
[root@lb-node1 ~]#

如果采用直接cp的方法修改系统时区,那么就会把它所链接的文件修改掉,例如把美国的时区文件内容修改成了上海的时区内容,有可能会导致有些编程语言或程序在读取系统时区的时候发生错误

  • 正确的修改方法是
1. CentOS6+ 、Ubuntu16+ 系统
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

2. CentOS7、RHEL7、Scientific Linux 7、Oracle Linux 7系统,最好使用timedatectl命令
# timedatectl list-timezones |grep Shanghai    #查找中国时区的完整名称
Asia/Shanghai
# timedatectl set-timezone Asia/Shanghai    #其他时区以此类推
或者手动创建软链接
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

同步网络时间

ntp常用服务器:
中国国家授时中心:210.72.145.44
NTP服务器(上海) :ntp.api.bz
美国: time.nist.gov
复旦: ntp.fudan.edu.cn
微软公司授时主机(美国) :time.windows.com
北京邮电大学 : s1a.time.edu.cn
清华大学 : s1b.time.edu.cn
北京大学 : s1c.time.edu.cn
台警大授时中心(台湾):asia.pool.ntp.org

# 同步网络时间
[root@lb-node2 ~]# ntpdate -u ntp.api.bz
12 Nov 19:47:29 ntpdate[6504]: adjust time server 47.98.146.45 offset 0.045074 sec
[root@lb-node2 ~]#

将系统时间写入硬件

[root@lb-node1 ~]# hwclock			# 查看硬件时间
Mon 12 Nov 2018 07:55:37 PM CST  -0.866369 seconds
[root@lb-node1 ~]#  hwclock -w			# 同步系统时间到硬件

# hwclock hctosys				# 同步硬件时间到系统
# hwclock systoch    			# 同步系统时间到硬件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值