linux时间同步两种方法:
一、使用主服务器,进行同步
主服务器和客户端操作:
yum -y reinstall chrony
timedatectl set-timezone Asia/Shanghai (更改系统时区为上海)
2:主服务器修改配置文件
sed -i '3s/^/ /' /etc/chrony.conf
sed -i '4s/^/ /' /etc/chrony.conf
sed -i '5s/^/ /' /etc/chrony.conf
sed -i '6s/^/ /' /etc/chrony.conf
sed -i '22c allow 客户端ip/24' /etc/chrony.conf (客户端网段,列:192.168.0.0 )
启动服务
systemctl enable chronyd
systemctl restart chronyd
3:客户端修改配置文件
sed -i '3c server 主服务器ip iburst' /etc/chrony.conf
sed -i '4,6d' /etc/chrony.conf
systemctl enable chronyd
systemctl restart chronyd
二、使用默认时间同步
主服务器和客户端操作:
yum -y reinstall chrony
timedatectl set-timezone Asia/Shanghai (更改系统时区为上海)
sed -i '3s/^/ /' /etc/chrony.conf
sed -i '4s/^/ /' /etc/chrony.conf
sed -i '5s/^/ /' /etc/chrony.conf
sed -i '6s/^/ /' /etc/chrony.conf
启动服务
systemctl enable chronyd
systemctl restart chronyd
再添加任务计划(隔两天校正一下时间同步)
* */2 * * * /bin/systemctl restart chronyd