【Linux】时间同步
- ntpd
vi /etc/ntp.conf
- 修改时间服务器的ntp.conf配置
vi /etc/ntp.conf
#授权 192.168.17.0-192.168.17.255 网段上的所有机器可以从这台机器上查询和同步时间
restrict 192.168.17.0 mask 255.255.255.0 nomodify notrap
- 修改/etc/sysconfig/ntpd 文件
vi /etc/sysconfig/ntpd
#让硬件时间与系统时间一起同步
SYNC_HWCLOCK=yes
- 重新启动 ntpd 服务
systemctl restart ntpd
- 设置 ntpd 服务开机启动
systemctl is-enabled ntpd #开机自启动状态。
- 在其他机器配置 1 分钟与时间服务器同步一次
sudo crontab -e
编写定时任务如下:
*/1 * * * * /usr/sbin/ntpdate localhost #localhost是主机名
- 重启corntab服务
service crond restart //重启服务