-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
教程基础入门基础入门
Description
当我们安装完服务器后,不可避免地需要配置时间同步服务。在 Linux 中时间同步配置是通过 NTP(Network Time Protocol)完成的。
设置时区
查看当前时区:
timedatectl status设置时区(中国使用的是上海时区):
timedatectl set-timezone Asia/Shanghai使用 NTP 守护进程同步时间
有两种类型的 NTP 守护进程,分别是 chronyd 和 ntpd。
本教程同时包含了这两个 NTP 守护进程的配置方法,你只需二选其一即可(如果系统中同时运行两个 NTP 守护进程,则会导致不兼容和不稳定):
- 使用 chronyd 同步时间(适用于虚拟系统)
- 使用 ntpd 同步时间(适用于网络系统)
不论使用上述哪种 NTP 守护进程,都需要从 NTP 公共池选择时间服务器,比如中国 NTP 池(pool.ntp.org: NTP Servers in China, cn.pool.ntp.org)的是:
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
使用 chronyd 同步时间
1)安装 chronyd 软件包:
yum install chrony -y2)编辑配置文件:
vi /etc/chrony.conf将:
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
修改为:
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
3)启动 chronyd 服务:
systemctl start chronyd4)设置当系统引导时自动启动 chronyd 服务:
systemctl enable chronyd使用 ntpd 同步时间
1)安装 ntpd 软件包:
yum install ntp -y2)编辑配置文件:
vi /etc/ntp.conf将:
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
修改为:
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
3)启动 ntpd 服务:
systemctl start ntpd4)设置当系统引导时自动启动 chronyd 服务:
systemctl enable ntpdMetadata
Metadata
Assignees
Labels
教程基础入门基础入门