linux/centos/集群安装ntp时间同步,自身实验成功

1. 准备节点

不管你有多少个节点,肯定要有一个 server 角色,至于谁是 server 你来决定。
例如下面这样,我们姑且假设有这样四个节点

192.168.11.101(server端 node1)
192.168.11.102(client端 node2)
192.168.11.103(client端 node3)

2. 安装配置 server 节点

在192.168.11.101端作为服务端,并在该节点进行以下步骤

2.1 下载安装

[root@node1 ~]# yum install ntp ntpdate

并将该服务器同步阿里云服务器网站

[root@node1 ~]# ntpdate ntp1.aliyun.com

2.2 编辑配置文件

[root@node1 ~]# 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
 

在下面再添加一行,代表本机作为服务器,不要怀疑下面的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
server 127.127.1.0 iburst

2.3 启动服务

[root@node1 ~]# systemctl start ntpd
[root@node1 ~]# systemctl enable ntpd.service #设置开机启动服务 

2.4 查看状态

[root@node1 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-02-11 19:38:22 CST; 19s ago
 Main PID: 1491 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─1491 /usr/sbin/ntpd -u ntp:ntp -g
 
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen and drop on 1 v6wildcard :: UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 2 lo 127.0.0.1 UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 3 ens33 192.168.0.108 UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 4 lo ::1 UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 5 ens33 fe80::e37b:3e48:9646:7eff UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listening on routing socket on fd #22 for interface updates
Feb 11 19:38:22 cdh1 ntpd[1491]: 0.0.0.0 c016 06 restart
Feb 11 19:38:22 cdh1 ntpd[1491]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Feb 11 19:38:22 cdh1 ntpd[1491]: 0.0.0.0 c011 01 freq_not_set
Feb 11 19:38:23 cdh1 ntpd[1491]: 0.0.0.0 c514 04 freq_mode

3. 安装配置 Client 节点

下面描述是在node2上进行的,也要在分别在node3或者有其他结点的下面都要执行一边下面操作

3.1 下载安装

[root@node2 ~]# yum install ntp ntpdate

3.2 编辑配置文件

[root@node2 ~]# vim /etc/ntp.conf

3.3 配置ntp服务器

[root@node2 ~]# 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
 

node2和node3都在下面再添加

#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.168.11.101 #配置本地ntp服务器为时间同步服务器
restrict 192.168.11.101 nomodify notrap noquery #允许本地时间服务器主动修改本机的时间

3.4 同步时间

[root@node2 ~]# ntpdate -d -b 192.168.11.101

3.5 启动服务

[root@node2 ~]# systemctl start ntpdate
[root@node2 ~]# systemctl enable ntpdate.service #设置开机启动服务 

4. 测试

所有节点执行 date 命令看时间是否一致即可。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值