使用ntpd来管理和同步时间
1、安装ntp
sudo yum install ntp
2、配置ntp(编辑 /etc/ntp.conf )
sudo vi /etc/ntp.conf
3、使用阿里云的源
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
4、配置服务并启用
sudo systemctl enable ntpd
sudo systemctl start ntpd
5、查看同步状态
ntpq -p
注意:出入口的防火墙放行 NTP 使用 UDP 端口 123,需确保防火墙允许通信 使用Firealld的 sudo firewall-cmd --add-service=ntp --permanent sudo firewall-cmd --reload
使用iptables 编辑 /etc/sysconfig/iptables,添加规则: -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
重启iptabls sudo service iptables restart
关于时区 查看当前时区 timedatectl 设置时区 sudo timedatectl set-timezone Asia/Shanghai