35.搭建与使用时间服务器
时间服务器(NAT服务器)的作用是控制两台服务器的系统时间完全一致。
需要两台服务器,一台ip为192,168,252,130作为NAT服务器,一台192.168.252.128作为客户服务器
1.在NAT上安装ntp服务端。

2.修改ntp的配置文件(NAT服务器)
vim /etc/ntp.conf
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap //访问控制设置允许访问此ntp服务器的客户,restrict是关键字,后面是允许的网段以及特殊选项,nomodify表示客户端不能修改ntp服务端的时间参数
server 127.127.1.0 perfer //设置此服务器与上层ntp服务器做时间同步,127.127.1.0为物理时钟,perfer表示优先设置。
server 210.72.145.44 //server是关键字,后面是互联网的时间服务器

启动ntpd服务。ntpd服务采用udp协议开放端口123。

3.客户服务器上设置
chkconfig ntpd off //关闭本机ntp服务的启动与自启动
service ntpd stop
yum -y install ntpdate //安装ntpdate工具
rpm -qa ntpdate
ntpdate 192.168.252.130 //同步时间,设置客户服务器时间与NAT服务器一致


4.验证是否成功
猜想:在NAT上修改时间,客户服务器时间是否会改变?


结果:再次同步NAT服务器时间,时间一致
ntpdate 192.168.252.130
date //查看到客户服务器时间已改变。

5.设定定时任务,每隔10分钟自动同步时间
crontab -e //打开定时任务编写文件
×/10 * * * * * /sbin/ntpdate 192.168.252.130 //写入定时任务内容,保存
crontab -l //查看已经设定的定时任务


ps:根据实验楼实验编写Linux服务器的网络时间服务器