ntp时间同步 - 黑猴子

集群时间同步

1. 时间服务器配置(必须root用户)

1) 检查ntp是否安装html

[root@node1 ~]# rpm -qa | grep ntpnode

fontpackages-filesystem-1.44-8.el7.noarchpython

ntp-4.2.6p5-25.el7.centos.2.x86_64centos

python-ntplib-0.3.2-1.el7.noarch服务器

ntpdate-4.2.6p5-25.el7.centos.2.x86_64网络

 

2) 若是没有ntp服务,可以使用yum命令进行安装less

[root@node1 ~]# yum -y install ntpide

 

2. 检查当前系统时区

1) 选择某台机器,做为集群中时间服务器的主节点,而后其余机器同步该机器的时间便可。可是在开始这步操做以前,咱们须要确保全部节点的时区是统一的测试

[root@node1 ~]# date -Rspa

显示相似以下格式:

Wed, 28 Feb 2018 15:28:53 +0800

 

2) 尖叫提示:若是显示的时区不是+0800,你能够删除localtime文件夹后,再关联一个正确时区的连接过去

[root@node1 ~]# rm -rf /etc/localtime

[root@node1 ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

3. 同步网络时间

1) 若是怀疑本身本地机器的时间与标准时间相差不少,建议使用时间服务器的主节点同步一下网络时间:

[root@node1 ~]# ntpdate pool.ntp.org

 

4. 修改ntp配置文件

1) 咱们须要修改ntp服务的配置文件,关闭网络时间的同步

[root@node1 ~]# vi /etc/ntp.conf

 

2)对以下内容作出修改

# Hosts on local network are less restricted.

 

# 受权192.168.2.0网段上的全部机器能够从这台机器上查询和同步时间

restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap

 

# 当该节点丢失网络链接,依然能够做为时间服务器为集群中的其余节点提供时间同步

server 127.127.1.0

fudge  127.127.1.0 stratum 10

# 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 2.centos.pool.ntp.org iburst

#server 3.centos.pool.ntp.org iburst

尖叫提示:

nomodify:客户端不能使用ntpc与ntpq修改服务器的时间参数

notrap:不提供trap远程时间登陆的功能

 

5.重启ntp服务

CentOS6

[root@node1 ~]# service ntpd restart

[root@node1 ~]# chkconfig ntpd on

CentOS7

[root@node1 ~]# systemctl restart ntpd.service

[root@node1 ~]# systemctl enable ntpd.service

 

6. 设置定时同步任务
1) 首先在其余节点上关闭ntp服务

 

CentOS6

[root@node1 ~]# service ntpd stop

[root@node1 ~]# chkconfig ntpd off

 

CentOS7

[root@node1 ~]# systemctl stop ntpd.service

[root@node1 ~]# systemctl disable ntpd.service

 

查看ntp进程id

[root@node1 ~]# pgrep ntpd

 

2) 其余节点手动同步第一台时间服务器的时间进行测试

[root@node1 ~]# ntpdate node1

 

3) 其余节点制定计划任务,周期性同步时间

[root@node1 ~]# crontab -e

 

# .------------------------------------------minute(0~59)

# | .----------------------------------------hours(0~23)

# | | .--------------------------------------day of month(1~31)

# | | | .------------------------------------month(1~12)

# | | | | .----------------------------------day of week(0~6)

# | | | | | .--------------------------------command

# | | | | | |

# | | | | | |

*/10 * * * * /usr/sbin/ntpdate node1

 

4) 重启定时任务

 

CentOS6

[root@node1 ~]# service crond restart

 

CentOS7

[root@node1 ~]# systemctl restart crond.service      

 

5) 查看任务

[root@node1 ~]# crontab -l

相关文章
相关标签/搜索