有时系统会出现时间不准的情况,当然可以手动校正时间,但每次都这样做实在很累,最方便的方法是透过 NTP 自动同步时闁,以下是 RHEL 及 CentOS 7 的设定方法。
先安装 ntp 套件:
$ sudo yum install ntp -y
安装 ntp 套件后,可以用 ntpdate 指令连接到 ntp 服务器同步时间,以下是适合台湾及香港使用的 ntp server:
$ sudo ntpdate time.stdtime.gov.tw
或
$ sudo ntpdate stdtime.gov.hk
上面的指令只会做一次时间同步,如果想自动同步,除了将上面指令放到 Shell Script, 也可以设定 ntpd deamon,编译档案 /etc/ntp.conf:
$ sudo vi /etc/ntp.conf
在 “Server” 设定需要使用的 ntp 服务器。
然后用 systemctl 启动 ntpd 及 设定开机自动启动:
$ sudo systemctl start ntpd
$ sudo systemctl enable ntpd
$ sudo systemctl enable ntpd
这样系统就会自动连接到 ntp 服务器校正系统时间。