虚机有三台:bigdata111、bigdata112、bigdata113,需将112和113的linux系统时间向111同步
rpm包下载:
链接:https://pan.baidu.com/s/1bonvucrHBwkncj_2D9eBNg
提取码:n4td
1)所有机器root用户安装ntp服务命令
#server安装
rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
#slave安装
rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
2)111主服务器切root修改ntp配置文件(根据服务器ip设置)
vi /etc/ntp.conf
清空所有,添加以下内容:
# 记录和上级时间服务器的时间差异
driftfile /var/lib/ntp/drift
# ntp 日志
logfile /var/log/ntp.log
# 日志级别 all event info
logconfig all
# 同意上层时间server主动改动本机时间
restrict default nomodify notrap nopeer noquery
# 允许本机地址的一切操作
restrict 127.0.0.1
restrict ::1
# 允许网段内客户端连接此服务器同步时间,但是拒绝让他们修改服务器上的时间
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# 利用 server 设定上层 NTP 服务器,可设置多个。prefer 表示优先
# 国家授时中心
server 210.72.145.44 prefer
# 阿里云
server ntp.aliyun.com prefer
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
# 外部时间server不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
3)修改111主服务器ntpd文件
vi /etc/sysconfig/ntpd
添加:
SYNC_HWCLOCK=yes
4)启动111主服务器ntpd服务
service ntpd status
service ntpd restart
5)设置111主服务器ntpd服务开机启动,其他服务器不设置
chkconfig ntpd on
systemctl enable ntpd
6)其他服务器使用root用户配置定时任务
crontab -e
*/10 * * * * /usr/sbin/ntpdate bigdata111