Using NTP to sync your server time.
NTP lets you automatically sync your system time with a remote server.
Installing NTP
[centos@centos ~]$ sudo yum install ntp
[sudo] password for centos:
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
-
-
Setting up Install Process
Package ntp-4.2.4p8-2.el6.x86_64 already installed and latest version
Nothing to do
[centos@centos ~]$
|
Check NTPD Status
[centos@centos ~]$ chkconfig --list |grep ntpd
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[centos@centos ~]$ /etc/init.d/ntpd status
ntpd (pid 1513) is running...
[centos@centos ~]$
|
If you want to choose NTP servers other than the defaults
[centos@centos ~]$ grep ^server /etc/ntp.conf
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
[centos@centos ~]$
|
NTP port 123
NTP uses UDP port 123 to conduct its business, either connecting out to another
NTP server or accepting incoming connections.
[centos@centos ~]$ sudo netstat -antupl|grep ntp
udp 0 0 10.0.2.15:123 0.0.0.0:* 1513/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1513/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 1513/ntpd
udp 0 0 fe80::a00:27ff:fe75:123 :::* 1513/ntpd
udp 0 0 ::1:123 :::* 1513/ntpd
udp 0 0 :::123 :::* 1513/ntpd
|
The ntpdate command will sync your clock with an NTP server
The ntpdate command will not run when the NTP server is running, if you run then it says
the NTP socket is in use, exiting.
[centos@centos ~]$ grep ^server /etc/ntp.conf
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
[centos@centos ~]$ sudo ntpdate 0.rhel.pool.ntp.org
[sudo] password for centos:
13 Nov 19:15:42 ntpdate[10611]: the NTP socket is in use, exiting
[centos@centos ~]$
|
Stop NTP and then run ntpdate
[centos@centos ~]$ sudo /etc/init.d/ntpd stop
Shutting down ntpd: [ OK ]
[centos@centos ~]$ sudo ntpdate 0.rhel.pool.ntp.org
13 Nov 19:16:58 ntpdate[10636]: adjust time server 123.108.200.163 offset -0.285447 sec
[centos@centos ~]$ sudo /etc/init.d/ntpd start
Starting ntpd: [ OK ]
[centos@centos ~]$ pgrep ntp
10643
[centos@centos ~]$
|
Reference: http://support.ntp.org/bin/view/Support/GettingStarted