2004 发表于 2018-10-21 13:24:55

linux ntp server

  UTC:协调世界时(英:Coordinated Universal Time ,法:Temps Universel Coordonné),又称世界统一时间,世界标准时间,国际协调时间。英文(CUT)和法文(TUC)的缩写不同,作为妥协,简称UTC。协调世界时是以原子时秒长为基础,在时刻上尽量接近于世界时的一种时间计量系统。
  NTP :network time protocol
  软件时钟,1970/1/1 0:0:0 计算的总秒数
  硬件时钟,bios时间
  server主机的port: UDP123 端口
  选择多部time server 来做NTPserver,避免单台坏了,时间无法同步
  NTP 的阶层概念, 当前主机向上层获取时间,向下提供时间
  ntp
  tzdata :time zone data 提供各个市区对应的显示格式
  配置文件:
  /etc/ntp.conf   主要的唯一的配置文件
  /usr/share/zoneinfo/*    由tzdata提供,为各时区的时间格式对应挡
  /etc/sysconfig/clock设定时区,与是否使用UTC时间钟的配置文件
  /etc/localtime本地端的时间配置文件,会把clock中指定的时区 /usr/share/zoneinfo/
  中的时间配置文件拷贝到/etc/localtime中
  常用指令:
  /bin/date用于linux软件时间的修改与显示
  /sbin/hwclock   用于bios时间的修改与显示,一般是用date修改系统时间后,再用hwclock同步到bios中
  /usr/sbin/ntpdate   客户端时间校正工具
  /usr/sbin/ntpd   提供NTP服务
  实例:移居美国,如何修改时间
  1 date显示当前时间,注意看时区
  2 vim /etc/sysconfig/clock
  zone="/America/New_York"修改时区到纽约
  3 cp /usr/share/zoneinfo/America/New_York/etc/localtime复制纽约的时间格式对应当 到本地时间配置文件中
  4 date查看时区
  /etc/ntp.conf
  restrict [你的IP]mask
  parameter:
  ignore拒绝所有
  nomodify客户端可以连接校正时间,但是不能用ntpc,ntpq修改时间服务器的参数
  noquery 不提供网络校时
  notrap不提供trap这个远程事件登陆的功能
  notrust拒绝没有认证的客户端
  特别注意: 如果没有加参数,表示没有设置任何限制
  server
  设置上层ntp服务器,prefer 表示优先使用
  driftfile [可以被ntpd写入的目录与档案]
  该文件 需要 使用完整的路径文件名
  不能是链接当
  ntpd 这个daemon要有写入权限
  该文件所记录的数值单位为:百万分之一秒
  keys
  客户端还可以通过密钥来认证
  /etc/init.d/ntpd start
  chkconfigntpd on
  tail /var/log/messages
  netstat -tulnp | grepntp
  ntpstat
  linux 手动校时的工作,date ,hwclock
  date
  date [+format]
  date [-u] MMDDhhmmYY.ss
  hwclock[-rws]
  网络校时
  ntpdate[-dv]
  ntpdateip地址
  记得不要在ntpserver 上运行 ntpdate 命令
  ntpdate脚本如下:
  #!/bin/bash
  #
  # chkconfig: - 57 75
  # description: set the date and time via NTP
  ### BEGIN INIT INFO
  # Provides: ntpdate
  # Required-Start: $network $local_fs $remote_fs
  # Should-Start: $syslog $named
  # Short-Description: set the date and time via NTP
  # Description: ntpdate sets the local clock by polling NTP servers
  ### END INIT INFO
  # Source function library.
  . /etc/init.d/functions
  # Source networking configuration.
  . /etc/sysconfig/network
  prog=ntpdate
  lockfile=/var/lock/subsys/$prog
  ntpconf=/etc/ntp.conf
  ntpstep=/etc/ntp/step-tickers
  start() {
  [ "$EUID" != "0" ] && exit 4
  [ "$NETWORKING" = "no" ] && exit 1
  [ -x /usr/sbin/ntpdate ] || exit 5
  [ -f /etc/sysconfig/ntpdate ] || exit 6
  . /etc/sysconfig/ntpdate
  [ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers=
  if ! echo "$tickers" | grep -qi '' && [ -f $ntpconf ]; then
  # step-tickers doesn't specify a server,
  # use servers from ntp.conf instead
  tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \
  egrep -v '127\.127\.+\.+')
  fi
  if ! echo "$tickers" | grep -qi ''; then
  echo $"NTP server not specified in $ntpstep or $ntpconf"
  exit 6
  fi
  echo -n $"$prog: Synchronizing with time server: "
  [ -z "$RETRIES" ] && RETRIES=2
  retry=0
  while true; do
  /usr/sbin/ntpdate $OPTIONS $tickers &> /dev/null
  RETVAL=$?
  [ $RETVAL -eq 0 ] || [ $retry -ge "$RETRIES" ] && break
  sleep $[10 * (1
页: [1]
查看完整版本: linux ntp server