Install and configure NTP in centos

Source: Internet
Author: User
Tags cron script


Install
Yum install NTP

Configuration File /Etc/NTP. conf
Restrict default Kod nomodify
Notrap nopeer noquery
Restrict-6 default Kod nomodify notrap nopeer noquery
Restrict 127.0.0.1
Restrict-6: 1
# Use restrict to control permissions
# Nomodify-the time parameter of the NTP server cannot be changed on the user end
# Noquery-the user end cannot use commands such as ntpq and ntpc to query the NTP server
# Notrap-remote trap login not provided
Restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
# Two NTP servers
Restrict cn.pool.ntp.org
Restrict 164.67.62.194

# Set the upper-layer NTP server with the server. "prefer" indicates priority.
Server cn.pool.ntp.org prefer
Server 164.67.62.194

Server 127.127.1.0 # local clock
Fudge 127.127.1.0 stratum 10
# Deviation between system time and bios events
Driftfile/var/lib/NTP/drift
Keys/etc/NTP/keys
# Logs
Logfile/var/log/NTP. Log
Broadcastdelay 0.008

One note:
The NTP server I set up in VMware can be synchronized by others, but its own time is not correct. It is synced to the upper and lower layers. Later I found the document for a long and found it: /Etc/NTP/step-tickers The NTP server cannot actively synchronize the upper-layer server, so you can write the address to the file.

I have not found this problem on the physical machine for the time being. Maybe the physical machine's own time is correct, and it is difficult to find out whether it actively synchronizes the upper-layer server.

Run NTP
Service ntpd start/stop/restart
Chkconfig ntpd on

View NTP port , You should see port 123
Netstat-unlnp

Check whether the NTP server is connected to the upper layer.
[[Email protected] ~] # Ntpstat
Synchronised to NTP server () at stratum 2
MS time correct to within 74
Polling server every 128 S
Note: The preceding synchronised command is slow. I used it for about 5 minutes.

View the connection between the NTP server and the upper layer
[[Email protected] ~] # Ntptrace-N 127.0.0.1
Wagner. 0.0.1: stratum 2, offset 0.064524, synch distance 0.121167
210.72.145.44: timed out, nothing already ed *** request timed out

View the status of the NTP server and the upper-layer NTP server
[[Email protected] ~] #Ntpq-P
Where,
Remote-IP address or Host Name of the local and upper-layer NTP servers. "+" indicates priority, and "*" indicates priority.
RefID-refer to the NTP host address on the previous layer.
St-stratum class
When-how many seconds ago has been synchronized
Poll-how many seconds after the next update
Reach-number of times that NTP servers on the upper layer require updates
Delay-network latency
Offset-time compensation
Jitter-time difference between system time and BIOS

 

Client synchronization time Method
Method 1: Use ntpdate
Ntpdate [ip_address]
Let's look at the example below. 192.168.1.5 is the NTP server I set up on the Intranet.
[[Email protected] ~] # Date
Thu Sep 25 12 13:04:17 CST 2008
[[Email protected] ~] # Ntpdate 192.168.1.5
25 sep 14:33:13 ntpdate [10302]: Step time server 192.168.1.5 offset 5327.700798 Sec
[[Email protected] ~] # Date
Thu Sep 25 12 14:33:18 CST 2008

Features of ntpdate:
1. ntpdate only runs once and ends, that is, only synchronization once. Therefore, to use the ntpdate synchronization time, write the command into cron.
VI/etc/crontab
* *** Root ntpdate 192.168.1.5 & hwclock-W
The command hwclock-W will be used later.
2. ntpdate synchronization time is skipped. As shown above, the time is synchronized immediately, which may cause file time tags and monitoring data disorder.

Method 2 : Use ntpd service
Step 1: Write/etc/ntpd. conf Server [ip_address]
Step 2: Chkconfig ntpd on
Step 3:Service ntpd start

It takes effect in about a quarter of an hour.

FAQ: System Error-Sep 25 11:59:39 localhost kernel: set_rtc_mmss: Can't update from 7 to 59
= ========================================================
If (ABS (real_minutes-cmos_minutes) <30) {update_cmos ()} else {printk ("set_rtc_mmss: Can't update from % d to % d \ n", cmos_minutes, real_minutes );} ========================================================== ========================================================== ==========
If the BIOS time differs from the system time by more than 30 minutes, the above error is reported. You only need to modify the BIOS time or system time.

Personal experience under virtual machines:
After my VM client synchronizes the server with ntpd, it gradually becomes the standard time, but then it becomes slower and slower than the standard time, and the above error is reported. So I think the synchronization frequency of ntpd is slower than that of my VM clock.

 

 

ntpd features:
1. The ntpd service is always running and regularly synchronized.
2. ntpd service slowly changes the time until the standard time.
3. If the difference between the system time and bios time exceeds 30 minutes, ntpd reports an error.
conclusion:
1. ntpd is recommended.
2. ntpdate cannot be used after ntpd is enabled. See the following example:
[email protected] ~] # Service ntpd start
starting ntpd: [OK]
[email protected] ~] # Ntpdate 192.168.1.5
25 sep 15:25:22 ntpdate [12334]: The NTP socket is in use, exiting
Appendix: linux time, time zone
1, time
system time: Date command
BIOS time: hwclock command (-r reads BIOS time, -w bios write time)
the system re-reads the BIOS time each time it is started.
hwclock is required for the cron script used in the preceding ntpdate command to avoid time confusion after the machine is restarted.
2. Time Zone
All Linux time zone files are stored in/usr/share/zoneinfo.
in Linux, the time zone file is/etc/localtime, which is a time format file and is not an acⅱ code. It is the same as its own time zone file under/usr/share/zoneinfo.
my time zone is Asia-Shanghai. Use diff to compare the two files.
[[email protected] ~] # Diff/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
[[email protected] ~] #
the current time zone information is also written in the/etc/sysconfig/clock file:
[email protected] ~] # Cat/etc/sysconfig/clock
zone = "Asia/Shanghai"
UTC = false
arc = false

 

By[Email protected]

Related Article

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.