Solaris时间同步的简单设置

服务器设置

查看是否安装了NTP软件包(默认是安装的),有下面两行则是已安装

# pkginfo | grep ntp

system SUNWntpr NTP, (Root)

system SUNWntpu NTP , (Usr)


1、拷贝ntp服务器配置样本作为ntp配置文件
# cp -p /etc/inet/ntp.server /etc/inet/ntp.conf

2、编辑ntp.conf,进行服务器配置
# vi /etc/inet/ntp.conf
将原文件中
server 127.127.XType.0 prefer
fudge 127.127.XType.0 stratum 0

两行的XType改成1,1表示local,即
server 127.127.1.0 prefer
fudge 127.127.1.0 stratum 0

并注释掉文件末尾的四行内容,否则会提示找不到/etc/inet/ntp.keys文件
#keys /etc/inet/ntp.keys
#trustedkey 0
#requestkey 0
#controlkey 0

3、启动ntp服务
Solaris 8 & 9
# /etc/rc2.d/S74xntpd stop
# /etc/rc2.d/S74xntpd start

Solaris 10
# svcadm disable svc:/network/ntp:default
# svcadm enable svc:/network/ntp:default

查看状态
# svcs svc:/network/ntp:default
如果显示为online则正常
如果显示为maintenance,需要执行一下
# svcadm clear svc:/network/ntp:default
再查看是否恢复正常

4、稍等一段时间后查看服务器状态
# ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
*LOCAL(0)        .LCL.            0 l   51   64  377     0.00    0.000   10.06

如果看到LOCAL前面有*了,则服务器工作正常。


客户端设置
1、
创建ntp客户端配置文件
# touch /etc/inet/ntp.conf
# chown root:sys /etc/inet/ntp.conf

2、编辑ntp.conf,设置同步时间的服务器
# vi /etc/inet/ntp.conf
内容如下:
server server1-ip-address prefer
server server2-ip-address
server server3-ip-address

将其中的server-ip-address换成服务器的IP地址。如果只有一台服务器,填写第一行就可以,如果有多台服务器提供冗余,可一并写上,并在首选服务器后添加prefer标志。

3、启动ntp服务(与服务器设置的第三步相同)
Solaris 9
# /etc/rc2.d/S74xntpd stop
# /etc/rc2.d/S74xntpd start

Solaris 10
# svcadm disable svc:/network/ntp:default
# svcadm enable svc:/network/ntp:default

查看状态
# svcs svc:/network/ntp:default
如果显示为online则正常
如果显示为maintenance,需要执行一下
# svcadm clear svc:/network/ntp:default
再查看是否恢复正常

4、稍等一段时间后查看同步情况
# ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
*pcp379652pcs.cn .LCL.            1 u   62   64  377     0.93  -26.011    0.87

看到前面出现*,并且reach值不断变大,disp值不断变小,则工作正常。

5、抓包查看能否进行数据同步
snoop -x udp port 123

serv.lrq.com -> 207.46.197.32 NTP   client [st=0] (2009-07-14 16:17:25.38047 )
 
           0: 000f 1f9d 735b 000c 2993 537e 0800 4500    ....s[..).S~..E.
          16: 004c fac9 4000 ff11 0000 c0a8 003b cf2e    .L..@........;..
          32: c520 007b 007b 0038 557c db00 04fa 0001    . .{.{.8U|......
          48: 0000 0001 0000 0000 0000 0000 0000 0000    ................
          64: 0000 0000 0000 0000 0000 0000 0000 0000    ................
          80: 0000 ce06 bd95 6166 6000                   ......af`.
 
207.46.197.32 -> serv.lrq.com    NTP  server [st=3] (2009-07-15 16:24:29.78357 )
 
           0: 000c 2993 537e 000f 1f9d 735b 0800 4500    ..).S~....s[..E.
          16: 004c 5ffa 0000 6d11 9874 cf2e c520 c0a8    .L_...m..t... ..
          32: 003b 007b 007b 0038 64ee 1c03 04fa 0000    .;.{.{.8d.......
          48: 14a1 0000 1370 4812 cd9d ce08 0e4e 24c0    .....pH......N$.
          64: bc1d ce06 bd95 6166 6000 ce08 10bd c897    ......af`.......
          80: c65a ce08 10bd c897 c65a                   .Z.......Z
 
serv.lrq.com -> 207.46.197.32 NTP  client [st=0] (2009-07-15 16:25:05.67451 )
 
           0: 000f 1f9d 735b 000c 2993 537e 0800 4500    ....s[..).S~..E.
          16: 004c facb 4000 ff11 0000 c0a8 003b cf2e    .L..@........;..
          32: c520 007b 007b 0038 557c db00 06ef 0000    . .{.{.8U|......
          48: 0000 0001 001a 0000 0000 0000 0000 0000    ................
          64: 0000 0000 0000 0000 0000 0000 0000 0000    ................
          80: 0000 ce08 10e1 acac 2000                   ........ .

到第三个包的时候服务器已经完成时间同步了.

 

 

 

 

[3]Check NTP Service Running :

root@testserver01 # ps -ef|grep ntp

root 5192 1 0 17:14:29 ? 0:00 /usr/lib/inet/xntpd

root 5408 4717 0 17:52:45 pts/2 0:00 grep ntp

[4]Check Client and Server時間差:

root@testserver01 # ntpdate -q 10.87.0.9

server 10.87.0.9, stratum 11, offset -0.000428, delay 0.02727

6 Jun 17:59:47 ntpdate[10012]: adjust time server 10.87.0.9 offset -0.000428 sec

[5]Stop Auto-Sync,Start Manual-Sync:

root@testserver01 # ntpdate 10.87.0.9

6 Jun 18:13:34 ntpdate[10018]: the NTP socket is in use, exiting

root@testserver01 # ps -ef|grep ntp

root 10019 9907 0 18:13:52 pts/1 0:00 grep ntp

root 9988 1 0 17:22:16 ? 0:00 /usr/lib/inet/xntpd

root@testserver01 # kill -9 9988

root@testserver01 # ps -ef|grep ntp

root 10023 9907 0 18:15:41 pts/1 0:00 grep ntp

root@testserver01 # ntpdate 10.87.0.9

6 Jun 18:15:48 ntpdate[10025]: adjust time server 10.87.0.9 offset -0.000834 sec

root@testserver01 # ps -ef|grep ntp

root 10026 9907 0 18:16:02 pts/1 0:00 grep ntp

root@testserver01 # ntpdate 10.87.0.9

6 Jun 18:16:07 ntpdate[10028]: adjust time server 10.87.0.9 offset 0.000447 sec

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值