时间同步服务
一、 ntpd服务
[root@dns-server ~]# vim /etc/ntp.conf
restrict 192.168.221.0 mask 255.255.255.0 nomodify notrap
//允许192.168.221.0/24网段的主机同步时间
[root@dns-server ~]# service ntpd start
Starting ntpd: [ OK ]
[root@dns-server ~]# netstat -ntplu |grep ntpd
udp 0 0 192.168.221.129:123 0.0.0.0:* 1741/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1741/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 1741/ntpd
udp 0 0 fe80::20c:29ff:feb0:149d:123 :::* 1741/ntpd
udp 0 0 ::1:123 :::* 1741/ntpd
udp 0 0 :::123 :::* 1741/ntpd
客户端同步:
[root@dns-client ~]# ntpdate 192.168.221.129
24 Jun 18:43:13 ntpdate[1645]: adjust time server 192.168.221.129 offset 0.004234 sec
//这种方法依赖于外网
二、托管于xinetd的时间同步
[root@dns-server ~]# vim /etc/xinetd.d/time-dgram
3 service time
4 {
5 # This is for quick on or off of the service
6 disable = no
7
[root@dns-server ~]# vim /etc/xinetd.d/time-stream
3 service time
4 {
5 # This is for quick on or off of the service
6 disable = no
[root@dns-server ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@dns-server ~]# netstat -ntplu |grep 37
tcp 0 0 :::37 :::* LISTEN 1837/xinetd
//客户端同步时间
[root@server ~]# date
Sun Jun 24 00:10:52 CST 2018
[root@server ~]# rdate -s 192.168.221.129
[root@server ~]# date
Sun Jun 24 19:05:30 CST 2018
//同步成功
注:
①ntpd服务同步时间,要在配置文件中允许其他机器同步才行,客户端用ntpdate IP同步。
②xinetd的时间同步服务,需修改其子配置文件将time-dgram 和time-stream
中的disabled选项改为no。