集群时间同步:在集群中找一台机器(node1,这里的node1就是任意一台机器,也可以写对应的IP地址),然后集群中的其他机器与node1 每十分钟同步一次。
步骤:
1.rpm -qa | grep ntp 查看ntp 和ntpdate 是否安装
[root@node1 share]# rpm -qa | grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.4p8-3.el6.centos.x86_64
ntp-4.2.4p8-3.el6.centos.x86_64
2. vi /etc/ntp.conf 需要修改三处
a 打开一个注释 ,192.168.1.0 是node1机器上的网关。
# Hosts on local network are less restricted.
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
b 将server0 ,server1 ,server2 注释掉
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
c 打开两个注释,server 和 fudge
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
3. vi /etc/sysconfig/ntpd 加上SYNC_HWCLOCK=yes
# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
4. chkconfig ntpd on 将ntp 永久开启
5. service ntpd start 后,可以查看状态 service ntpd status
6. crontab -e 编写定时器同步时间, 意义:每十分钟与node1 同步一次时间。需要在集群中其他的机器中都编写 crontab -e
## sync cluster time
## 分 时 日 月 周 这里是每十分钟同步
0-59/10 * * * * /usr/sbin/ntpdate node1
7. ntpdate node1 然后就可以手动先同步一下时间.