centos集群中各節點如何實現時間同步?


選擇集群中一台節點為ntp時間服務器,其他節點以此機器的時間為基准來進行同步。

 

本節以兩台服務器為例

192.168.1.1

192.168.1.2

本節以192.168.1.1作為ntp服務器,192.168.1.2作為客戶端來同步服務器的時間, 在多節點的集群中道理是一樣的。

 

1 集群中所有節點安裝ntp時間同步工具

yum -y install ntp ntpdate #安裝ntpdate時間同步工具

 

2  192.168.1.1時間同步服務器設置

修改/etc/ntp.conf文件,添加server設置127.127.1.0為其自身

vim /etc/ntp.conf

在public servers節下添加

server     127.127.1.0   #設置自己作為時間同步服務器

在access節下新增加一個restrict段為可以接受服務的網段,本例為192.168.1.0

restrict 192.168.1.0

如下標黃加粗部分所示:

# 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 ::1 restrict 192.168.1.0 #設置可接受服務的網段

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 127.127.1.0 #設置自己作為時間同步服務器
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst

 

啟動時間同步服務器

systemctl start ntpd     #啟動時間同步程序
systemctl enable ntpd  #允許時間同步程序開機啟動

在其它節點上運行如下命令同步時間

ntpdate -u 192.168.1.1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM