Chronyc 时间同步服务器

Server端

# CentOS 7
yum -y install chrony 

# Ubuntu
apt-get install chrony

修改配置文件

# CentOS 7
vim /etc/chrony.conf

# Ubuntu
vim /etc/chrony/chrony.conf

开启服务

# CentOS 7
systemctl enable chronyd.service
systemctl restart chronyd.service

# Ubuntu
service chrony restart

设置时区

timedatectl set-timezone Asia/Shanghai
timedatectl status

Client端

# CentOS 7
yum -y install chrony 

# Ubuntu
apt-get install chrony

修改配置文件

# CentOS 7
cp -a /etc/chrony.conf{,-bak}
#备份原配置文件

echo server 192.168.100.10 iburst > /etc/chrony.conf
# 这里的100.10,是上面server端的IP

# Ubuntu
cp -a /etc/chrony/chrony.conf{,-bak}
echo server server端的IP iburst > /etc/chrony.conf

开启服务

# CentOS 7
systemctl enable --now chronyd.service
systemctl status chronyd.service

# Ubuntu
service chrony restart

设置时区

timedatectl set-timezone Asia/Shanghai

同步时间

chronyc sources

查看时间

date +%F-%T