一、設置主節點時間服務器的時區
二、在每一個節點上檢查是否安裝時間服務ntp
三、在主節點上配置時間同步的相關文件
四、在其他從節點上配置與主節點時間同步的腳本
一、設置主節點時間服務器的時區
1、選擇時區(就選到beijing就行)
[root@node001 ~]# tzselect
2、把時區,將cp /usr/share/zoneinfo/Asia/Shanghai設置為到/etc/localtime的鏈接
[root@node001 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、在每一個節點上檢查是否安裝時間服務ntp
[root@node001 ~]# rpm -q ntp
ntp-4.2.6p5-15.el6.centos.x86_64
[root@node001 ~]# chkconfig --list ntpd
ntpd 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
# For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict -6 ::1 # Hosts on local network are less restricted. restrict 192.168.181.0 mask 255.255.255.0 nomodify notrap #這里新增內容,更改為自己的網關,我的是181.第一處新增,意思是從IP #地址192.168.181.1-192.168.181.254,默認網關255.255.255.0的服務器 #都可以使用我們的NTP服務器來同步時間 # 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 iburst #server 1.centos.pool.ntp.org iburst #如果集群是在一個封閉的局域網內,可以屏蔽掉默認的server這里注釋掉 #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server 210.72.145.44 perfer #中國國家受時中心 server 202.112.10.36 #1.cn.pool.ntp.org server 59.124.196.83 #這里可有可無,制定ntp服務器的同步時間范圍 server 192.168.217.130 #broadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client # Enable public key cryptography. #crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
server 127.127.1.0 #當服務器與公網失去連接后使用本地時間作為服務的同步時間
fudge 127.127.1.0 stratum 10
[root@node001 ~]# vi /etc/sysconfig/ntpd
增加內容
SYNC_HWCLOCK=yes
正在啟動 ntpd: [確定]
[root@node002 ~]# crontab -e
* */1 * * * /usr/sbin/ntpdate node001
檢查是否寫成
[root@node002 ~]# crontab -l
* */1 * * * /usr/sbin/ntpdate node001
同樣的步驟在其他節點重復
更改一個節點的時間
[root@node002 ~]# date -s "2019-4-29 00:00:00"
十分鍾后查看時間檢查是否同步
[root@node002 ~]# date
如果現在立即要同步,可以手動同步
[root@node002 ~]#ntpdate node001