码迷,mamicode.com
首页 > 其他好文 > 详细

Centos7.1 for NTP服务器配置

时间:2016-07-14 19:32:28      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:network   服务器   master   防火墙   server   

NTP服务器:network timeprotocol

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

NTP原理:

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

  2. 2.   clientNTPserver发送校对时间的消息

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

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

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

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

配置ntp时间同步

1.准备环境:两台主机

172.17.220.145:作为第三级的时间服务器ntpd,用于与二级标准时间服务器210.72.154.44同步时间

172.17.220.224ntp客户端,用于与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包检查

技术分享

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

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

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

技术分享

我们关闭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设置对客户端的限制
restrict172.17.220.0 mask 255.255.255.0 nomodify
:<<’restrict参数

技术分享

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
server110.75.190.198 perfer
server202.108.6.95
server202.112.29.82
#5.3设置自身为3级NTPserver
fudge172.17.220.145 stratum 3

6.重新启动ntpd并查看

systemctlrestart ntpd重启ntpd

ntpq–p查看ntpd

技术分享

7.设置ntp客户端

7.1 测试ntpd是否安装成功

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

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

技术分享

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

  crontab –e
0 */1 * * * /usr/sbin/ntpdate192.168.0.240;/sbin/hwclock –w 
crontab –l

技术分享

修改时区的命令

#cd /usr/share/zoneinfo #进入查找所有时区
# timedatectl set-timezone Asia/Shanghai
# timedatectl status

技术分享

Centos7.1 for NTP服务器配置

标签:network   服务器   master   防火墙   server   

原文地址:http://bigtrash.blog.51cto.com/8966424/1826481

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!