Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间
2017-10-09 17:26
316 查看
查看时区列表: timedatectl list-timezones|grep Asia
设置中国时区: timedatectl set-timezone Asia/Shanghai 执行完后时间就变为北京时间了
查看当前时间: date
查看当前设置:
[root@localhost ~]# timedatectl
Local time: Mon 2017-10-09 16:44:08 CST
Universal time: Mon 2017-10-09 08:44:08 UTC
RTC time: Mon 2017-10-09 08:44:08
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
如果没有系统没有安装ntp服务器的话可以安装yum install ntp -y
然后编辑ntp的配置文件vi /etc/ntp.conf (日志文件默认在/var/log/messages中),添加以下几个服务器域名,如果原配置文件没有的话
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
systemctl restart ntpd
systemctl enable ntpd
这样,服务器端就配置得差不多了,但我为了让效果更明显,把服务器修改为纽约时区,另一台需要同步的linux客户端的时区修改为非洲时间,结果导致,客户端ntpdate之后没有同步,后来才发现,需要在同一时区内才能同步时间,也就是说,服务端和客户端的时区必须在中国这个时区内才可以
下面来测试我们的ntp服务器配置有没有成功
在服务器端(ip:10.0.3.66)上
使用date -s 23:30:30 (时间可以随便改,反正改一个跟客户端时间不一样的就可以了),然后date可以看到时间变成了23:30:30
在客户端上
ntpdate 10.0.3.66 执行后发现,时间也变成了23:30:30
让人无语的是我在centos6.5的最小化安装的系统上,timedatectl命令用不了,也不知道怎么安装,但是又想看一下当前系统的时区是哪个,有没有配置正常?对于这种情况,我们可以简单的使用date -R来查看时区,当然这样看到的时区是数字时区,而不是英文时区。如果你初中的地理课没白上,就应该记得北京时间是东八区的时间,看到后面是+0800就表示当前系统时区是东八区时间
那么问题又来了,我们又该如何设置系统时区为东八区呢?
执行命令cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
再date -R查看时区,可以看到时区恢复正常
设置中国时区: timedatectl set-timezone Asia/Shanghai 执行完后时间就变为北京时间了
查看当前时间: date
查看当前设置:
[root@localhost ~]# timedatectl
Local time: Mon 2017-10-09 16:44:08 CST
Universal time: Mon 2017-10-09 08:44:08 UTC
RTC time: Mon 2017-10-09 08:44:08
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
如果没有系统没有安装ntp服务器的话可以安装yum install ntp -y
然后编辑ntp的配置文件vi /etc/ntp.conf (日志文件默认在/var/log/messages中),添加以下几个服务器域名,如果原配置文件没有的话
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
systemctl restart ntpd
systemctl enable ntpd
这样,服务器端就配置得差不多了,但我为了让效果更明显,把服务器修改为纽约时区,另一台需要同步的linux客户端的时区修改为非洲时间,结果导致,客户端ntpdate之后没有同步,后来才发现,需要在同一时区内才能同步时间,也就是说,服务端和客户端的时区必须在中国这个时区内才可以
下面来测试我们的ntp服务器配置有没有成功
在服务器端(ip:10.0.3.66)上
使用date -s 23:30:30 (时间可以随便改,反正改一个跟客户端时间不一样的就可以了),然后date可以看到时间变成了23:30:30
在客户端上
ntpdate 10.0.3.66 执行后发现,时间也变成了23:30:30
让人无语的是我在centos6.5的最小化安装的系统上,timedatectl命令用不了,也不知道怎么安装,但是又想看一下当前系统的时区是哪个,有没有配置正常?对于这种情况,我们可以简单的使用date -R来查看时区,当然这样看到的时区是数字时区,而不是英文时区。如果你初中的地理课没白上,就应该记得北京时间是东八区的时间,看到后面是+0800就表示当前系统时区是东八区时间
那么问题又来了,我们又该如何设置系统时区为东八区呢?
执行命令cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
再date -R查看时区,可以看到时区恢复正常
[root@localhost ~]# date Mon Oct 16 21:59:20 EDT 2017 [root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime cp: overwrite `/etc/localtime'? y [root@localhost ~]# date Tue Oct 17 09:59:41 CST 2017 [root@localhost ~]# date -R Tue, 17 Oct 2017 09:59:45 +0800 [root@localhost ~]#
相关文章推荐
- 部署NTP服务器进行时间同步
- 部署NTP服务器进行时间同步
- NTP服务器同步本地时间(WinForm)
- 部署NTP服务器进行时间同步
- centos7 网络时间同步到本地
- 高精度时间同步系统 北斗同步时钟 北斗卫星时钟 PC时间同步 XP时间同步 北京时间同步 北京时间校准 NTP服务器 时间服务器 时间同步服务器 北斗授时系统 北斗对时系统 北斗时间服务器 北斗对时装置
- CRH5.1_x64_CentOS7集群上搭建ntp服务器实现时间同步
- Linux--日志的管理以及时间的同步
- Linux 时区修改以及时间同步
- 从时间服务同步本地时间
- Java通过Ntp服务器获取网络时间修改本地服务器时间
- linux的ntp服务器时间同步设置
- WEB应用中实现本地时间与服务器时间同步方案
- Linux修改系统时间、硬件时间以及时间同步问题
- js实现本地时间同步功能
- cisco 交换机设置时区、时间、同步日志本地时间等操作
- Android从网络获取北京时间以及动态的监听时间
- Sqlite3中对于毫秒数和本地时间之间的转换以及时间相关操作
- NTP服务器列表--同步时间成功
- python实现定时同步本机与北京时间的方法