cengos 5.5搭建NTP服务器

简介:

#为了保证应用程序层和数据库层的服务器能够同步时钟,所以要架设一台NTP服务器,让内部所有的服务器来同步NTP服务器的时钟

#检查服务器是否安装ntp
[root@ntp ~]# rpm -qa |grep ntp

#yum安装ntp
[root@ntp ~]# yum install -y ntp

#源码包安装ntp
[root@ntp ~]# wget 
http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p2.tar.gz
[root@ntp ~]# tar -zxvf ntp-4.2.6p2.tar.gz
[root@ntp ~]# cd ntp-4.2.6p2
[root@ntp ntp-4.2.6p2]# ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
[root@ntp ntp-4.2.6p2]# make;make install

#让本服务器时间与time.nist.gov时间同步,使服务器为标准时间
[root@ntp ~]# ntpdate time.nist.gov

#自动同步服务器时钟
[root@ntp ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate time.nist.gov

[root@ntp ~]# service crond restart

#修改ntp配置文件
[root@ntp ~]# vi /etc/ntp.conf

# 用restrict控管权限
# nomodify - 用户端不能更改ntp服务器的时间参数
# noquery - 用户端不能使用ntpq,ntpc等命令来查询ntp服务器
# notrap - 不提供trap远端登陆

#允许任何IP的客户机都可以进行时间同步
#restrict default nomodify notrap noquery  //注释掉这一行
restrict default nomodify

#只允许10.8.0.0网段的客户机进行时间同步
restrict default nomodify notrap noquery
restrict 10.8.0.0 mask 255.255.0.0 nomodify     //添加一行

# 以下是两个ntp服务器
restrict time.nist.gov
restrict 164.67.62.194

# 用server设定上层ntp服务器,“prefer”表示优先
server time.nist.gov prefer
server 164.67.62.194
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

# 系统时间与bios事件的偏差记录
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

# 日志
logfile /var/log/ntp.log
broadcastdelay 0.008

#BIOS时间同步
SYNC_HWCLOCK=yes


#yum安装启动方式
[root@ntp ~]# service ntpd start

#源码包安装以守护进程启动ntpd
[root@ntp ~]# /usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid

#查看端口
[root@ntp ~]# netstat -unlnp

#iptables开启udp 123端口
[root@ntp ~]# iptables -A INPUT -p udp -m udp --dport 123 -j ACCEPT

#查看ntp服务器有无和上层连通
[root@ntp ~]# ntpstat

#查看ntp服务器与上层间的联系
[root@ntp ~]# ntptrace -n time.nist.gov
time.nist.gov: stratum 1, offset 0.000000, synch distance 0.002650, refid 'ACTS'

查看ntp服务器与上层ntp服务器的状态
[root@ntp ~]# ntpq -p

remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid - 参考上一层ntp主机地址
st - stratum阶层
when - 多少秒前曾经同步过时间
poll - 下次更新在多少秒后
reach - 已经向上层ntp服务器要求更新的次数
delay - 网络延迟
offset - 时间补偿
jitter - 系统时间与bios时间差

#linux客户端同步NTP服务器时钟
[root@db_1 ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate 10.8.2.10

#winsows客户端同步NTP服务器时钟



本文转自king_819 51CTO博客,原文链接:http://blog.51cto.com/kerry/394513,如需转载请自行联系原作者

相关文章
|
网络协议 算法 定位技术
利用GPS北斗卫星系统开发NTP网络时间服务器
利用GPS北斗卫星系统开发NTP网络时间服务器
|
监控 Linux 定位技术
Linux【环境部署 01】NTP时间服务器搭建及Linux+Windows客户端使用(一篇学会使用NTP服务)
Linux【环境部署 01】NTP时间服务器搭建及Linux+Windows客户端使用(一篇学会使用NTP服务)
3667 0
|
网络安全
构建 NTP 时间服务器
构建 NTP 时间服务器
764 2
|
Linux 数据库
ntp如何配置同步服务器
【5月更文挑战第19天】ntp如何配置同步服务器
2104 2
|
缓存 Linux 开发工具
centos设置ntp服务同步目标服务器时间
【7 月更文挑战第 1天】linux+centos设置ntp服务同步目标服务器时间
|
Linux 数据库
ntp如何配置同步服务器
【5月更文挑战第24天】ntp如何配置同步服务器
1266 0
|
2月前
|
弹性计算 运维 安全
阿里云轻量应用服务器与云服务器ECS啥区别?新手帮助教程
阿里云轻量应用服务器适合个人开发者搭建博客、测试环境等低流量场景,操作简单、成本低;ECS适用于企业级高负载业务,功能强大、灵活可扩展。二者在性能、网络、镜像及运维管理上差异显著,用户应根据实际需求选择。
225 10
|
2月前
|
运维 安全 Ubuntu
阿里云渠道商:服务器操作系统怎么选?
阿里云提供丰富操作系统镜像,涵盖Windows与主流Linux发行版。选型需综合技术兼容性、运维成本、安全稳定等因素。推荐Alibaba Cloud Linux、Ubuntu等用于Web与容器场景,Windows Server支撑.NET应用。建议优先选用LTS版本并进行测试验证,通过标准化镜像管理提升部署效率与一致性。
|
2月前
|
弹性计算 ice
阿里云4核8g服务器多少钱一年?1个月和1小时价格,省钱购买方法分享
阿里云4核8G服务器价格因实例类型而异,经济型e实例约159元/月,计算型c9i约371元/月,按小时计费最低0.45元。实际购买享折扣,1年最高可省至1578元,附主流ECS实例及CPU型号参考。
355 8

热门文章

最新文章