ITPub博客

首页 > Linux操作系统 > Linux操作系统 > RHEL5.2中用ntp实现时间自动同步(和AS4不一样)

RHEL5.2中用ntp实现时间自动同步(和AS4不一样)

原创 Linux操作系统 作者:football2006 时间:2008-07-06 07:43:39 0 删除 编辑

配置时钟同步

a.安装软件包:(一般已经安装了这个包)

Yum install ntp

Ntp的配置文件是/etc/ntp.conf,工作目录是/etc/ntp/,接着编辑/etc/ntp.conf文件。

b.服务端配置:

IP:172.15.3.126

编辑/etc/ntp.conf文件:

[root@rhel5 ~]#vi /etc/ntp.conf 增加下面的内容

restrict 172.15.3.0 mask 255.255.255.0 nomodify notrap(允许内网通讯)

restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap noquery notrust(禁止其他ip来更新时间)

Logfile /var/log/ntp.log(定义日志信息)

restrict 0. pool.ntp.org mask 255.255.255.255 nomodify notrap noquery

restrict 1. pool.ntp.org mask 255.255.255.255 nomodify notrap noquery

restrict 1. pool.ntp.org mask 255.255.255.255 nomodify notrap noquery

注:(/etc/sysconfig/clock是用来设置时区的文件,例如:

[root@rhel5 ntp]# cat /etc/sysconfig/clock

# The ZONE parameter is only evaluated by system-config-date.

# The timezone of the system is defined by the contents of /etc/localtime.

ZONE="Asia/Chongqing"

UTC=true

ARC=false

/usr/share/zoneinfo这个目录里规定了各主要时区的时间设定文件,例如重庆:/usr/share/zoneinfo/Asia/Chongqing)

如果想把同步好的时间写入BIOS里,就要设置/etc/sysconfig/ntpd文件,将其中的SYNC_HWCLOCK=no更改为SYNC_HWCLOCK=yes。

启动ntp服务:

[root@rhel5 ntp]# service ntpd restart

Shutting down ntpd: [ OK ]

ntpd: Synchronizing with time server: [ OK ]

Starting ntpd: [ OK ]

[root@rhel5 ntp]#chkconfig ntpd on

c.客户端的设置:

可以通过使用system-config-time来设置,将其中的时间服务器更改为172.15.3.126即可,或者使用ntpdate -u 172.15.3.126来和时间服务器同步。切记更改完以后要重新启动NTP服务,使其生效。或者使用crontab -e来编辑:

*/5 * * * * /usr/sbin/ntpdate -u 172.15.3.126 表示每五分钟同步一次。重启crond服务即可。

[root@node2 ~]# service ntpd restart

可以使用ntpq –p查看同步状态

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8119050/viewspace-1006835/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    39
  • 访问量
    94129