核心:
使用一台服务器A作为ntp服务器,自动同步网络时间;
其余的服务器皆作为客户端,自动同步服务器A的时间。
理由:
统一时间,防止因时间问题造成的程序混乱
操作:
服务器A操作,如下:
1、确认是否安装ntp:rpm -qa|grep ntp
2、未安装,安装ntp:yum -y install ntp
3、更改配置:vim /etc/ntp.conf
> **新增:**
restrict 服务器A的ip mask 255.255.252.0 nomodify notrap
server 127.127.1.0
fudge 127.127.1.0 stratum 10
> **注释掉:**
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
4、查看时间,并校验:
查看:date
校验:date -s '年-月-日 时:分:秒'
5、启动ntp的服务:service ntpd start 或者 systemctl start ntpd
6、设置ntp服务开机自启动:systemctl enable ntpd
其他服务器:
1、定crontab计划任务自动校时:
使用命令:crontab -e, 然后添加:
*/1 * * * * /usr/sbin/ntpdate 服务器A的ip