linux 调试ntp服务,linux中配置NTP基本操作

计算机的系统时间是由计算机内的石英晶体震荡电路以固定的震荡频率产生的

NTP基于UDP报文进行传输,使用的UDP端口号123

适用于场合:

1、采集日志信息,分析调试信息时间作为参看依据

2、计费系统要求所有设备的时钟保持一致

3、定时重启网络中的所有设备

4、多个系统协同处理同一个比较复杂的事件时,为了保证正确的执行顺序,多个系统必须参考同一时钟

5、备份服务器数据,要求备份服务器和所有客户端之间的时钟同步

第一步、修改时区配置文件

cat /etc/sysconfig/clock#查看所属时区

[root@localhost ~]# vim /etc/sysconfig/clock

ZONE="America/New_York"

#改为

ZONE="Asia/Shanghai"

覆盖 /etc/localtime

cp -a /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

cp: overwrite `/etc/localtime'? y

第二步、配置系统时间(同步时间)

date:查看系统时间

clock:查看硬件时间

查看日期:cal

date 111317402016#修改系统时间为(2016年11月13日17点40分)

hwclock -w将系统时间同步到硬件时间(硬件时间比较精确)

hwclock -s 将硬件时间写到系统上

第三步、检查是否安装ntp服务

[root@localhost ~]# rpm -qa |grep ntp

[root@localhost ~]# yum install ntp* -y#安装ntp服务

第四步、配置ntp文件

vim /etc/sysconfig/ntpdate#设置同步更新本地hwclock

在 Linux 下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了那么既然两个时钟独自运行,那么时间久了必然就会产生误差了,而 NTP 默认又只更新系统时间,因此我们需要设置硬件时钟进行同步调整

[root@mini ~]# vim /etc/ntp.conf

For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# 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#禁用全部地址对NTPD各服务的访问

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#允许本机地址(127.0.0.1)对NTPD各服务的访问

restrict -6 ::1  #ipv6

# Hosts on local network are less restricted.

restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap #允许地址段192.168.100.0对NTPD各服务的访问,但不允许此地址段内客户端修改NTPD服务器时间

# Use public servers from the pool.ntp.org project.

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

#server 0.rhel.pool.ntp.org

#server 1.rhel.pool.ntp.org

#server 2.rhel.pool.ntp.org

#broadcast 192.168.1.255 autokey        # broadcast server

#broadcastclient                        # broadcast client

#broadcast 224.0.1.1 autokey            # multicast server

#multicastclient 224.0.1.1              # multicast client

#manycastserver 239.255.254.254         # manycast server

#manycastclient 239.255.254.254 autokey # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup

# and when no outside source of synchronized time is available.

server  127.127.1.0     # local clock  #外部时间服务器不可用时,以本地时间作为时间服务

fudge   127.127.1.0 stratum 10 #设置本地时钟源的层次为10,这样如果NTPD服务从本地时钟源获取时间的话,NTPD对外宣布的时间层次为11

...........................................................

第五步、重启ntp服务

[root@localhost ~]# service ntpd restart

第六步、查看ntp状态

ps aux |  grep ntpd  查看ntp进程

ntpq -p列出目前ntp相关的状态

第七步、关闭防火墙

vim /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

sestatus#查看selinux状态

ntpdate server地址  客户机同步服务器时间

注:同步需要一段时间

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux上搭建NTP校时服务器可以按照以下步骤进行操作: 1. 首先需要安装NTP软件,可以使用命令sudo apt-get install ntp来安装NTP。 2. 安装完成后,编辑/etc/ntp.conf文件,将搭建的NTP服务端加入server时钟源。可以在文件添加类似于server time.nist.gov的行,其time.nist.gov是一个常用的NTP服务器。 3. 设置NTP自动同步,可以使用sudo crontab -e命令来编辑定时同步任务。在文件添加类似于ntpdate time.nist.gov的行,设置时间间隔至少1分钟以上,以免对NTP服务器造成过大的负担。 4. 完成以上配置后,保存文件并退出编辑器。 5. 最后,重新启动NTP服务,可以使用sudo service ntp restart命令来重启NTP服务。 需要注意的是,在配置NTP服务器时,可以参考引用提到的方法,同时可以使用ntpdate命令手动同步系统时钟和远程时间服务器的时间,使用ntpq命令查询NTP服务器的状态和性能。另外,还可以使用其他一些常用的NTP命令,如ntpstat用于显示系统时钟和NTP服务器之间的时间差,ntpdc用于与NTP服务器进行交互和调试ntptrace用于跟踪NTP服务器之间的路径,ntp-wait用于等待NTP服务器同步等。这些命令可以帮助我们进行NTP校时服务器的配置调试。引用提供了关于ntpq命令的参数含义和备注说明。 请注意,以上步骤仅为一种常用的方法,根据具体情况可能会有所不同。建议在进行NTP校时服务器搭建时,参考官方文档或相关资源,确保正确配置和操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [linux——搭建NTP服务器](https://blog.csdn.net/qq_43325582/article/details/130852018)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值