使用Linux服务器搭建

环境描述 :
操作系统: DC50sp4 x86-64
Asianux 3 x86-64
ntp server ip: 10.10.0.1
客户端ip: 10.10.0.3
广播域: 10.10.0.0
子网掩码: 255.255.255.0

操作步骤:
服务器端配置
1、vi /etc/ntp.conf
加上如下代码
restrict 10.10.0.0 mask 255.255.255.0 nomodify notrap
并注释掉其他外部NTP服务器。

2、将 ntpd 服务设成开机自启动
[root@localhost ~]#chkconfig ntpd on

3、开启 ntpd 服务
[root@localhost ~]#service ntpd start

———————————————————————————————————————————————-

客户端配置
1、vi /etc/ntp.conf
找到类似如下代码,并添加粗字体表示的代码:
# — CLIENT NETWORK ——-
# Permit systems on this network to synchronize with this
# time service. Do not permit those systems to modify the
# configuration of this service. Also, do not use those
# systems as peers for synchronization.
restrict 10.10.0.0 mask 255.255.255.0 nomodify notrap

# — OUR TIMESERVERS —–
#server 0.pool.ntp.org
#server 1.pool.ntp.org
#server 2.pool.ntp.org
server 10.10.0.1

DC50sp4 x86-64 和 Asianux 3 x86-64 系统的NTP服务器配置不同,但写入的代码是一样的。

2、关闭NTP服务
[root@localhost ~]#service ntp stop

3、手动与NTP时间服务器同步
[root@localhost ~]#ntpdate 10.10.0.1

NTP服务器搭建好后,需要5分钟左右的自身同步时间,所以,客户端需要稍等一段时间后,才能正常同步时间。

此时同步的时间,只是系统时间,而系统时间又是取自机器硬件时间,所以,机器硬件时间不准确的话,下次重启后,系统时间又会变化,所以,可以使用 hwclock -w 命令,将系统时间写入硬件时间中。

也可以用计划任务,对系统时间做定时更新:
# crontab -e

MAILTO=“”
*/1 * * * * /usr/sbin/ntpdate 10.10.0.1;/sbin/hwclock -w;

上述意思是,每分钟同步一次,并写入硬件中。具体要求,可以自己设置。