Linux上三种方式--ntp时间同步

Linux时间同步
方式一:
设置时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
联网情况:ntpdate us.pool.ntp.org

运行结果:
Linux上三种方式--ntp时间同步

方式二:
查看NTP状态
service ntpd status
yum install -y ntpd
Linux上三种方式--ntp时间同步

chkconfig ntpd on
查看时区:
date -R
同步网络时间
ntpdate 1.centos.pool.ntp.org
结果展示:
Linux上三种方式--ntp时间同步

方式三:(集群中常用的方法)
配置ntp服务端:
vi /etc/ntp.conf
restrict 172.16.0.0 mask 255.255.255.0 nomodify notrap
使用本地时钟
server 127.127.1.0
fudge 127.127.1.0 stratum 10
保存退出

开启防火墙udp 123端口
iptables -I INPUT -p udp –dport 123 -j ACCEPT
service iptables save

在启动ntpd服务之前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。
ntpdate 0.centos.pool.ntp.org

启动ntpd服务
service ntpd start

步骤跟踪:
Linux上三种方式--ntp时间同步

在子集群中运行
ntpdate 配置好了的主机名,实现集群时间同步

Linux上三种方式--ntp时间同步