同步服务器时间

在线同步

设置时区

  • 查看当前时区 date -R
    1
    2
    [root@localhost /]# date -R
    Sat, 14 Dec 2019 19:25:39 +0800
    +0800 表示时间为东8区,即北京时间
    若显示结果为非当前时区时间,可以进行设置
  • 设置当前时区
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    [root@localhost /]# tzselect
    ...
    5) Asia
    ...
    11) none - I want to specify the time zone using the Posix TZ format.
    #? 5
    ...
    9) China
    ...
    17) Iraq 34) Pakistan
    #? 9
    Please select one of the following time zone regions.
    1) Beijing Time
    2) Xinjiang Time
    #? 1
    The following information has been given:

    China
    Beijing Time

    Therefore TZ='Asia/Shanghai' will be used.
    Local time is now: Sun Dec 8 21:07:46 CST 2019.
    Universal Time is now: Sun Dec 8 13:07:46 UTC 2019.
    Is the above information OK?
    1) Yes
    2) No
    #? 1
    You can make this change permanent for yourself by appending the line
    TZ='Asia/Shanghai'; export TZ
    to 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 you
    can use the /usr/bin/tzselect command in shell scripts:
    Asia/Shanghai

    安装ntp服务

  • 安装ntp服务命令:
    1
    apt-get install ntp  或者 yum install ntp

    ntp服务相关命令

    检查ntp服务状态命令 systemctl status ntpd
    启动ntp服务命令 systemctl start ntpd
    设置开机启动ntp服务 systemctl enable ntpd

    开始同步时间

    1
    2
    3
    将服务器ip时间与本地时间同步
    注意:若不加上-u参数, 会出现以下提示:no server suitable for synchronization found
    ntpdate -u 服务器ip

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

至此服务器时间同步完成。

离线同步

1
2
# 设置时间 2019-12-14 18:00:00
[root@localhost /]# date -s 2019-12-14 18:00:00

Welcome to Hexo
Donate comment here