生产环境关联主机间常要求时间一致,若有 NTP 时间同步服务器,可配置各主机与时间同步服务器同步时间。
1 服务端配置
1.1 安装 ntpd
- yum install -y ntp
1.2 配置 ntp.conf 文件
- cat > /etc/ntp.conf <<EOF
- # restrict行和-6行分别表示拒绝ipv4和ipv6用户同步
- restrict default kod nomodify notrap nopeer noquery
- restrict -6 default kod nomodify notrap nopeer noquery
- restrict 127.0.0.1
- restrict -6 ::1
- #允许192.168网段进行时间同步
- restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
- # 该ntp服务器的上层ntp服务器,而不是自己
- server 192.168.1.1
- # 以下两句为没有上层时启用自身时间为准
- #server 127.127.1.0
- #fudge 127.127.1.0 stratum 10
- # 上层服务与本机主板时钟之间时间差别记录在这个文件里
- driftfile /var/lib/ntp/drift
- keys /etc/ntp/keys
- EOF
- chkconfig ntpd on
- service ntpd restart
2 客户端配置
安装 ntp 客户端:
- yum install ntpdate
同步时间:
- ntpdate 192.168.160.2
配置定时同步任务,以 root 执行 crontab -e,在调出的 vi 中输入以下内容:
- 0 1 * * * /usr/sbin/ntpdate 192.168.160.2
说明:前边的五个值依次为分 / 时 / 日 / 月 / 星期,* 表示任意。
来源: http://www.bubuko.com/infodetail-1970669.html