NTP
参考:http://blog.sina.com.cn/s/blog_75c7ccf40101hg5l.html
客户端:
yum install ntp -y
# 配置
vim /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.100.3.221 iburst
# 设置开启服务后自动同步上级ntp server时间
vim /etc/ntp/step-tickers
192.100.3.221
# 启动
systemctl restart ntpd
systemctl enable ntpd
# 开启同步
ntpdate 192.100.3.221
# 查看
[root@node-1 conf]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*yum_repository 192.100.3.221 11 u 42 64 377 0.167 0.667 0.123
前面有*说明同步成功
# 查看是否开启 NTP synchronized: yes
timedatectl
ntpstat
服务端:
#1.备份配置文件
cp /etc/ntp.conf /etc/ntp.conf.bak
#2.添加参数
vim /etc/ntp.conf
server controller iburst
restrict -4 default kod notrap nomodify
restrict -6 default kod notrap nomodify
#3.注释以下参数
#restrict default nomodify notrap nopeer noquery
#restrict 127.0.0.1
#restrict ::1
#4.启动ntp服务
systemctl enable ntpd.service
systemctl start ntpd.service
配置文件中一般有restrict default语句,#掉后选择,以下2种的一种
restrict default nomodify notrap noquery # 默认允许所有可连接客户端ntpdate到本机
restrict default ignore # 默认所有客户端禁止ntpdate到本机
#与上级服务端连续性同步时间,prefer表示优先,如无可不设置
server 上级ntp服务器IP或者域名 [prefer]
#当之前设置了restrict default ignore的情况下,可以设置哪些客户可以ntpdate到本机
restrict 192.168.1.88 mask 255.255.255.255 nomodify notrap
chrony
#安装
yum install chrony -y
#控制节点:vim /etc/chrony.conf
server controller iburst
# Serve time even if not synchronized to a time source.
#打开注释,本机不同步任何主机的时间,本机作为时间源
local stratum 10
#允许访问的网段
allow 10.0.0.0/24
#其他节点:vim /etc/chrony.conf
server controller iburst
#启动
systemctl enable chronyd.service
systemctl restart chronyd.service
ntpdate controller
#验证
chronyc sources
chronyc sources -v 查看状态说明
timedatectl