• 步骤精简:
    • 1.确认系统是否已安装NTP服务
      • rpm -qa | grep ntp
    • 2.vim /etc/ntp.conf 分别配置NTP服务端和客户端配置信息,具体配置见如下文。
    • 3.systemctl status ntpd.service 验证所有服务器的ntp服务启动状态,只有NTP服务端才需要启动NTP服务,其余NTP客户端均需要关闭这个NTP服务(systemctl stop ntpd.service)
    • 4.systemctl enable ntpdate.service 设置ntpdate 时间同步服务开机自启动
    • 5.date 查看下本机当前系统时间
    • 6.ntpdate xxx 同步一下NTP服务端服务器的系统时间
    • 7.date 再次查看本机当前系统时间,看一下同步是否成功
  • 1.环境准备(347条消息) Linux服务器ntp时间同步离线安装配置_software_student的博客-CSDN博客
  • 确定一台ntp服务端,剩下的服务器均为NTP客户端。
  • 在NTP服务端服务器上安装NTP服务和NTPdate服务
  • 将所有NTP客户端服务器的/etc/ntp.conf配置文件中的上游时间配置为NTP服务端服务器的ip地址,通过修改NTP服务端 的系统时间,以其为基准,来控制整个集群的服务器系统时间
  • 2.下载安装包
  • 确认操作系统版本,可执行以下命令确认自己系统的版本信息(我的Linux系统为CentOS7.4 x86_64版本)
  • cat /etc/redhat-releaseuname -acat /proc/version
  • uname -a
  • cat /proc/version
  • 确认系统是否已安装NTP服务
  • rpm -qa | grep ntp
  • 如果系统自带或已安装版本不符合个人需求,可进行卸载,命令如下:
    • rpm -e –nodeps ntpdate-4.2.6p5-29.el7.centos.2.x86_64
    • rpm -e –nodeps ntp-4.2.6p5-29.el7.centos.2.x86_64
  • 3.安装NTP服务
  • 下载完成所需安装包,接下来就进行NTP服务的安装
  • 安装ntpdate
  • rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
  • 4.配置NTP
  • NTP服务器端配置
  • 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 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 ::1
  • # Hosts on local network are less restricted.
  • #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  • # 允许172.16.54.0网段内所有机器从esnode1同步时间
  • restrict 172.16.54.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 iburst
  • #server 1.centos.pool.ntp.org iburst
  • #server 2.centos.pool.ntp.org iburst
  • #server 3.centos.pool.ntp.org iburst
  • # 中国国家授时中心服务器地址
  • server 0.cn.pool.ntp.org
  • server 1.cn.pool.ntp.org
  • server 2.cn.pool.ntp.org
  • server 3.cn.pool.ntp.org
  • # 允许上层时间服务器主动修改本机时间
  • restrict 0.cn.pool.ntp.org nomodify notrap noquery
  • restrict 1.cn.pool.ntp.org nomodify notrap noquery
  • restrict 2.cn.pool.ntp.org nomodify notrap noquery
  • restrict 3.cn.pool.ntp.org nomodify notrap noquery
  • # 外部时间服务器不可用时,以本地时间作为时间服务
  • server 127.127.1.0
  • fudge 127.127.1.0 stratum 10
    • #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
  • # Enable public key cryptography.
  • #crypto
  • includefile /etc/ntp/crypto/pw
  • # 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
  • # Enable writing of statistics records.
  • #statistics clockstats cryptostats loopstats peerstats
  • # Disable the monitoring facility to prevent amplification attacks using ntpdc
  • # monlist command when default restrict does not include the noquery flag. See
  • # CVE-2013-5211 for more details.
  • # Note: Monitoring will not be disabled with the limited restriction flag.
  • SYNC_HWCLOCK=yes
  • disable monitor
  • NTP客户端配置
  • # 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 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 ::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 iburst
  • #server 1.centos.pool.ntp.org iburst
  • #server 2.centos.pool.ntp.org iburst
  • #server 3.centos.pool.ntp.org iburst
  • # 从esnode1中同步时间
  • server 172.16.54.22
  • # 允许esnode1修改本地时间
  • restrict 172.16.54.22 nomodify notrap noquery
  • # 如果esnode1不可用,用本地的时间服务
  • server 127.127.1.0
  • fudge 127.127.1.0 stratum 10
    • #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
  • # Enable public key cryptography.
  • #crypto
  • includefile /etc/ntp/crypto/pw
  • # 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
  • # Enable writing of statistics records.
  • #statistics clockstats cryptostats loopstats peerstats
  • # Disable the monitoring facility to prevent amplification attacks using ntpdc
  • # monlist command when default restrict does not include the noquery flag. See
  • # CVE-2013-5211 for more details.
  • # Note: Monitoring will not be disabled with the limited restriction flag.
  • SYNC_HWCLOCK=yes
  • disable monitor
  • 5.验证时间同步
  • 启动ntp服务端的NTP服务
    • systemctl start ntpd.service
    • 查看启动运行状态
    • systemctl status ntpd.service
    • ntpstat
  • 在其他客户端服务器上尝试着同步NTP服务端服务器的系统时间
  • ntpdate xxx
  • 每个节点开启开机自启动
  • systemctl enable ntpdate.service
  • linux修改系统时间
  • 一、查看和修改Linux的时区1. 查看当前时区
  • 命令 : “date -R”
  • 1.修改设置Linux服务器时区方法 A
  • 命令 : “tzselect”
  • 依据引导进行选择
  • 二、查看和修改Linux的时间1. 查看时间和日期
  • 命令 : “date”
  • 如果时间不对,可以自己手动调整时间
  • 例如:将系统日期设定成2009年11月3日的命令
  • 命令 : “date -s 11/03/2009”
  • 将系统时间设定成下午5点55分55秒的命令
  • 命令 : “date -s 17:55:55”
  • 3. 将当前时间和日期写入BIOS,避免重启后失效
  • 命令 : “hwclock -w”
  • ————————————————
  • 版权声明:本文为CSDN博主「MrLixinglin」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
  • 原文链接:https://blog.csdn.net/lixld/article/details/88060836
  • 查看当前系统时间
    • date

作者 admin

张宴银,大数据开发工程师

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注