开发者社区> 问答> 正文

多台ecs不能ntp不能连接到一台ecs(作为ntp server)

设置了一台ecs为ntp server
其他三台ecs作为ntp client连接失败
ntp的版本如下
ntpdate -d xxx 也看不出信息
没有 notrust关键字


展开
收起
提子提子 2019-03-07 21:30:52 1375 0
1 条回答
写回答
取消 提交回答
  • 确认已经ntp程序包:# yum install ntp 配置时间源# vi /etc/ntp.conf server time.lib.tsinghua.edu.cn server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org 配置是否为其他PC提供时间服务# vi /etc/ntp.conf restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 配置开机时自动运行时间服务# chkconfig ntpd on 启动或停止时间服务# service ntpd start # service ntpd stop # service ntpd restart 验证ntp服务已经运行# pgrep ntpd 初始同步# ntpdate -u time.lib.tsinghua.edu.cn 确认同步成功# ntpq -p 如果要提供时间服务,还必须相应的设置iptable防火墙的配置。CentOS的时间服务使用udp 123端口。
    现在让我们来开始在 CentOS 上设置 NTP 服务器。 首先,我们需要保证正确设置了服务器的时区。在 CentOS 7 中,我们可以使用 timedatectl 命令查看和更改服务器的时区(比如,"Australia/Adelaide",LCTT 译注:中国可设置为 Asia/Shanghai ) # timedatectl list-timezones | grep Australia # timedatectl set-timezone Australia/Adelaide # timedatectl  继续并使用 yum 安装需要的软件 # yum install ntp  然后我们会添加全球 NTP 服务器用于同步时间。 # vim /etc/ntp.conf server 0.oceania.pool.ntp.org server 1.oceania.pool.ntp.org server 2.oceania.pool.ntp.org server 3.oceania.pool.ntp.org  默认情况下,NTP 服务器的日志保存在 /var/log/messages。如果你希望使用自定义的日志文件,那也可以指定。 logfile /var/log/ntpd.log  如果你选择自定义日志文件,确保更改了它的属主和 SELinux 环境。 # chown ntp:ntp /var/log/ntpd.log # chcon -t ntpd_log_t /var/log/ntpd.log  现在初始化 NTP 服务并确保把它添加到了开机启动。 # systemctl restart ntp # systemctl enable ntp
    一、搭建时间服务器 1、在一台linux服务器安装ntp server tar zxvf ntp-4.2.6.tar.gz cd ntp-4.2.6 ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks make && make install 2、修改ntp.conf配置文件 vi /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 default nomodify (允许任何IP的客户机都可以进行时间同步,如果是只允许某个网段的客户机进行时间同步可以这样写 restrict 10.58.26.0 mask 255.255.255.0 nomodify) 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 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 #server 0.rhel.pool.ntp.org(默认时间服务器) #server 1.rhel.pool.ntp.org(默认时间服务器) #server 2.rhel.pool.ntp.org(默认时间服务器) server 10.128.14.25 (手工设置的时间服务器) (如果是可以直连外网,可以使用LINUX默认提供的三组标准时间服务器,否则可以自己指定一个同步时间源)  #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 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10  3、以守护进程启动ntpd  #/etc/rc.d/init.d/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid  #/etc/rc.d/init.d/ntpd start  #ps -ef|grep ntpd 4、在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令进行同步时会产生no server suitable for synchronization found的错误。 下面命令可以知道何时ntp server完成了和自身同步的过程 在ntp server上使用命令: # watch ntpq -p 注意LOCAL的这个就是与自身同步的ntp server。 注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒*5=320秒的时间。  二、配置时间同步客户机 vi /var/spool/cron/root(或crontab -e) 增加一行,在每天的1点10分、9点10分、17点10分与时间同步服务器进行同步并写入BIOS  10 1 ,9,17* * * root /usr/sbin/ntpdate 10.128.14.25; /sbin/hwclock -w 如果同步不正常,可以加输出日志或看系统日志 输出日志的方法: 10 1 ,9,17* * * root /usr/sbin/ntpdate 10.128.14.25>>/tmp/1.txt; /sbin/hwclock -w 在1.txt中可查看时间同步时的输出结果。 或者看/var/mail/root系统日志 Subject: Cron <root@tyzssq8> /usr/sbin/ntpdate 10.128.14.25;/sbin/hwclock -w X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <HOME=/root> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=root> X-Cron-Env: <USER=root> Message-Id: <20121127103001.076FF2090E@tyzssq8.site> Date: Tue, 27 Nov 2012 18:30:01 +0800 (CST) 27 Nov 18:29:59 ntpdate[6917]: step time server 10.128.14.25 offset -1.361968 sec 可以看到同步成功了,如果未成功会报出错误。  三、无法同步的问题 检查ntp server主机的防火墙。可能是ntp server的防火墙屏蔽了upd 123端口。 可以用命令 #service iptables stop
    

    image.png

    “答案来源于网络,供您参考”

    2019-09-24 18:18:50
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS计算与存储分离架构实践 立即下载