方法1:ntp方式
步骤1:服务端配置
# yum install -y ntp //系统自带
# vim /etc/ntpd.conf
# systemctl restart ntpd
步骤2:客户端配置
# yum install -y ntp ntpdate
如有防火墙配置需开放udp 123端口
# firewall-cmd --permanent --add-port=123/udp
# firewall-cmd --reload
# vim /etc/ntpd.conf //将原有 server 字段注释并增加以下配置
# systemctl restart ntpd
# ntpq -p //查看同步状态,最前面有*号表示同步成功,如果没有需要等一会
方法2:chrony方式
服务端配置:
# yum install chrony -y //sp2服务器自带
# vim /etc/chrony.conf
如有防火墙配置需开放udp 123端口
# firewall-cmd --permanent --add-port=123/udp
# firewall-cmd --reload
客户端配置:
# yum install chrony -y //sp2服务器自带
# vim /etc/chrony.conf
# systemctl restart chronyd
# chronyc sources -v //查看同步状态,前面 ^*开头表示同步正常
方式3:crond+ntpdate方式
按照方式2配置完毕后,客户端也可使用定时任务的方式,指定同步周期
# ntpdate 192.168.1.150 //手动同步
# vim /etc/crontab //加入定时任务
*/10 * * * * /usr/sbin/ntpdate 192.168.1.21 && hwclock -w