首页 > 代码库 > Linux时间同步配置教程
Linux时间同步配置教程
生产环境关联主机间常要求时间一致,若有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
1.3 重启ntp服务
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
说明:前边的五个值依次为分/时/日/月/星期,*表示任意。
Linux时间同步配置教程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。