您的位置:首页 > 运维架构 > Linux

Linux(Unix)时钟同步ntpd服务配置方法

2014-10-24 17:42 651 查看
假定时钟服务器IP地址为:192.168.0.1

服务器端配置:

1:置/etc/ntp.conf文件内容为:

server 127.127.1.0 minpoll 4

fudge 127.127.1.0 stratum 1

restrict 127.0.0.1

restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

driftfile /var/lib/ntp/drift

2: /etc/ntp/ntpservers应置空

3: /etc/ntp/step-tickers应配置为 127.127.1.0

上诉修改完成后,以root用户身份重启ntpd服务:service ntpd restart即可

客户端配置:

1:置/etc/ntp.conf文件内容为:

server 192.168.0.1

fudge 127.127.1.0 stratum 2 //多个客户端stratum值配置 3,4,5,...

restrict 127.0.0.1

driftfile /var/lib/ntp/drift

restrict 192.168.0.1 mask 255.255.255.255

2. /etc/ntp/ntpservers 文件内容置空

3. /etc/ntp/step-tickers文件内容置为时钟服务器IP地址 192.168.0.1

上诉修改完成后,以root用户身份重启ntpd服务:service ntpd restart即可

用户可用以下两个常用命令查看ntpd服务状态:

1 ntpq -p

2 ntpstat

在其他主机上去同步时钟即可

ntpdate 192.168.0.1

更多的是在crond上自动运行

crontab -e

* 1 * * * /usr/sbin/ntpdate 192.168.0.1

每天凌晨1点同步时间

如果出现the NTP socket is in use, exiting错误,原因是xnptd已经绑定到了该Socket,运行ntpdate时,它会首先进行广播,然后侦听端口123,如果xntpd正在运行,而有一个进程已经在侦听该端口了,则会使ntpdate无法在上面运行。运行下列命令即可找出xnptd的pid

ps -ef|grep xntpd

如果没有找到,则使用

lsof -i:123

[root@hna-slavenode1 ~]# lsof -i:123

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

ntpd 56919 ntp 16u IPv4 3392998 0t0 UDP *:ntp

ntpd 56919 ntp 17u IPv6 3393000 0t0 UDP *:ntp

ntpd 56919 ntp 18u IPv4 3393006 0t0 UDP localhost:ntp

ntpd 56919 ntp 19u IPv4 3393007 0t0 UDP hna-slavenode1:ntp

ntpd 56919 ntp 20u IPv6 3393008 0t0 UDP localhost:ntp

ntpd 56919 ntp 21u IPv6 3393009 0t0 UDP [fe80::2e44:fdff:fe7e:7730]:ntp

kill -9 56919杀掉后,就可以正常运行了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: