Linux:NTP服务离线安装及配置

0、常用命令:

      rpm -qa | grep ntp     #查询已安装的ntp版本信息等

      service ntpd status    #查询ntp服务状态

      service ntpd start      #启动

      service ntpd stop      #停止

      service ntpd restart   #重启

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

      ntpstat     #命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。

                     刚启动的时候,一般是:

# ntpstat 

  unsynchronised

  time server re-starting

  polling server every 64 s

                    连接同步后:

synchronised to NTP server (202.120.2.101) at stratum 4 

   time correct to within 1192 ms

   polling server every 64 s

1、下载ntp的安装包:

      下载地址:https://download.csdn.net/download/qq_29171935/10975073
       ntp:可以为其配置ntp.conf将其设置为自动同步某服务器时钟。
       ntpdate:可以使用 ntpdate -u ip地址 来手动同步某服务器的时钟。

 

2、安装命令:
    

     方式(1) rpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpm


      若出现找不到依赖则使用下面的命令:

      方式(2)rpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpm --nodeps --force
 

      本人在使用方式(2)后使用rpm -qa | grep ntp 后看到了ntp,但是没有在/etc里看到ntp.conf。于是乎又使用方式一重新安装了一遍,这个文件出现了。(玄学)

3、客户端配置:(/etc/ntp.conf)

[root@localhost etc]# cat ntp.conf 

//然后添加这两行 ,意思是 允许IPV4 IPV6 查询 拒绝修改
restrict -4 default kod notrap nomodify   
restrict -6 default kod notrap nomodify
//允许上层进行修改本机时间
//restrict 10.173.24.27 nomodify notrap noquery
//配置上层server(要同步的),在这里配置的是实际的物理地址
server 10.173.24.27  
fudge 10.173.24.27 stratum 8 

[root@localhost etc]# 

4、服务器配置:(/etc/ntp.conf)

[root@localhost etc]# cat ntp.conf
  
//然后添加这两行 ,意思是 允许IPV4 IPV6 查询 拒绝修改
restrict -4 default kod notrap nomodify   
restrict -6 default kod notrap nomodify 
//添加修改上层时间服务器,如果能联通外网,则不需要修改,
//server 0.rhel.pool.ntp.org iburst
//server 1.rhel.pool.ntp.org iburst
//server 2.rhel.pool.ntp.org iburst
//server 3.rhel.pool.ntp.org iburst
//如果联不通外网,则把上面几行注释,然后添加下面两行,意思是设置成时间服务器是自己
server 127.127.1.0
fudge 127.127.1.0 stratum 8

[root@localhost etc]# 

5、测试(ntpstat一般是过个5-10分钟才能同步)

      (1)服务器:

[root@localhost etc]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           8 l   36   64  377    0.000    0.000   0.000


[root@localhost etc]# ntpstat

synchronised to local net at stratum 9 
   time correct to within 12 ms
   polling server every 64 s

     (2)客户端:

[root@localhost etc]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*10.173.24.27    LOCAL(0)         9 u   40   64  377    1.108    2.560   0.764


[root@localhost etc]# ntpstat

synchronised to NTP server (10.173.24.27) at stratum 10 
   time correct to within 461 ms
   polling server every 64 s

6、日志设置

[root@localhost sysconfig]# pwd
/etc/sysconfig

[root@localhost sysconfig]#cat ntpd

# Command line options for ntpd
OPTIONS="-g -l /var/log/ntpstats/ntpd.log"

[root@localhost ntpstats]# service ntpd stop

[root@localhost ntpstats]# service ntpd start 

[root@localhost ntpstats]# service ntpd status

[root@localhost ntpstats]# tail -200f /var/log/ntpstats/ntpd.log

 

 

 

 

 

                                                                                                底线


 

  • 14
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Linux 中,如果你的系统无法连接到互联网或者没有网络连接,你仍然可以离线安装 NTP。 以下是离线安装 NTP 的步骤: 1. 在可以访问互联网的机器上,下载 NTP 的二进制包和依赖包。你可以在官方的 NTP 网站(http://www.ntp.org/downloads.html)上找到合适的版本。选择与你的 Linux 发行版和架构相匹配的二进制包。 2. 将下载好的二进制包和依赖包拷贝到离线机器上,可以使用 USB 存储设备或者其他传输方式。 3. 在离线机器上,打开终端并切换到二进制包所在的目录。 4. 安装依赖包。使用以下命令安装依赖包,例如: ``` sudo apt-get install <dependency_package_name> ``` 注意替换 `<dependency_package_name>` 为实际的依赖包名称。 5. 安装 NTP 二进制包。使用以下命令安装 NTP,例如: ``` sudo dpkg -i <ntp_package_name.deb> ``` 注意替换 `<ntp_package_name.deb>` 为实际的 NTP 二进制包名称。 6. 安装完成后,可以使用以下命令启动 NTP 服务: ``` sudo service ntp start ``` 7. 验证 NTP 是否成功安装和运行,可以使用以下命令检查 NTP 服务状态: ``` sudo service ntp status ``` 如果返回类似于 "active (running)" 的结果,表示 NTP 服务已成功启动。 这样,你就可以在离线的环境中安装和运行 NTP 服务来同步时间了。请确保下载的二进制包和依赖包与你的系统兼容,并按照上述步骤进行操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值