linux ntp配置文件在哪

linux ntp配置文件在哪,第1张

linux ntp时间服务器及客户端安装配置1、主要文件及命令: /etc/ntp/bin/view/Main/SoftwareDownloads下载,安装RPM包: [root@localhost ~]# rpm -ivh ntp-4.2.2p1-9.el5_4.1.rpm3、备份一下配置文件 cp /etc/ntp.conf /etc/ntp.conf_bak4、ntp.conf文件主要参数说明: 4.1、利用 restrict 来管理权限控制restrict [你的IP] mask [netmask_IP] [parameter]其中 parameter 的参数主要有底下这些:ignore: 拒绝所有类型的 NTP 联机;nomodify: 客户端不能使用 ntpc 与 ntpq 这两支程序来修改服务器的时间参数, 但客户端仍可透过这部主机来进行网络校时的;noquery: 客户端不能够使用 ntpq, ntpc 等指令来查询时间服务器,等于不提供 NTP 的网络校时;notrap: 不提供 trap 这个远程事件登录 (remote event logging) 的功能。notrust: 拒绝没有认证的客户端。 4.2、利用 server 设定上层 NTP 服务器server [IP or hostname] [prefer] perfer 表示‘优先使用’5、具体配置如下: 原来的上层服务器及对上层的限制注释掉,然后直接加上这几项 server 210.72.145.44 prefer server time.nist.gov restrict 210.72.145.44 mask 255.255.255.255 nomodify notrap noquery restrict time.nist.gov mask 255.255.255.255 nomodify notrap noquery restrict 192.168.1.0 mask 255.255.255.0 nomodify #对内网访问开放,不同网段设置要改一下 6、重启服务:/etc/init.d/ntpd restart 7、加入开机启动:chkconfig ntpd on8、查看系统日志看有没有报错:tail /var/log/messages9、查看启动的端口:netstat -tlunp grep ntp10、检查与上层服务器是否同步成功(约15分钟后才会和上层连接): ntpstat 或 ntpq -p11、先对服务器进行手动较正,要不误差超过1000秒的话服务会自动停掉: date MMDDHHMMCCYY.SS #设置时间,格式:月月日日时时分分年年.秒秒 /etc/init.d/ntpd stop #要把服务停掉,因为ntp与ntpdate不能同时生效 ntpdate 210.72.145.44 hwclock -w #写入硬件时间,-r是显示硬件时间 /etc/init.d/ntpd restart 12、别的客户端要进行同步,则这样处理: vim /etc/crontab */10 * * * * root (/usr/sbin/ntpdate 210.72.145.44 &&/sbin/hwclock -w) &>/dev/null /etc/init.d/crond restart13、要点: linux 系统本来就有两种时间,一种是 linux 以 1970/01/01 开始计数的系统时间,一种则是 BIOS 记载的硬件时间; linux 可以透过网络校时,最常见的网络校时为使用 NTP 服务器,这个服务启动在 udp port 123; 时区档案主要放置于 /usr/share/zoneinfo/ 目录下,而本地时区则参考 /etc/localtime; NTP 服务器为一种阶层式的服务,所以 NTP 服务器本来就会与上层时间服务器作时间的同步化, 因此 nptd 与 ntpdate 两个指令不可同时使用; NTP 服务器的联机状态可以使用 ntpstat 及 ntpq -p 来查询; NTP 提供的客户端软件为 ntpdate 这个指令; 在 linux 下想要手动处理时间时,需以 date 设定时间后,以 hwclock -w 来写入 BIOS 所记录的时间。 NTP 服务器之间的时间误差不可超过 1000 秒,否则 NTP 服务会自动关闭。

配置的时钟服务器的ip地址为192.168.100.116

第一步  为服务器和客户机安装ntp  ntpdate

[root@sql-proxy1 app]#yum install ntp ntpdate -y第二步 查找时间同步服务器

http://www.pool.ntp.org/zone/asia #在里面可以找到中国第三步  编辑 /etc/ntp.conf

[root@sql-proxy1 app]#vim /etc/ntp.conf server 0.cn.pool.ntp.org

server 1.cn.pool.ntp.org

server 2.cn.pool.ntp.org

server 3.cn.pool.ntp.org #以上四个是时间同步服务器server 127.127.1.0 iburst local clock #当外部时间不可用时,使用本地时间restrict 192.168.10.1 mask 255.255.255.0 nomodify #允许更新的IP地址段第四步  启动ntp服务

[root@sql-proxy1 app]#systemctl start ntpd第五步  验证服务

[root@sql-proxy1 app]#ntpq -p    remote          refid      st t when poll reach  delay  offset  jitter

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

120.25.115.19  .INIT.          16 u    -  64    0    0.000    0.000  0.000

ntp6.flashdance .INIT.          16 u    -  64    0    0.000    0.000  0.000

time5.aliyun.co .INIT.          16 u    -  64    0    0.000    0.000  0.000

85.199.214.101  .INIT.          16 u    -  64    0    0.000    0.000  0.000

biisoni.miuku.n .INIT.          16 u    -  64    0    0.000    0.000  0.000

ntp5.flashdance .INIT.          16 u    -  64    0    0.000    0.000  0.000

leontp.ccgs.wa. .INIT.          16 u    -  64    0    0.000    0.000  0.000

ntp1.ams1.nl.le .INIT.          16 u    -  64    0    0.000    0.000  0.000

*LOCAL(0)        .LOCL.          5 l    7  64    1    0.000    0.000  0.000

第六步  远程客户端时间同步测试

[root@sql-mysql2 ~]#ntpdate 192.168.10.116 17 Dec 20:55:08 ntpdate[11904]: adjust time server 172.18.68.31 offset -0.000067 sec

第七步 客户端设置计划任务,每天晚上1点同步时间

crontab -e

00 01 * * * root /usr/sbin/ntpdate 192.168.10.116/usr/sbin/clock -w

EDT 时间即美国东部时间。这里要改为北京时间即可:

命令如下:

root@ubuntu# mv /etc/localtime /etc/localtime.bak 

root@ubuntu# ln -s /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime 

root@ubuntu# date 

修改116服务器本机的ntp时间同步

systemctl stop ntpd

ntpdate cn.pool.ntp.org

systemctl start ntpd

rpm -qa |grep ntp     #检查ntp版本

service ntpd status    #查询ntp服务状态

service ntpd start      #启动

service ntpd stop      #停止

service ntpd restart   #重启

ntpq -p   #查看ntp服务器与上层ntp的状态


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7170430.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存