linux ubuntu多台主机使用ntp同步时间
1台主机同步网络时间,叫做server,其他主机同步server的时间,叫做client
步骤:
1.下载ntpdate
2.统一时区 tzselect
3.使用date修改到一个大体相同的时间 date -s '2020-10-22 21:23:05’
4. 照着这篇文章修改server和client的/etc/ntp.conf
https://www.cnblogs.com/rancher-maomao/p/9309990.html
NTP server配置文件/etc/ntp.conf去除注释后的内容:
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 1.networktime.org iburst
server 2.networktime.org iburst
server ntp.synet.edu.cn iburst
server ntp.neu6.edu.cn iburst
server ntp.gwadar.cn iburst
server ntp.neu.edu.cn iburst
restrict -4 default kod notrap nomodify nopeer limited
restrict -6 default kod notrap nomodify nopeer limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery
NTP client 配置文件/etc/ntp.conf去除注释后的内容:
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 192.168.3.220 iburst
restrict -4 default kod notrap nomodify nopeer limited
restrict -6 default kod notrap nomodify nopeer limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery
5.**打开Linux自带的防火墙(iptables)的UDP入口和出口的123端口。**这样运行ntpdate同步时间时,才不会出现“no server suitable for synchronization found”错误。
NTP Client
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -j ACCEPT
NTP Server
iptables -A INPUT -p udp --dport 123 -j ACCEPT
iptables -A OUTPUT -p udp --sport 123 -j ACCEPT
6.NTP服务和ntpdate命令不可同时使用。
使用ntpdate之前,一定要先停止NTP服务。
NTP Client
sudo service ntp stop
7.同步 client同步server
ntpdate server的ip地址
资料
鸟哥讲NTP
http://cn.linux.vbird.org/linux_server/0440ntp.php#ps4