linux防火墙添加udp 123,centos下的ntp的安装和配置 (注意 防火牆的udp 123要打開,不然會不能用)...
centos下的ntp的安装和配置安装 yum install
ntp
配置文件 /etc/ntp.conf
restrict default kod nomodify
notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1 # 用restrict控管权限
# nomodify - 用户端不能更改ntp服务器的时间参数
# noquery - 用户端不能使用ntpq,ntpc等命令来查询ntp服务器
# notrap - 不提供trap远端登陆
restrict 192.168.0.0 mask 255.255.0.0 nomodify
notrap
# 以下是两个ntp服务器
restrict cn.pool.ntp.org
restrict 164.67.62.194
# 用server设定上层ntp服务器,“prefer”表示优先
server cn.pool.ntp.org 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
一个说明:
我在vmware下搭建的ntp服务器,别人可以同步它,它自己的时间却不对。照理是它同步上层,下层同步它呀。后来找了蛮久的资料,发现这个文件:/etc/ntp/step-tickers,说是ntp服务器无法主动同步上层服务器,所以将地址写入该文件中即可。
我在物理机里暂时没发现这个问题,也许是物理机本来自己的时间就正确,就难以发现它有没有主动同步上层服务器。
运行ntp
service ntpd start/stop/restart
chkconfig ntpd on
查看ntp的端口,应该看到123端口
netstat -unlnp 查看ntp服务器有无和上层连通
[root@S5 ~]# ntpstat
synchronised to NTP server () at stratum 2
time correct to within 74 ms
polling server every 128 s
注意:此命令出现上述synchronised结果比较慢,我的用了大概5分钟。
查看ntp服务器与上层间的联系 [root@S5 ~]# ntptrace -n
127.0.0.1 127.0.0.1: stratum 2, offset 0.064524, synch
distance 0.121167
210.72.145.44: timed out, nothing received***Request timed
out
查看ntp服务器与上层ntp服务器的状态
[root@S5 ~]# ntpq -p
其中,
remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid - 参考上一层ntp主机地址
st - stratum阶层
when - 多少秒前曾经同步过时间
poll - 下次更新在多少秒后
reach - 已经向上层ntp服务器要求更新的次数
delay - 网络延迟
offset - 时间补偿
jitter - 系统时间与bios时间差
客户端同步时间的方法
方法一:使用 ntpdate
ntpdate [IP_Address]
看下面的例子,其中192.168.1.5是我在内网搭建的ntp服务器
[root@zy180 ~]# date
Thu Sep 25 13:04:17 CST 2008
[root@zy180 ~]# ntpdate 192.168.1.5
25 Sep 14:33:13 ntpdate[10302]: step time server 192.168.1.5 offset
5327.700798 sec
[root@zy180 ~]# date
Thu Sep 25 14:33:18 CST 2008
ntpdate 的特点:
1,ntpdate只运行一次就结束,即只同步一次。所以要使用ntpdate同步时间的话要将该命令写入cron中。
vi /etc/crontab
* * * * * root ntpdate 192.168.1.5
&& hwclock -w
之所以使用hwclock -w命令稍后再说。
2,ntpdate同步时间是跳跃的,如上面的显示,时间立即就同步了,这将可能导致文件时间标记、监控数据的紊乱。
方法二:使用ntpd服务
step1:/etc/ntpd.conf 写入 server [IP_Address]
step2:chkconfig ntpd on
step3:service ntpd start
大概过一刻钟开始起作用。
FAQ:系统报错 - Sep 25 11:59:39 localhost kernel: set_rtc_mmss: can't
update from 7 to 59
==================================网上查得源码==========================================
if (abs(real_minutes - cmos_minutes) < 30) {
update_cmos() } else { printk("set_rtc_mmss: can't update from %d
to %d\n", cmos_minutes, real_minutes); }
========================================================================================
bios时间与系统时间差异超过30分钟,就会报上述错误,只要修改bios时间或系统时间即可。
虚拟机下个人体验:
我的vm客户端用ntpd同步服务器后,慢慢变成标准时间,可接着又比标准时间越来越慢,然后出现上述报错。所以我觉得ntpd的同步频率比我的vm时钟频率跑得慢。
ntpd 的特点:
1,ntpd服务始终运行,定期同步时间。
2,ntpd服务是慢慢改变时间直至标准时间。
3,如果系统时间与bios时间差异超过30分钟,ntpd就会报错。
总结:
1,推荐使用 ntpd 服务。
2,ntpd开启后,无法使用ntpdate,看如下例子:
[root@zy180 ~]# service ntpd start
Starting ntpd: [ OK ]
[root@zy180 ~]# ntpdate 192.168.1.5
25 Sep 15:25:22 ntpdate[12334]: the NTP socket is in use,
exiting
附:linux的时间、时区 1,时间
系统时间:date 命令
bios时间:hwclock命令 (-r 读取bios时间,-w 写入bios时间)
每次开机时系统重新读bios时间。
所以前面ntpdate命令时的cron脚本需要用到hwclock,以避免机器重启后时间混乱。
2,时区
linux的所有时区文件都放在 /usr/share/zoneinfo 下。
linux系统的时区文件是
/etc/localtime,这是个时间格式的档案,不是ACSII码。它与/usr/share/zoneinfo/下的自己的时区文件是一样的。
我的时区是Asia-Shanghai,用diff比较两个文件,如下:
[root@zy180 ~]# diff /usr/share/zoneinfo/Asia/Shanghai
/etc/localtime
[root@zy180 ~]#
在 /etc/sysconfig/clock 文件中也写有本时区的信息:
[root@zy180 ~]# cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false
NTP时间服务器:
使用环境:当一个计算机群体需要需要进行时间的严格同步,即可使用NTP服务器。
NTP通信协议原理:
1.首先主机启动NTP。
2.客户端会向NTP服务器发送调整时间的message。
3.然后NTP server会送出当前的标准时间给client
4.client接受来自server的时间后,会根据这个信息来调整自己的时间。这样就实现了网络对时。
NTP这个deamon采用了123端口。(UDP)
“当我们要利用Tim server来进行实践的同步更新时,就需要使用NTP软件提供的ntpdate来连接端口123”
安装:
首先检查是否安装了组建:
[root@testmechine ~]# rpm -qa ntp
ntp-4.2.2p1-9.el5.centos.1
假如没有安装则yum install ntp来进行安装。
所需要的配置文件:
1./etc/ntp.conf
linux各版本虽然目录不同,但文件名相同。可以用which ntp.conf 或者locate
ntp.conf来查找。这是NTP唯一的一个设置文件。
2./usr/share/zoneinfo/
这个里面规定了这个主要时区的时间设置文件。
3./etc/sysconfig/clock
这个文件是linux的主要时区设置文件,每次开机后linux会自动读取这个文件来设置系统所默认的显示时间,可以看看它里面到底设置了什么:
[root@testmechine sysconfig]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of
/etc/localtime.
ZONE="Asia/Shanghai"
UTC=true
ARC=false
4./etc/localtime
本地端时间配置文件。
5./bin/date
这个是时间的修改命令,除了输出时间,还可以修改时间。
6./sbin/hwclock
因为linux系统上面BIOS时间与linux系统时间是分开的,所以使用date这个指令调整了时间之后,还需要使用hwclock才能将修改过的时间写入BIOS中。
7./usr/sbin/ntpd
这是NTP的daemon文件,需要启动它才能提供NTP服务,这个命令会读取/etc/ntp.conf里面的设置。
8./usr/sbin/ntpdate
这是client用来连接NTP Server的主要执行文件,如果您不想启用NTP,只想启用NTP
Client功能的话,可以只应用此命令。
9,/usr/sbin/ntptrace
可以用来追踪某台时间服务器的时间对应关系。
NTP时间服务器采用类似于分层的架构:
关于ntp.conf的设置:
[root@testmechine ~]# cat /etc/ntp.conf
# 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
#添加如下命令:
restrict default nomodify noquery notrap
restrict 202.112.10.60
restrict 202.106.199.36
restrict 202.112.7.150
restrict 127.0.0.1 mask 255.0.0.0
restrict 192.168.0.0 mask 255.255.255.0 nomodify
# 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
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
#进行如下替换
server time.buptnet.edu.cn
server s1b.time.edu.cn
server s1c.time.edu.cn
server s1d.time.edu.cn
#broadcast 192.168.1.255 key
42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key
42 # multicast server
#multicastclient
224.0.1.1 # multicast client
#manycastserver
239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for
backup
# and when no outside source of synchronized time is available.
#加入如下代码:
server 202.112.10.60 prefer #以这台主机最优先
server 202.106.199.36
server 202.112.7.150
server
127.127.1.0 # local clock
fudge 127.127.1.0 stratum
10
# Drift file. Put this in a directory which the daemon can write
to.
# No symbolic links allowed, either, since the daemon updates the
file
# by creating a temporary in the same directory and then
rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift
# 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
[root@testmechine ~]#
以上是ntp.conf的最终设置。
然后我们修改/etc/sysconfig/ntpd:
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"
# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=yes #make no into yes; BIOS的时间也会跟着修改
# Additional options for ntpdate
NTPDATE_OPTIONS=""
启动NTP:
[root@testmechine ~]# /etc/init.d/ntpd start
Starting ntpd: [ OK ]、
看看端口启动情况:
[root@testmechine ~]# netstat -nltpu|grep ntpd
udp 0 0
192.168.0.20:123 0.0.0.0:* 7237/ntpd udp 0 0
127.0.0.1:123 0.0.0.0:* 7237/ntpd udp 0 0
0.0.0.0:123 0.0.0.0:* 7237/ntpd udp 0 0
::1:123 :::*
linux防火墙添加udp 123,centos下的ntp的安装和配置 (注意 防火牆的udp 123要打開,不然會不能用)...相关推荐
- Linux Centos下SQL Server 2017安装和配置
Linux Centos下SQL Server 2017安装和配置 原文:Linux Centos下SQL Server 2017安装和配置 我们知道在Linux下安装服务有很多方式,最为简单的也就是 ...
- linux 双网卡主备,CentOS下双网卡主备模式配置
CentOS下双网卡主备模式配置 1简述 通过双网卡设置主备模式,实现当一块网卡宕掉时,另外一块网卡可以自动顶替宕掉的网卡工作,保障网络正常访问. 2实现 2.1.查看网卡信息 执行ifconfig ...
- linux防火墙的复规则,Centos下iptables防火墙规则编辑方法 - YangJunwei
今天整理一下Centos下iptables防火墙规则的保存.清除等编辑方法. 如已经安装,请跳过. $ yum install iptables 二.查看 iptables 防火墙已有规则 以下四种方 ...
- CentOS下Apache服务器的安装与配置
配置服务文件参数 服务目录 /etc/httpd 配置文件 /etc/httpd/conf/httpd.conf 网站数据目录 /var/www/html 访问目录 /var/log/httpd/ac ...
- linux下centos安装mysql数据库_Linux CentOS 下的MySQL数据库安装与配置-阿里云开发者社区...
安装mysql yum -y install mysql yum -y install mysql-server yum -y install php-mysql yum -y install mys ...
- CentOS下Samba文件服务器的安装与配置
前言:文件服务器提供的服务在大多数公司或企业都会被用到,因为在任何的公司或企业都涉及不同职位获取不同资源文件的情况,这就需要根据不同职位配置相关的不同权限,以保证相关资源文件的安全性和保密性. 一.S ...
- Linux中fcitx输入法配置文件,Ubuntu下Fcitx输入法的安装与配置
Fcitx 大家不陌生吧..支持五笔拼音混输.日文,棒子文.等等.很牛b的国人精品Linux输入法.而且,界面友好. 注:以上图片上传到红联Linux系统教程频道中. 对于.一些朋友安装之后出现Fci ...
- linux 安装rpm qt can't creat,centos 下 Qt Creator 的安装使用
centos 下 Qt Creator 的安装使用 Qt 以其开源,免费,完全面向对象(很容易扩展),允许真正的组件编程以及可移植跨平台等诸多优势得到越来越多的开发人员的青睐.Qt Creator 是 ...
- linux的mysql本地yum安装_Linux Centos 下使用yum 命令安装mysql实现步骤
Linux Centos 下使用yum 命令安装mysql实现步骤 1. 查看服务器中有没有安装过Mysql 1. 查看有没有安装包: yum list mysql* #移除已经安装的mysql yu ...
最新文章
- 高考计算机如何检索投档,2021年高考平行志愿如何投档?
- Caffe学习系列(11):图像数据转换成db(leveldb/lmdb)文件
- python异步编程视频_asyncio异步编程【含视频教程】
- 剑指 Offer II 014. 字符串中的变位词
- python函数不同类型参数顺序
- 人力资源大数据公司_大数据与人力资源相结合,平衡透明度和隐私
- java实现微信支付
- Atitit ppt转换文本txt 目录 1.1. Atitit word ppt excel convert txt bp 等文档转换纯文本问题最佳实践.docx	1 1.2. 跨语言转换Open
- asp导出word中文乱码_你还在加班吗?“蟒蛇”办公自动化Word篇——一招搞定300页文档
- 小米8,全面屏手机判断是否显示虚拟键
- ffmpeg用法及如何使用fluent-ffmpeg
- oracle 取农历函数,完善SQL农历转换函数
- 结巴 python_结巴中文分词使用学习(python)
- Java扫码点餐小程序源码 SaaS系统源码 微信、支付宝扫码点餐小程序源代码
- EXCEL编程经验总结
- 链接太长如何缩短?稳定的短链接api接口分享与用法实例
- 开源存储这么香,为何我们还要坚持自研?
- [译] 讨论 JS ⚡:文档
- 基于微信小程序菜谱小程序毕业设计开题报告功能参考
- 美国南加州大学研究生计算机专业申请条件,南加州大学申请条件
热门文章
- “兴趣社区2.0”俘获年轻人
- 最具中产气质的“网易考拉”,离“中国版Costco”还有多远?
- php 扩展包是什么意思,大家知道扩展用户组是什么意思么??
- python教程:一篇文章让你理解字符串的格式化
- Python基础练习题:猜数字小游戏
- Python函数的递归调用
- python的可变对象和不可变对象
- Python基础教程:自定义函数
- Python常用模块之configparser
- linux下 面向对象语言,人工智能(AI)程序设计(面向对象语言)PDF+PPT与习题等...