时间同步
apt-get install chrony(树莓派等) yum install chrony -y (centos)
ssh 可能乱码
>vi /etc/locale.conf
把LANG=zh_CN.UTF-8 改成 LANG=zh_CN.GBK
>source /etc/locale.conf
设置chrony开机服务
- 服务状态:
systemctl start chronyd.service
systemctl enable chronyd.service
systemctl status chronyd.service
- 服务端和客户端chrony配置
-
服务端配置
配置文件修改
vi /etc/chrony/chrony.conf
配置允许访问的客户端列表,支持CIDR,例如
allow 192.168/16 -
纯时间服务不向其他NTP服务器同步
local stratum 10
重启下服务端chrony服务
systemctl restart chronyd.service
- 客户端配置
-
配置文件修改
vim /etc/chrony.conf
修改server即可,添加要同步时间的源服务器ip
server ntp.aliyun.com iburst -
重启下客户端chrony服务
systemctl restart chronyd.service -
查看同步状态
systemctl status chronyd -l
-
常用命令
-
查看时间同步源: $chronyc sources -v
-
立即手工同步 $chronyc -a makestep
-
查看时间同步源状态: $ chronyc sourcestats -v
-
设置硬件时间硬件时间默认为UTC: $ timedatectl set-local-rtc 1
-
启用NTP时间同步: $ timedatectl set-ntp yes
-
校准时间服务器: $ chronyc tracking
最后需要注意的是,配置完/etc/chrony.conf后,需重启chrony服务