Centos7.4 集群ntp时间同步配置

一、实现功能

CDH集群搭建的时候,通过NTP配置时钟同步,从而可以使集群时间一致,保证集群运行基本条件。

二、环境

Centos7.4

三、配置ntp服务器

1.查看系统是否安装ntp

rpm -qa | grep ntp

2.安装ntp和ntpdate

yum -y install ntp ntpdate

3.查看是否已安装完成

[root@cdh1 ~]# rpm -qa | grep ntp        
ntp-4.2.6p5-29.el7.centos.x86_64
ntpdate-4.2.6p5-29.el7.centos.x86_64

4.配置ntp服务器

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 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

5.启动ntp服务并且设置开机启动

systemctl start ntpd
systemctl enable ntpd

6.查看状态

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

7. 查看是否同步

ntpq -p

备注:ntp服务器启动后,可能要等3-5min,才能检测到启动服务
 

四、客户端配置

1.查看系统是否安装ntp

rpm -qa | grep ntp

2.安装ntp和ntpdate

yum -y install ntp ntpdate

3.查看是否已安装完成

rpm -qa | grep ntp

4.配置ntp服务器

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

【cdh集群】
#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.0.108 #配置本地ntp服务器为时间同步服务器
restrict 192.168.0.108 nomodify notrap noquery #允许本地时间服务器主动修改本机的时间

5.手动同步一下

systemctl stop ntpd
ntpdate 10.2.31.25
systemctl start ntpd
【cdh集群】
[root@cdh2 ~]# systemctl stop ntpd
[root@cdh2 ~]# ntpdate 192.168.0.108
11 Feb 21:55:26 ntpdate[1266]: adjust time server 192.168.0.108 offset -0.000086 sec
[root@cdh2 ~]# systemctl start ntpd

6.检测与本地ntpd Server同步

ntpdate -u 10.2.31.25

centos7.4
[root@cdh3 ~]#  ntpdate -u 192.168.0.108
11 Feb 21:50:09 ntpdate[1215]: adjust time server 192.168.0.108 offset -0.140448 sec

7.启动ntp并且设置开机启动

systemctl start ntpd
systemctl enable ntpd

8.查看同步状态

ntpq -p

备注:服务器初次启动,大概要等3-5min,然后时间会自动同步,偏差会逐渐缩小

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CentOS 7 可以使用ntpd服务来配置NTP时间同步。首先,要安装ntpd服务:sudo yum install ntp。然后配置/etc/ntp.conf,添加NTP服务器列表。最后,启动ntpd服务:sudo systemctl start ntpd。 ### 回答2: 在CentOS 7上配置NTP时间同步,需要以下步骤: 1. 安装NTP软件包:打开终端,并使用root权限执行以下命令安装NTP软件包: `yum install ntp -y` 2. 配置NTP服务器:编辑NTP配置文件,通过以下命令打开它: `vi /etc/ntp.conf` 在文件的顶部添加以下行来配置NTP服务器: ``` server pool.ntp.org iburst server time.google.com iburst ``` 3. 更新防火墙规则:如果系统启用了防火墙,需要更新防火墙规则以允许NTP流量通过。执行以下命令更新防火墙规则: ``` firewall-cmd --zone=public --add-service=ntp --permanent firewall-cmd --reload ``` 4. 启用和启动NTP服务:使用以下命令启用和启动NTP服务: ``` systemctl enable ntpd systemctl start ntpd ``` 5. 检查NTP服务状态:执行以下命令来检查NTP服务的状态: `systemctl status ntpd` 6. 验证时间同步:使用以下命令验证时间同步是否成功: `ntpq -p` 如果出现一列以"*"开头的服务器,表示时间同步成功。 注意:以上步骤假设您具有root权限。如果没有root权限,请使用sudo命令来执行相应的命令。另外,根据自己的需求可以选择不同的NTP服务器进行配置。 ### 回答3: Centos 7配置NTP时间同步非常简单。您可以按照以下步骤进行设置: 1. 打开终端并以root用户身份登录到Centos 7系统中。 2. 使用以下命令安装ntp软件包: ``` yum install ntp ``` 3. 安装完成后,修改ntp配置文件。使用以下命令打开该文件: ``` vi /etc/ntp.conf ``` 4. 在打开的文件中,找到并注释掉以"server"开头的行,例如: ``` # server <服务器地址> ``` 然后,在下面添加以下行来指定要同步的时间服务器: ``` server ntp.ntsc.ac.cn iburst ``` 您可以根据需要选择其他可靠的NTP服务器。 5. 保存并关闭文件。 6. 启动ntp服务并设置其自动启动: ``` systemctl start ntpd systemctl enable ntpd ``` 7. 使用以下命令验证时间同步是否成功: ``` ntpq -p ``` 该命令将显示已同步到的时间服务器列表。 现在,您的Centos 7系统已配置为使用NTP时间同步。它将自动与指定的NTP服务器同步时间。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值