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