linux7配置ntp服务器,Centos7.1 for NTP服务器配置

NTP服务器:network timeprotocol

BIOS内部芯片自身的特性易导致BIOS时间与UTC全球标准时间存在差异。时间同步(synchronize)能够有效地避免主机长时间运行导致的时间偏差。

NTP原理:1.NTP server开启daemon(监听端口号123为UDP的端口)

2.client向NTPserver发送校对时间的消息

3.NTP server回复当前的标准时间给client()

4.client收到来自NTPserver的回复之后,调整自己的时间

client可以自动计算传输过程中的时延;server负载若过重,可采用master/slave架构提供网络校时。

大多数NTP服务器在国外,国内也有一个第二级的NTP服务器(210.72.154.44),直接连国内这台即可。

配置ntp时间同步

1.准备环境:两台主机

172.17.220.145:作为第三级的时间服务器ntpd,用于与ntpd服务器110.75.190.198(阿里巴巴提供)同步时间

172.17.220.224:ntp客户端,用于与172.17.220.145同步时间

2.设置防火墙vi/etc/sysconfig/iptables

在“-AINPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT”后增加

-AINPUT -p udp -m state --state NEW -m udp --dport 123 -j ACCEPT

3.rpm包检查

c9fe3cb2307e8cf597c5522e6842cdcf.png

若没有安装,可通过yum install ntp安装。

4.设置系统开机自启及启动服务

Centos7默认通过chronyd服务实现时钟同步

4aa6fe375684c95a6b06c4f4db95b1ef.png

我们关闭chronyd服务并使其开机不自启,同时启动ntpd并将其加入开机自启[15:57:44root@localhost ~]# systemctl stop chronyd

[15:59:26root@localhost ~]# systemctl disable chronyd

[15:59:34root@localhost ~]# systemctl enable ntpd

[15:59:45root@localhost ~]# systemctl start ntpd

5.修改配置文件vi/etc/ntp.conf

#5.1设置对客户端的限制(4.2及以后的版本建议不要restricte notrush参数)

restrict172.17.220.0 mask 255.255.255.0 nomodify

:<

29ea92dd9ea4539108a835ad9f1e333e.png#5.2设置自身时间的服务器来源

#注释掉系统默认,尽量通过ip设置(减少dns解析时间)’

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

#server1.centos.pool.ntp.org iburst

#server2.centos.pool.ntp.org iburst

#server3.centos.pool.ntp.org iburst

server 110.75.190.198 perfer

server 202.108.6.95

server 202.112.29.82

#5.3设置自身为3级NTPserver

fudge 127.127.0.1 stratum 3

6.重新启动ntpd并查看

systemctlrestart ntpd:重启ntpd

ntpq–p查看ntpd

604f30befb7fa96ae4de558df25fb461.png

7.设置ntp客户端

7.1测试ntpd是否安装成功

ntpdate 172.17.220.145 #从ntpd(172.17.220.145)获取当前时间

date; hwclock –r #获取当前时间,通过hwclock–r写入bios时间

d767ddbc95e01c726d6abca45bcd5995.png

注:客户端不能同步,一般建议设置iptables后重启firewalld,或者直接关闭firewalld。

7.2设置自动同步(每隔三个小时更新一次时间)crontab –e

0 */1 * * * /usr/sbin/ntpdate 172.17.220.145;/sbin/hwclock -w >/dev/null 2>&1

crontab –l

0 */1 * * * /usr/sbin/ntpdate 172.17.220.145;/sbin/hwclock -w >/dev/null 2>&1

修改时区的命令#  cd /usr/share/zoneinfo #进入查找所有时区

# timedatectl set-timezone Asia/Shanghai

# timedatectl status

e4b8b7102575ad7d0248497985367b45.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值