CRH5.1_x64_CentOS7集群上搭建ntp服务器实现时间同步

分有外网和无外网情况。

  • 注意配置ip映射

1. 有外网

  • 每台机器直接安装使用ntp服务,让时间与网络时间同步。
安装
[root@redoop01 ~]#  for ip in $(cat hosts);do  ssh ${ip} yum install -y ntp; done
启动
[root@redoop01 ~]#  for ip in $(cat hosts);do  ssh ${ip} systemcntl start ntpd ; done
开机自启动
[root@redoop01 ~]#  for ip in $(cat hosts);do  ssh ${ip} systemcntl enable ntpd ; done

2. 无外网,选一台机器做ntp server,其他机器做 ntp client

  • 集群所有机器安装 ntp
[root@redoop01 ~]#  for ip in $(cat hosts);do  ssh ${ip} yum install -y ntp; done
  • 启动ntp server节点 ntp服务
systemctl start ntpd

systemctl enable ntpd
  • 在server节点上设置其ntp服务器为其自身,同时设置可以接受连接服务的客户端,通过更改/etc/ntp.conf文件来实现,其中server设置127.127.1.0为其自身,新增加一个restrict段为可以接受服务的网段
# 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 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 ::1
restrict 192.168.0.0 mask 255.255.0.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
#server 3.centos.pool.ntp.org iburst
### 
  • 重启ntp server 节点的 ntp 服务
systemctl restart ntpd
  • 在client节点上设置ntp server机器为 授时服务器
# 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 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 ::1


# 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 redoop03
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
  • 在client节点上同步server的时间
ntpdate redoop03
  • client节点启动ntpd服务
systemctl start ntpd
systemctl enable ntpd
  • 所有节点启动时间同步
timedatectl set-ntp yes
  • 查看同步效果
[root@redoop01 ~]# for ip in $(cat hosts);do ssh ${ip} date -R;done
Mon, 26 Mar 2018 16:03:08 +0800
Mon, 26 Mar 2018 16:03:08 +0800
Mon, 26 Mar 2018 16:03:09 +0800
[root@redoop01 ~]# 

更多精彩原创文章,详见红象云腾社区

猜你喜欢

转载自blog.csdn.net/redoop123/article/details/79708953