Time Synchronization (ntp) operations in centos6
1. Importance of time synchronization
Time Synchronization can ensure normal business operation, such as data synchronization, such as batch execution of system scheduled tasks. .
2. view your system time.
[Root @ localhost ~] # Date
3. system modification time
# Date-s "19:00:00"
After modification, remember to execute clock-w and write the system time to CMOS to ensure that it will take effect after restart.
4. Hardware time settings
View: [root @ localhost ~] # Clock -- show
Synchronize system time to hardware time: [root @ localhost ~] # Clock-w
Synchronize the network time source to the system time immediately: [root @ localhost ~] # Ntpdate IP address of the time server on the network
Time zone modification: [root @ localhost ~] # Tzselect
You can directly modify the time file:
[Root @ localhost ~] #/Etc/sysconfig/clock
Synchronize hardware time to system time:
[Root @ localhost ~] # Hwclock-s
5. Network Synchronization
After the ntpdate operation, you only need to set the system time to the ntp server time. Cpu tick may be faulty. The crontab command is generally required for periodic synchronization settings. For example, add in crontab: (remember to manage scheduled tasks)
0 12 */usr/sbin/ntpdate the IP address of the time source is synchronized.
6. NTP-related configuration and file directory
/Etc/ntp. confntp configuration file.
/Usr/share/zoneinfo/directory of files in different time zones
/Etc/sysconfig/clock Linux boot will read the time needed here.
/Etc/localtime local time call will read the time zone configuration, and then copy the corresponding time zone.
/Etc/timezone modify system time zone
Configuration:
[Root @ linux ~] # Vi/etc/ntp. conf
#1. permission settings
# The permission setting is mainly based on the restrict parameter. The main syntax is:
# Restrict IP mask netmask_IP parameter
# The IP address can be the software address or default, which is similar to 0.0.0.0.
# Paramter:
# Ignore: Disable all NTP online services
# Nomodify: indicates that the Client cannot change the time parameter of the Server. However, the Client can still perform network calibration through the Server.
# Notrust: unless the Client passes authentication, the Client source will be considered as a untrusted domain.
# Noquery: does not provide Client-side time query
# Notrap: remote event logon is not provided.
# If paramter is not set at all, it indicates that the IP address (or domain) is "unlimited"
Restrict default nomodify notrap noquery # disable all NTP request packets
Restrict 127.0.0.1 # This allows query at the current level
Restrict 192.168.0.1 mask 255.255.255.0 nomodify
# The Server in the 192.168.0.1/24 network segment can use this NTP Server for time synchronization.
#2. Upper-layer host settings
# Set the upper-layer host to the server parameter. The syntax is as follows:
# Server [IP | HOST Name] [prefer]
# The Server is followed by our upper-layer Time Server! If the Server Parameter
# If perfer is added later, it means that our NTP host mainly uses this host
# Time correction. In addition, to solve the transmission delay action of the update time packet,
# So we can use driftfile to specify our host
# The Time spent communicating with the Time Server can be recorded in driftfile
# In the following file, for example, in the following example, the NTP server and
# The time spent when cn.pool.ntp.org is online is recorded in the/etc/ntp/drift file.
Server 0.pool.ntp.org
Server 1.pool.ntp.org
Server 2.pool.ntp.org
Server cn.pool.ntp.org prefer
# Set other values by default.
Server 127.127.1.0 # local clock
Fudge 127.127.1.0 stratum 10
Driftfile/var/lib/ntp/drift
Broadcastdelay 0.008
Keys/etc/ntp/keys
Restrict is used to set access permissions, server is used to set upper-level time servers, and driftfile is used to set files that save the drift time.
Check whether ntpd is enabled.
[Root @ linux ~] # Netstat-ln | grep 123 ntp port 123
Ntpstat to view the synchronization status.
After the service is enabled, it will take a while to synchronize.
Ntp service. By default, only the system time is synchronized. If you want ntp to synchronize hardware time at the same time, you can set the/etc/sysconfig/ntpd file.
In the/etc/sysconfig/ntpd file, add SYNC_HWCLOCK = yes to synchronize the hardware time with the system time.
Ntpd is smooth. Ntpdate is decisive.
If ntpd is slow. Then ensure that the business will not be down due to your determination. Manually modify the time or synchronize ntpdate.