玛卡巴卡的卡巴卡玛 发表于 2022-8-11 02:01:05

linux 局域网时钟同步

Linux时钟同步

一        需求

​        以172.20.1.152作为时钟服务器,其他服务器根据这台服务器进行时钟同步。
二        时钟服务器172.20.1.152实施

2.1        安装ntp

#检查是否已经安装,出现了红框中的就说明已经安装了
rpm -qa | grep ntp
#安装ntp
yum install ntphttps://img2022.cnblogs.com/blog/2867690/202206/2867690-20220625112543697-217980731.png
2.2        配置时钟服务器

vi /etc/ntp.conf
#代表允许172.20网段的服务器与此服务器进行时间同步,根据需要进行替换id和子网掩码即可# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
restrict 172.20.1.0 mask 255.255.255.192 nomodify notrap
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 102.3        开启服务

service ntpd start2.4        设置ntp开机自启动

chkconfig ntpd on2.5        开发访问端口权限

#之后还需要对ntp的默认端口123进行放行,这个一定要配,除非你关了防火墙,否则会报错,no server suitable for #synchronization found
iptables -I INPUT -p tcp --dport 123 -j ACCEPT
iptables -I INPUT -p udp --dport 123 -j ACCEPT2.6        本服务器时间可以根据互联网时钟或者数据库手动调整

https://img2022.cnblogs.com/blog/2867690/202206/2867690-20220625113005044-888269386.png
三        时钟客户端172.20.1.158实施

3.1        安装ntp

#检查是否已经安装,出现了红框中的就说明已经安装了
rpm -qa | grep ntp
#安装ntp
yum install ntp3.2        配置

vi /etc/ntp.conf记得把地址替换为你自己的那台时间服务器的地址
server 172.20.1.152
fudge 172.20.1.152 stratum 103.3        启动

service ntpd start3.4        开机启动

chkconfig ntpd on3.5        手动同步下测试

ntpdate -d 172.20.1.152
#显示以下内容代表成功# ntpdate -d 172.20.1.152
25 Jun 09:58:57 ntpdate: ntpdate 4.2.6p5@1.2349-o Fri Apr 13 12:52:28 UTC 2018 (1)
Looking for host 172.20.1.152 and service ntp
host found : 172.20.1.152
transmit(172.20.1.152)
receive(172.20.1.152)
transmit(172.20.1.152)
receive(172.20.1.152)
transmit(172.20.1.152)
receive(172.20.1.152)
transmit(172.20.1.152)
receive(172.20.1.152)
server 172.20.1.152, port 123
stratum 11, precision -24, leap 00, trust 000
refid , delay 0.02586, dispersion 0.00000
transmitted 4, in filter 4
reference time:    e660efe3.56e033ceSat, Jun 25 2022 10:22:27.339
originate timestamp: e660f01a.2e8a535dSat, Jun 25 2022 10:23:22.181
transmit timestamp:e660ea67.47801f45Sat, Jun 25 20229:59:03.279
filter delay:0.026210.025910.025860.02589
         0.000000.000000.000000.00000
filter offset: 1458.902 1458.902 1458.902 1458.902
         0.000000 0.000000 0.000000 0.000000
delay 0.02586, dispersion 0.00000
offset 1458.902283

25 Jun 09:59:03 ntpdate: step time server 172.20.1.152 offset 1458.902283 sec3.6        查看同步状态

ntpq -p
#when代表最近同步时间https://img2022.cnblogs.com/blog/2867690/202206/2867690-20220625112609763-413636834.png
3.7        创建定时任务,自动同步

#查看已有定时任务
crontab -l
#添加定时任务
crontab -e
#每天凌晨一点20,自动从172.20.1.152同步一次
20 1 * * * ntpdate 172.20.1.152
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: linux 局域网时钟同步