ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

服务器集群配置时钟同步

2022-02-07 21:34:05  阅读:169  来源: 互联网

标签:centos ntp sudo server 集群 org 服务器 ntpd 时钟


1)时间服务器配置(必须root用户)

查看所有节点ntpd服务状态和开机自启动状态

sudo systemctl status ntpd
sudo systemctl is-enabled ntpd

在所有节点关闭ntpd服务和自启动

sudo systemctl stop ntpd
sudo systemctl disable ntpd

修改localhost的ntp.conf配置文件(要将主机名为localhost作为时间服务器)

sudo vim /etc/ntp.conf
#修改内容如下

#修改1(授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#改为
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

#修改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(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10

修改localhost的/etc/sysconfig/ntpd 文件

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

重新启动ntpd服务,设置ntpd服务开机启动

sudo systemctl start ntpd
sudo systemctl enable ntpd

2)其他机器配置(必须root用户)

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

sudo crontab -e

编写定时任务如下:

*/10 * * * * /usr/sbin/ntpdate localhost

配置完成,测试一下:

修改任意机器时间 

sudo date -s "2017-9-11 11:11:11"

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

sudo date

标签:centos,ntp,sudo,server,集群,org,服务器,ntpd,时钟
来源: https://www.cnblogs.com/jake-jin/p/15869429.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有