linux 改时间脚本,CentOS时间同步方法和更新时间脚本

CentOS时间同步方法和更新时间脚本

Linux

#centos #时间同步 #脚本2012-04-24 09:28

在CentOS 5不再区分客户端和服务器,只要配置了NTP,它就会提供NTP服务。

1)确认已经ntp程序包:

# yum install ntp

2)配置时间源

# vi /etc/ntp.conf

server pool.ntp.org   #可选择其他优先服务器

server 0.pool.ntp.org

server 1.pool.ntp.org

server 2.pool.ntp.org

3)配置是否为其他PC提供时间服务

# vi /etc/ntp.conf

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

4)配置开机时自动运行时间服务

# chkconfig ntpd on

5)启动或停止时间服务

# service ntpd start

# service ntpd stop

# service ntpd restart

6)验证ntp服务已经运行

# pgrep ntpd

7)初始同步

# ntpdate -u time.lib.tsinghua.edu.cn

8)确认同步成功

# ntpq -p

9)同时建议修改一下 /etc/sysconfig/ntpd 文件

# vi /etc/sysconfig/ntpd

SYNC_HWCLOCK=yes

# 改成 yes 吧!这样主机 BIOS 的时间也会跟着一起改变的 !

当然,如果要提供时间服务,还必须相应的设置iptable防火墙的配置。CentOS的时间服务使用udp 123端口。

#! /bin/bash

PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin

export PATH

create()

{

cat >/usr/local/sbin/ntp.txt<

210.72.145.44

clock.via.net

time.windows.com

time-a.nist.gov

time-b.nist.gov

time-nw.nist.gov

time.stdtime.gov.tw

ntp.nasa.gov

EOF

}

if [ ! -f /usr/local/sbin/ntp.txt ];

create

fi

LOG=/var/log/jbmon/secure/service.txt

for svr in `cat /usr/local/sbin/ntp.txt`; do

/usr/sbin/ntpdate $svr >> $LOG

if [ $? = 0 ]; then exit; fi

done

相关文章

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值