设为首页 收藏本站
查看: 481|回复: 0

[经验分享] linux ntp时间服务器配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-22 10:32:13 | 显示全部楼层 |阅读模式
ntp (network time protocol)网络时间协议

1、检测是否已经安装ntp
   rpm -qa ntp
  如果没有安装就直接yum安装
   yum install -y ntp

2、 配置/etc/ntp.conf文件
   先备份原始文件   cp /etc/ntp.conf /etc/ntp.conf.bak
配置文件的内容如下


# 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  
与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内

# Permit time synchronization with our time source, but do not   
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery   将此行注释掉
restrict -6 default kod nomodify notrap nopeer noquery  禁止ipv6的ntp同步
restrict default nomodify  添加此行,默认对所有客户端开放
权限的设定主要以 restrict 这个参数来设定,主要的语法为: restrict IP地址 mask 子网掩码 参数
其中 IP 可以是IP地址,也可以是 default ,default 就是指所有的IP
参数有以下几个:
ignore :关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询
注意:如果参数没有设定,那就表示该 IP (或子网)没有任何限制!


# 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 -6 ::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 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   上级时间服务器地址

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
3、/etc/ntp.conf配置完之后,保存退出。关闭防火墙,开启ntp服务。
service iptables stop  关闭服务器
service ntpd  start   开启ntp服务
4、查看配置是否正确
[iyunv@localhost etc]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*nist1-lnk.binar .ACTS.           1 u   62  128  177  273.310  -14.041  63.275
这种显示配置成功。
remote:本地机器所连接的ntp远程服务器

refid:给远程服务器提供时间同步的服务器
st:ntp服务器的等级,从1-16
t:这个还不知道
when:还有多久就进行ntp时间同步
poll:每隔多久就ntp时间同步
reach:是否与ntp服务器连接,每连接一次增加1
dalay:从本地发送同步要求到ntp服务器的时间
offset:本地与ntp服务器的时间差别
jitter:在特定连接数里offset的分布情况,数值越小越精确
5、 查看每次更新间隔
[iyunv@localhost etc]# ntpstat
synchronised to NTP server (216.229.0.179) at stratum 2 本ntp服务器层次为2,已从216.229.0.179同步过
   time correct to within 159 ms  校验差在159ms
   polling server every 128 s   每隔128s同步一次
6、每次同步只是同步系统时间,同时要同步bios时间。

hwclock -w  即可同步bios时间
7、客户端同步时间。
ntpdate ntp服务器ip地址


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-261303-1-1.html 上篇帖子: 磁盘分区工具fdisk和parted实战操作演练 下篇帖子: linux系统调优及安全设置(oldboy notes) 服务器 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表