centos 7时间同步方法

来源:互联网 发布:java 神经网络框架 编辑:程序博客网 时间:2024/05/22 05:03

1.环境信息

Linux:CentOS Linux release 7.1.1503 (Core) 

2. 安装ntp包

包名称如下(存在依赖关系,按顺序安装,yum 就无所谓了):

  autogen-libopts-5.18-5.el7.x86_64.rpm  

  ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm

  ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm


3.安装

[root@master yum.repos.d]# yum install yum-downloadonly ntpLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.cn99.com * extras: centos.ustc.edu.cn * updates: mirrors.sohu.comNo package yum-downloadonly available.Resolving Dependencies--> Running transaction check---> Package ntp.x86_64 0:4.2.6p5-25.el7.centos.2 will be installed--> Processing Dependency: ntpdate = 4.2.6p5-25.el7.centos.2 for package: ntp-4.2.6p5-25.el7.centos.2.x86_64--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-25.el7.centos.2.x86_64--> Running transaction check---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed---> Package ntpdate.x86_64 0:4.2.6p5-25.el7.centos.2 will be installed--> Finished Dependency ResolutionDependencies Resolved============================================================================================================================================================================================================================================ Package                                                     Arch                                               Version                                                              Repository                                        Size============================================================================================================================================================================================================================================Installing: ntp                                                         x86_64                                             4.2.6p5-25.el7.centos.2                                              base                                             547 kInstalling for dependencies: autogen-libopts                                             x86_64                                             5.18-5.el7                                                           base                                              66 k ntpdate                                                     x86_64                                             4.2.6p5-25.el7.centos.2                                              base                                              86 kTransaction Summary============================================================================================================================================================================================================================================Install  1 Package (+2 Dependent packages)Total size: 699 kTotal download size: 152 kInstalled size: 1.6 MIs this ok [y/d/N]: yDownloading packages:(1/2): autogen-libopts-5.18-5.el7.x86_64.rpm                                                                                                                                                                         |  66 kB  00:00:00     (2/2): ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm                                                                                                                                                                    |  86 kB  00:00:00     --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                                                                                                                       331 kB/s | 152 kB  00:00:00     Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Installing : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                                                                        1/3   Installing : ntpdate-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                                                                   2/3   Installing : ntp-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                                                                       3/3   Verifying  : ntp-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                                                                       1/3   Verifying  : ntpdate-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                                                                   2/3   Verifying  : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                                                                        3/3 Installed:  ntp.x86_64 0:4.2.6p5-25.el7.centos.2                                                                                                                                                                                                      Dependency Installed:  autogen-libopts.x86_64 0:5.18-5.el7                                                                                ntpdate.x86_64 0:4.2.6p5-25.el7.centos.2                                                                               Complete!

4.查看服务器时区

[root@master ~]# date -RWed, 20 Sep 2017 19:12:49 +0800

如果时区不正确,同步的时间也是不对的,先修改时区:

[root@master ~]# tzselect Please identify a location so that time zone rules can be set correctly.Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean10) Pacific Ocean11) none - I want to specify the time zone using the Posix TZ format.#? 5Please select a country. 1) Afghanistan           18) Israel                35) Palestine 2) Armenia               19) Japan                 36) Philippines 3) Azerbaijan            20) Jordan                37) Qatar 4) Bahrain               21) Kazakhstan            38) Russia 5) Bangladesh            22) Korea (North)         39) Saudi Arabia 6) Bhutan                23) Korea (South)         40) Singapore 7) Brunei                24) Kuwait                41) Sri Lanka 8) Cambodia              25) Kyrgyzstan            42) Syria 9) China                 26) Laos                  43) Taiwan10) Cyprus                27) Lebanon               44) Tajikistan11) East Timor            28) Macau                 45) Thailand12) Georgia               29) Malaysia              46) Turkmenistan13) Hong Kong             30) Mongolia              47) United Arab Emirates14) India                 31) Myanmar (Burma)       48) Uzbekistan15) Indonesia             32) Nepal                 49) Vietnam16) Iran                  33) Oman                  50) Yemen17) Iraq                  34) Pakistan#? 9Please select one of the following time zone regions.1) Beijing Time2) Xinjiang Time#? 1The following information has been given:        China        Beijing TimeTherefore TZ='Asia/Shanghai' will be used.Local time is now:      Wed Sep 20 19:14:23 CST 2017.Universal Time is now:  Wed Sep 20 11:14:23 UTC 2017.Is the above information OK?1) Yes2) No#? 1You can make this change permanent for yourself by appending the line        TZ='Asia/Shanghai'; export TZto the file '.profile' in your home directory; then log out and log in again.Here is that TZ value again, this time on standard output so that youcan use the /usr/bin/tzselect command in shell scripts:Asia/Shanghai
添加环境变量并使之生效:



[root@master ~]# source /etc/profile[root@master ~]# echo $TZAsia/Shanghai[root@master ~]# 

时区配置完成


5.时间同步

[root@master ~]# ntpdate -u 202.120.2.10120 Sep 19:19:10 ntpdate[30211]: adjust time server 202.120.2.101 offset 0.026881 sec[root@master ~]# date           #时间正常Wed Sep 20 19:19:34 CST 2017[root@master ~]# 

6.其他服务器同步

其他节点可以同步改服务器时间,以这个服务器作为自己局域网时间服务器,可以写个crontab 任务没分中同步一次

ntpdate -u master  #master 为改主机名,可以IP, 要安装上面的安装包,时间服务相关配置在/etc/ntp.con 


安装hbase 用的!

原创粉丝点击