NTP service under the CENTOS5

Source: Internet
Author: User
Tags time zones local time

In the network world, time synchronization is very important, sometimes strange problems, often may be caused by time synchronization problems, and the global total of 24 time zones, so need NTP server to synchronize the time of each region. There is also a hardware time on the computer, that is, the CMOS clock, in the Windows system, the system starts directly from the COMs clock reading time, closed to the CMOS to write, so as to maintain the consistency of both. The Linux system is through the Hwclock command to read and set the hardware clock, below to see the centos5 under the NTP service bar.

[Root@centos5 ~]# hwclock View Hardware clock
July 04, 2009 Saturday 19:18 11 sec -0.609827 seconds


[Root@centos5 ~]# hwclock--UTC set hardware clock to GMT
July 05, 2009 Sunday 03:19 26 sec -0.561311 seconds

[Root@centos5 ~]# cat/etc/sysconfig/clock View system hardware clock and time zone configuration file
Zone= "Asia/shanghai"
Utc=true
Arc=false


[Root@centos5 ~]# ls-l/usr/share/zoneinfo/asia/shanghai
-rw-r--r--2 root root 405 2008-03-11/usr/share/zoneinfo/asia/shanghai

[Root@centos5 ~]# date-r View the time zone of the system
Sun, Feb 2009 01:05:53 +0800

Write system time to hardware clock
[Root@centos5 ~]# date-s "2009-07-04 19:04:00"
Saturday, July 04, 2009 19:04:00 CST
[Root@centos5 ~]# Date
Saturday, July 04, 2009 19:04:18 CST

[Root@centos5 ~]# Hwclock
July 05, 2009 Sunday 19:44 32 sec -0.685570 seconds
[Root@centos5 ~]# Hwclock--SYSTOHC
[Root@centos5 ~]# Hwclock
July 04, 2009 Saturday 19:04 56 sec -0.653825 seconds

Write hardware clock to system clock

[Root@centos5 ~]# Hwclock
July 03, 2009 Friday 19:04 30 sec -0.298749 seconds

[Root@centos5 ~]# date-s "2009-07-04 19:04:00"
Saturday, July 04, 2009 19:04:00 CST
[Root@centos5 ~]# Hwclock--hctosys
[Root@centos5 ~]# Date
Friday, July 03, 2009 19:05:02 CST

Compile to install NTP service
http://www.ntp.org/downloads.html, download the source package from the home page, compile and install
[root@centos5 ~]# cd/usr/local/src/
[ Root@centos5 src]# tar-zxvf ntp-4.2.4p7.tar.gz
[root@centos5 src]# cd NTP-4.2.4P7
[root@centos5 ntp-4.2.4p7]#./ Configure--PREFIX=/USR/LOCAL/NTP
[root@centos5 ntp-4.2.4p7]# make && make install
[root@centos5/]# CD/ usr/local/
[root@centos5 local]# ls
bin etc games include Lib Libexec ntp sbin share src
[root@centos5 local]# LS ntp/
Bin lib man
[root@centos5 ntp]# CD./bin/
[root@centos5 bin]# ls
ntpd     NTP dc       ntpq     ntptrace sntp
ntpdate Ntp-keygen ntptime Ntp-wait Tickadj

[Root@centos5 bin]#/ntpdate ch.pool.ntp.org Trial and ch.pool.ntp.org This public network NTP server synchronization time
4 June 20:08:47 ntpdate[28663]: Step time server 134.34.3.18 offset 88900.032745

SEC, where offset is the time lag between the two sides

Edit the configuration file and start the service
[Root@centos5 bin] #cd.
[Root@centos5 ntp]# ls
Bin Lib Mans
[Root@centos5 ntp]# mkdir etc
[Root@centos5 ntp]# ls
Bin etc Lib man
[Root@centos5 ntp]# VI etc/ntpd.conf
Server ch.pool.ntp.org
[Root@centos5 ntp]#./bin/netpd-c/usr/local/ntp/ntpd.conf
[Root@centos5 ntp]# NETSTAT-NUPL |grep 123
UDP 0 0 192.168.0.200:123 0.0.0.0:* 28697/ntpd
UDP 0 0 127.0.0.1:123 0.0.0.0:* 28697/ntpd
UDP 0 0 0.0.0.0:123 0.0.0.0:* 28697/ntpd
UDP 0 0 fe80::20c:29ff:fefd:123:::* 28697/ntpd
UDP 0 0:: 1:123:::* 28697/ntpd
udp        0      0:::123                      :::*                                      28697/ Ntpd

[root@centos5/]# tail-f/var/log/messages
June 4 20:21:08 centos5 ntpd[28696]: ntpd 4.2.4p7@1.1607 Fri June 3 11:11 : UTC 2009 (1)
June 4 20:21:08 centos5 ntpd[28697]: precision = 1.000 usec
June 4 20:21:08 centos5 ntpd[28697]: Li Stening on Interface #0 wildcard, 0.0.0.0#123 Disabled
June 4 20:21:08 centos5 ntpd[28697]: Listening on interface #1 W Ildcard:: #123 Disabled
June 4 20:21:08 centos5 ntpd[28697]: Listening on interface #2 lo:: 1#123 Enabled
June 4 2 0:21:08 centos5 ntpd[28697]: Listening on interface #3 eth0, fe80::20c:29ff:fefd:caa0#123 Enabled
June 4 20:21:08 Cento S5 ntpd[28697]: Listening on interface #4 lo, 127.0.0.1#123 Enabled
June 4 20:21:08 centos5 ntpd[28697]: listening on I Nterface #5 eth0, 192.168.0.200#123 Enabled
June 4 20:21:08 centos5 ntpd[28697]: Kernel time sync status 0040

[Root@centos5/]# cd/usr/local/ntp/etc/
[Root@centos5 etc]# VI ntpd.conf
Server ch.pool.ntp.org
Server 127.127.1.0 use local time as a reference when the network is unavailable
Restrict default ignore rejects all time synchronization requests and other accesses
Restrict 127.0.0.1 allows time synchronization for native and 192.168.0.0/24-bit hosts
Restrict 192.168.0.0 mask 255.255.255.0
Restrict ch.pool.ntp.org noquery Specifies that the parent NTP server can access this NTP server, but with the Noquery parameter, the other party is not allowed to query its own service status


[Root@centos5/]# ps-ef |grep ntpd
Root 28697 1 0 20:21? 00:00:00./bin/ntpd-c/usr/local/ntp/etc/ntpd.conf
Root 28731 5928 0 20:36 pts/0 00:00:00 grep ntpd
[Root@centos5/]# kill-9 28697
[Root@centos5/]# ps-ef |grep ntpd
Root 28733 5928 0 20:36 pts/0 00:00:00 grep ntpd

[Root@centos5/]#/usr/local/ntp/bin/ntpd-c/usr/local/ntp/etc/ntpd.conf
[Root@centos5/]# NETSTAT-NUPL |grep 123
UDP 0 0 192.168.0.200:123 0.0.0.0:* 28743/ntpd
UDP 0 0 127.0.0.1:123 0.0.0.0:* 28743/ntpd
UDP 0 0 0.0.0.0:123 0.0.0.0:* 28743/ntpd
UDP 0 0 fe80::20c:29ff:fefd:123:::* 28743/ntpd
UDP 0 0:: 1:123:::* 28743/ntpd
UDP 0 0::: 123:::* 28743/ntpd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.