一.安装方法:
1.RPM包安装:
mount /dev/cdrom/media/
rpm -ivh /media/centos/ntp/-4.XXXX.rpm
2. 源码编译安装:
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p4.tar.gz
tar -zxvf ntp-4.2xx.tar.gz -C /usr/local
cd ntp-4.2.xx
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-prase-clocks
make
make install
3.yum安装:
yum install ntp
二:配置
[[email protected] ~]# cat /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
192.168.1.0 mask 255.255.255.0 nomodify
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server cn.pool.ntp.org
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
[[email protected] ~]#
[[email protected] ~]# chkconfig ntpd on
[[email protected] ~]#
[[email protected] ~]# vi /etc/sysconfig/ntpd
[[email protected] ~]# service ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
[[email protected] ~]#
[[email protected] ~]# netstat -ntulp |grep
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help‘ for more information.
[[email protected] ~]# netstat -ntulp |grep 123
udp 0 0 192.168.1.200:123 0.0.0.0:* 25982/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 25982/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 25982/ntpd
udp 0 0 ::1:123 :::* 25982/ntpd
udp 0 0 :::123 :::* 25982/ntpd
[[email protected] ~]# date
Tue Aug 4 15:30:34 CST 2015
需要同步时间的服务器:
方法1、
[[email protected] nrpe2.13]# ntpdate 192.168.1.200
4 Aug 15:39:48 ntpdate[26443]: step time server 192.168.1.200 offset 333893.127016 sec
[[email protected] nrpe-2.13]# date
Tue Aug 4 15:39:54 CST 2015
[[email protected] nrpe-2.13]#
并且设备同步时间服务器地址:
[[email protected] nrpe-2.13]# crontab -e
*/1 * * * * /usr/sbin/ntpdate 192.168.1.200
[[email protected] nrpe-2.13]# crontab -l
*/1 * * * * /usr/sbin/ntpdate 192.168.1.200
[[email protected] nrpe-2.13]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
[[email protected] ~]#
方法2、
[[email protected] nrpe-2.13]# vi /etc/ntp.conf
[[email protected] nrpe-2.13]# cat /etc/ntp.conf
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.1.200
[[email protected] ~]# chkconfig ntpd on
[[email protected] ~]#
[[email protected] ~]# vi /etc/sysconfig/ntpd
[[email protected] ~]# cat /etc/sysconfig/ntpd
# Command line options for ntpd
OPTIONS="-g"
SYNC_HWCLOCK=yes
[[email protected] ~]#
[[email protected] ~]# service ntpd restart