linux通过ntp实现多台服务器时间同步

ntp服务端192.168.10.81实施
1、yum list | grep ntp

2、yum -y install ntp.x86_64

3、修改配置文件:
vi /etc/ntp.conf

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.149.0 mask 255.255.255.0 nomodify notrap  #加入这一行,表示允许这个网段的ip来同步时间
 
# 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 127.127.1.0   #先禁用4个自带的服务,添加server 127.127.1.0
Fudge 127.127.1.0 stratum 10    #设置stratum级别

4、如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,
在/etc/sysconfig/ntpd文件中,添加【SYNC_HWCLOCK=yes】这样,就可以让硬件时间与系统时间一起同

5 启动时间服务器,命令如下:

service ntpd status

service ntpd start

service ntpd restart

6 查看启动结果,如下所示:

命令:ntpq -p

7 设置自启动,命令如下:

chkconfig ntpd on

8、设置系统时间
date -s "20200907 19:10:00"

9、将当前时间和日期写入BIOS,避免重启后失效
hwclock -w

10、查看时间和时区
timedatectl

11、查看端口,确保123端口开放访问:
netstat -ln|grep 123
firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload

ntp客户端192.168.10.82实施
1、yum list | grep ntp

2、yum -y install ntp.x86_64

3、修改配置文件:

vi /etc/ntp.conf

# 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
server 192.168.10.81   #先禁用4个自带的服务,添加主节点为服务端
Fudge 192.168.10.81 stratum 10    #设置stratum级别
    
    4、如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,
在/etc/sysconfig/ntpd文件中,添加【SYNC_HWCLOCK=yes】这样,就可以让硬件时间与系统时间一起同

5 启动时间服务器,命令如下:

service ntpd status

service ntpd start

service ntpd restart

6 查看启动结果,如下所示:

命令:ntpq -p

7 设置自启动,命令如下:

chkconfig ntpd on

8 立即同步
ntpdate -d 192.168.10.81

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值