首页 > 系统相关 >Linux配置时间同步

Linux配置时间同步

时间:2022-12-22 14:48:03浏览次数:41  
标签:同步 ntp 配置 server systemctl pool Linux org ntpd

一、Master节点

1、关闭ntp服务和自启动(必须root用户)

yum install -y ntp
sudo systemctl stop ntpd
sudo systemctl disable ntpd

2、修改ntp配置文件

vi /etc/ntp.conf

  修改内容如下:

  (1)修改1(授权192.168.67.0-192.168.67.255网段上的所有机器可以从这台机器上查询和同步时间)

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

  改为:

restrict 192.168.67.0 mask 255.255.255.0 nomodify notrap

  (2)修改2(集群在局域网中,不使用其他互联网上的时间)

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.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

  (3)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)

server 127.127.1.0
fudge 127.127.1.0 stratum 10

4、修改/etc/sysconfig/ntpd 文件

vi /etc/sysconfig/ntpd
#增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes

5、重新启动ntpd服务

systemctl start ntpd

6、设置ntpd服务开机启动

systemctl enable ntpd

7、查看ntpd状态

systemctl status ntpd

二、其他节点,其他机器配置(必须root用户)

1、在其他机器配置10分钟与时间服务器同步一次

crontab -e
#编写定时任务如下:
*/10 * * * * /usr/sbin/ntpdate 192.168.67.1

2、修改任意机器时间

date -s "2020-5-14 12:12:12"

3、十分钟后查看机器是否与时间服务器同步

date

三、Bug说明

1、若时间服务器错误,则:

  (1)关闭ntpd服务:

systemctl stop ntpd

  (2)查询网络时间:

ntpdate cn.pool.ntp.org

  (3)启动ntpd服务:

systemctl start ntpd

2、若其他机器同步时间时发生错误,则:

  (1)关闭ntpd服务:

systemctl stop ntpd

  (2)关闭ntpd服务自启动:

systemctl disable ntpd

  (3)与时间服务器时间同步:

ntpdate 192.168.67.1

 

标签:同步,ntp,配置,server,systemctl,pool,Linux,org,ntpd
From: https://www.cnblogs.com/qq1035807396/p/16998647.html

相关文章

  • 【配置化】C# dapper是怎么实现的?精短ORM
    目录一、什么是dapper二、实现问题与思路&源码参考三、小结 一、什么是dapperdapper是个组件,一个dll文件,可以通过NuGet下载。作用:快速访问数据库并自动完成数据......
  • Linux 利用wkhtmltopdf动态生成pdf
    yumlocalinstallwkhtmltox-0.12.6-1.centos8.x86_64.rpmwkhtmltopdf--version;yuminstalllibpng15*yumlistlibpng15*wkhtmltopdf--disable-smart-shrinki......
  • Linux挂载磁盘
    1、查看磁盘信息fdisk-l2、格式化磁盘mkfs.xfs/dev/sda3、创建挂载目录mkdir-p/data/1/4、挂载并将挂载信息写入/etc/fstab,开启自动挂载mount/dev/sda......
  • Linux配置免密
    1、进入ssh目录cd~/.ssh2、若不存在则创建该目录mkdir-p~/.ssh3、查看是否有公钥cd~/.sshll|grepid_rsa.pub4、若没有,则公钥和私钥(然后敲(三个回车),就会......
  • 时钟系统,Linux系统中芯片时钟的基本原理
    第一:时钟系统分析   每款芯片都有自己的主频,有的时候需要把主频设置到合适的值,才能发挥它的最大性能。     可以看出,开发板的系统时钟来源于两个部分:32.7......
  • 问题 | Linux虚拟机无法联网
    前言:有一段时间没有开启过虚拟机的Linux系统,打开发现无法上网,IP也不显示为之前设置的静态IP,怀疑是安装win10虚拟机时修改了网络设置影响的,虚拟机系统:CentOs-71.检查ens33......
  • CentOS全局配置JAVA环境变量,实现多个tomcat共用环境变量,不用再一个个tomcat配置
     vim/etc/profile然后在最后加入下面的代码:export JAVA_HOME=/usr/local/java/jdkexport PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/ro......
  • centos 7配置网卡聚合
    一、需求1、多网卡聚合,可以起到网络链路冗余作用,当故障发生时,网络自动切换,保证业务数据不中断。 2、多网卡聚合成一条虚拟链路,可实现网络带宽提升,突破网卡的带宽瓶颈,提......
  • spring boot 配置Bean
    packagecom.example.demo.config;importcom.example.demo.entiy.User;importorg.springframework.context.annotation.Bean;importorg.springframework.context.an......
  • nginx 配置服务端地址
    server{listen8099;server_namelianghj.top;#charsetkoi8-r;#access_loglogs/host.access.logmain;......