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

[经验分享] ntp服务器搭建与修改时区

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-11-21 17:35:18 | 显示全部楼层 |阅读模式

NTP是最长用的也是最基本的服务了,很多加密应用都依赖此服务,比如:openvpn、puppet、saltstack等都需要首先同步好时间,所以把搭建NTPserver总结下,方便以后自己查询。

首先下载ntp server源码包:ntp-4.2.6p5.tar,如附件。


解压,进入ntp-4.2.6p5目录开始安装,命令如下:
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install


安装完成后直接配置/etc/ntp.conf  是ntp这个包提供的配置文件,配置如下:

driftfile /var/lib/ntp/drift

#restrict default kod nomodify notrap nopeer noquery

restrict 58.55.127.0 mask 255.255.255.0 nomodify

restrict 221.235.188.0 mask 255.255.255.0 nomodify

restrict default nomodify notrap noquery

restrict -6 default kod nomodify notrap nopeer noquery

# 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

server 0.centos.pool.ntp.org

server 1.centos.pool.ntp.org

server 2.centos.pool.ntp.org


修改配置文件:

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

server 0.pool.ntp.org

#server 0.centos.pool.ntp.org

#server 1.centos.pool.ntp.org

#server 2.centos.pool.ntp.org


配置完成后开启ntp服务:

[iyunv@box logs]# /etc/init.d/ntpd restart

Shutting down ntpd:                                        [FAILED]

Starting ntpd:                                             [  OK  ]


查看服务是否正常运行:

root@box logs]# netstat -lntup |grep ntp

udp        0      0 192.168.2.137:123           0.0.0.0:*                               14010/ntpd         

udp        0      0 58.55.127.137:123           0.0.0.0:*                               14010/ntpd         

udp        0      0 127.0.0.1:123               0.0.0.0:*                               14010/ntpd         

udp        0      0 0.0.0.0:123                 0.0.0.0:*                               14010/ntpd         

udp        0      0 fe80::2a0:d1ff:feea:bd15:123 :::*                                    14010/ntpd         

udp        0      0 fe80::2a0:d1ff:feea:bd14:123 :::*                                    14010/ntpd         

udp        0      0 ::1:123                     :::*                                    14010/ntpd         

udp        0      0 :::123                      :::*                                    14010/ntpd   


查看NTP状态是否同步上层NTP服务器成功:

[iyunv@box logs]# ntpstat

synchronised to NTP server (83.137.98.96) at stratum 3

   time correct to within 499 ms

   polling server every 64 s

看到synchronised to NTP server,说明已经同步成功了,


查看NTP Server时间是否正确:

[iyunv@box logs]# date

Thu Sep  5 11:03:33 CST 2013

如果显示如下:

[iyunv@box logs]# ntpstat

unsynchronised

   polling server every 16 s

说明未同步成功,请检查配置是否修改正确。


还可以用这个命令查看;

[iyunv@box logs]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

spacys.de       130.133.1.10     2 u   35   64    3  346.738   -7.946   0.536

blueshift.trevo 209.51.161.238   2 u   56   64    1  252.679    0.387   0.000

jaded.fsck.ca   132.163.4.103    2 u   45   64    1  286.477  -37.529   0.000
每项含义可以参照:
http://baike.baidu.com/view/5874764.htm


PS:
每次重启NTP 服务器之后大约要3-5 分钟客户端才能与server 建立正常的通讯
切记每次修改了配置文件后都需要重新启动服务来使配置生效。


命令行修改时区三步:

[iyunv@localhost ~]# vi /etc/sysconfig/clock

ZONE="Asia/Shanghai"

[iyunv@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

cp: overwrite `/etc/localtime'? y

[iyunv@localhost ~]# date

Thu Sep  5 19:33:12 CST 2013


最后crontab中添加:

*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1

Ntpdate –u +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.iyunv.com/thread-32601-1-1.html 上篇帖子: centos6.5的yum源更改成163的源 下篇帖子: Redhat Enterprise 6.5安装步骤 服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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