服务器端
1.使用yum安装ntp ntpdate;
yum install ntp ntpdate -y
2.查看服务是否安装成功,有相应服务即代表成功;
rpm -qa | grep ntp
3.修改配置文件,使该NTP服务器同步阿里NTP服务器;
vim /etc/ntp.conf
server ntp1.aliyun.com
server ntp2.aliyun.com
4.启动ntp服务,查看状态
systemctl start ntpd
5.查看是否同步
ntpq -p
6.设置开机自启
systemctl enable ntpd
7.设置防火墙,打开udp123端口
firewall-cmd --permanent --add-port=123/udp
firewall-cmd --reload
8.查看端口是否被打开
iptables -L -n
客户端
1.安装ntp服务同服务器端,查看服务是否安装成功
2.修改配置文件,将刚刚搭建好的NTP服务器作为客户端上游时间服务器
ps:配置上游时间服务器为本地的ntpd Server服务器
server 172.16.40.130
ps:配置允许上游时间服务器主动修改本机的时间
restrict 172.16.40.130 nomodify notrap noquery
4.与本地ntpd Server同步一下
ntpdate -u 172.16.40.130
5.启动ntp服务
service ntpd start
6.设置ntp服务开机自启
systemctl enable ntpd
7.查看状态
ntpq -p